I'm totally new to GreaseMonkey, but I'm trying to make a little script.
// ==UserScript==
// @require http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js
// ==/UserScript==
(function() {
$ = unsafeWindow.jQuery;
alert($); // this gives 'undefined'
}());
Why does the alert give undefined
and how to fix this?
UPDATE
I tried this:
(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($);
}
})();
but this gave me an infinite loop of ok-alerts. Seems like jQuery doesn't get loaded at all.