我玩弄jquery和greasemonkey,并试图使用setTimeout每秒调用一个函数,但由于某种原因它不起作用。greasemonkey,jquery和setTimeout
// Add jQuery
var GM_JQ = document.createElement('script');
GM_JQ.src = 'http://jquery.com/src/jquery-latest.js';
GM_JQ.type = 'text/javascript';
document.getElementsByTagName('head')[0].appendChild(GM_JQ);
// Check if jQuery's loaded
function GM_wait() {
if(typeof unsafeWindow.jQuery == 'undefined') { window.setTimeout(GM_wait,100); }
else { $ = unsafeWindow.jQuery; letsJQuery(); }
}
GM_wait();
// All your GM code must be inside this function
function letsJQuery() {
功能定时器(){ 警报( 'TEST') }
的setTimeout(定时器,1000);
}
有什么想法吗?
最新版本的jQuery犯规的在Greasemonkey工作。在GM中工作的更高版本是1.3.2,并且我建议你添加一个eventlistener(on load)到GM_JQ,所以你可以避免使用GM_wait() – w35l3y 2010-08-08 19:10:09