admin管理员组文章数量:1134586
I am writing a script which logs into my college network when the login page is loaded.
The code looks as follows
// ==UserScript==
// @name My Fancy New Userscript
// @namespace /
// @version 0.1
// @description enter something useful
// @match <College login page>
// @copyright 2012+, You
// ==/UserScript==
$(document).ready(function() {
var usr=document.getElementsByName("username");
var pass = document.getElementByName("password");
usr.value="usrname";
pass.value="password";
var submitButton = document.querySelector ('input[type="submit"][value="Login"]');
var clickEvent = document.createEvent ('MouseEvents');
clickEvent.initEvent ('click', true, true);
submitButton.dispatchEvent (clickEvent);
});
The console shows a error saying
$ is not defined
Can someone tell me what is going on here?
I am writing a script which logs into my college network when the login page is loaded.
The code looks as follows
// ==UserScript==
// @name My Fancy New Userscript
// @namespace http://use.i.E.your.homepage/
// @version 0.1
// @description enter something useful
// @match <College login page>
// @copyright 2012+, You
// ==/UserScript==
$(document).ready(function() {
var usr=document.getElementsByName("username");
var pass = document.getElementByName("password");
usr.value="usrname";
pass.value="password";
var submitButton = document.querySelector ('input[type="submit"][value="Login"]');
var clickEvent = document.createEvent ('MouseEvents');
clickEvent.initEvent ('click', true, true);
submitButton.dispatchEvent (clickEvent);
});
The console shows a error saying
$ is not defined
Can someone tell me what is going on here?
Share Improve this question asked Jul 15, 2014 at 8:58 JonahJonah 2,1174 gold badges20 silver badges24 bronze badges2 Answers
Reset to default 371You need to have a @require
in the user script header to load jQuery. Something like:
// @require https://code.jquery.com/jquery-3.6.0.min.js
(Selecting your desired version from the of list of available versions of jQuery)
For future googlers,
If you have used the above method and still jQuery doesn't seem to be loaded by your script try looking at the spaces, And try to match the indentation with the rest of the header. Apparently the indentation is important.
// ==UserScript==
// @name New Userscript
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author You
// @match https://stackoverflow.com/*
// @require http://code.jquery.com/jquery-3.4.1.min.js
^ here should be correct amount of spaces
...
本文标签: javascriptTrying to load jquery into tampermonkey scriptStack Overflow
版权声明:本文标题:javascript - Trying to load jquery into tampermonkey script - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736805377a1953663.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论