jQuery is an excellent javascript library which makes writing JS fun again!
Bookmarklet to load jQuery onto the currently visible page!
jQuerify
code from above Bookmarklet for direct (userscript) use:
(function() {
var s=document.createElement('script');
s.setAttribute('src','http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.js');
if(typeof jQuery!='undefined') {
var msg='This page already using jQuery v' + jQuery.fn.jquery;
} else {
document.getElementsByTagName('head')[0].appendChild(s);
var msg='This page is now jQuerified'
}
var el=document.createElement('div');
el.style.position='fixed';
el.style.height='30';
el.style.width='200';
el.style.margin='0 auto 0 auto';
el.id='jq-kswedberg';
el.style.top='0';
el.style.left='40%';
el.style.padding='5px 10px 5px 10px';
el.style.backgroundColor='#f99';
el.innerHTML=msg;
var b=document.getElementsByTagName('body')[0];
b.appendChild(el);
window.setTimeout(function() {
jQuery('#jq-kswedberg').fadeOut('slow',function() {
jQuery(this).remove()
});
}, 2500);
})();
JS snippet (Userscriptable) to load jQuery on the page if not loaded already:
// 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() {
alert($); // check if the dollar (jquery) function works
}
(via [[http://joanpiedra.com/jquery/greasemonkey/]])