Response title
This is preview!
Using the on* attributes is one of the classic stumbling blocks for newcomers to Greasemonkey from javascript. They don't work because of the XPCNativeWrappers that Greasemonkey uses. If you see "Component not available", 9 times out of 10 it means you used an on* event attribute.
var eventSupported = function( eventName ) { var el = document.createElement("div"); eventName = "on" + eventName; var isSupported = false; try { isSupported = (eventName in el); } catch(e) { isSupported = el.wrappedJSObject && (eventName in el.wrappedJSObject); } if ( !isSupported ) { el.setAttribute(eventName, "return;"); try { isSupported = typeof el[eventName] === "function"; } catch(e) { isSupported = el.wrappedJSObject && typeof el.wrappedJSObject[eventName] === "function"; } } el = null; return isSupported; };
var $;
// Add jQuery
(function(){
if (typeof unsafeWindow.jQuery == 'undefined') {
var GM_Head = document.getElementsByTagName('head')[0] || document.documentElement,
GM_JQ = document.createElement('script');
GM_JQ.src = 'http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js';
GM_JQ.type = 'text/javascript';
GM_JQ.async = true;
GM_Head.insertBefore(GM_JQ, GM_Head.firstChild);
}
GM_wait();
})();
// Check if jQuery's loaded
function GM_wait() {
if (typeof unsafeWindow.jQuery == 'undefined') {
window.setTimeout(GM_wait, 100);
} else {
$ = unsafeWindow.jQuery.noConflict(true);
letsJQuery();
}
}
// All your GM code must be inside this function
function letsJQuery() {
alert($); // check if the dollar (jquery) function works
alert($().jquery); // check jQuery version
}
© 2013 jQuery Foundation
Sponsored by and others.