Trying to load jquery into tampermonkey script

泪湿孤枕 提交于 2019-12-20 08:04:11

问题


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?


回答1:


You need to have a @require in the user script header to load jQuery. Something like:

// @require http://code.jquery.com/jquery-3.4.1.min.js

(Selecting your desired version from the of list of available versions of jQuery)



来源:https://stackoverflow.com/questions/24753908/trying-to-load-jquery-into-tampermonkey-script

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!