我尝试了这一行,但它不起作用:
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.js
Run Code Online (Sandbox Code Playgroud)
jQuery根本不适用于Greasemonkey.还有其他方法在Greasemonkey中使用jQuery吗?
-
对于遇到相同问题的所有人,您必须将文件上传到greasespot,然后从那里安装.
"创建新脚本"选项不起作用!
我是GreaseMonkey的新手,但我正在尝试制作一个小脚本.
// ==UserScript==
// @require http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js
// ==/UserScript==
(function() {
$ = unsafeWindow.jQuery;
alert($); // this gives 'undefined'
}());
Run Code Online (Sandbox Code Playgroud)
为什么警报会给出undefined以及如何解决此问题?
UPDATE
我试过这个:
(function(){
//boilerplate greasemonkey to wait until jQuery is defined...
function GM_wait()
{
alert('ok');
if(typeof unsafeWindow.jQuery == 'undefined')
window.setTimeout(GM_wait,100);
else
unsafeWindow.jQuery(function() { letsJQuery(unsafeWindow.jQuery); });
}
GM_wait();
function letsJQuery($)
{
alert($);
}
})();
Run Code Online (Sandbox Code Playgroud)
但这给了我一个无限循环的ok-alert.好像jQuery根本没有加载.