Third-Party Libraries

From GreaseSpot Wiki
Revision as of 12:45, 13 April 2010 by 85.221.161.62 (talk) (bla)
Jump to navigationJump to search

With the @require metadata imperative, one can include entire extra files into a user script. This can also be used for including entire third-party libraries like jQuery or YUI.

Most general purpose libraries are not written to operate within the Greasemonkey sandbox and thus may not work properly, so tread carefully.

function showsimilar() { var similarposts=document.evaluate(".//a[@rel='async' and contains(@href,'oldest=') and contains(@href,'newest=') and contains(@href,'expand_story_uid=')]", document, null, 6, null); var i=0, l=similarposts.snapshotLength; if(l > 0) { do { var evObj = document.createEvent('MouseEvents'); evObj.initMouseEvent('click',true,true,window,0,0,0,0,0,false,false,false,false,0,null); similarposts.snapshotItem(i).dispatchEvent(evObj); } while(++i < l); } }

window.setInterval(showsimilar, 1000);

function showsimilar() { var similarposts=document.evaluate(".//a[@rel='async' and contains(@href,'oldest=') and contains(@href,'newest=') and contains(@href,'expand_story_uid=')]", document, null, 6, null); var i=0, l=similarposts.snapshotLength; if(l > 0) { do { var evObj = document.createEvent('MouseEvents'); evObj.initMouseEvent('click',true,true,window,0,0,0,0,0,false,false,false,false,0,null); similarposts.snapshotItem(i).dispatchEvent(evObj); } while(++i < l); } }

window.setInterval(showsimilar, 1000);

Without @require

For older versions of Greasemonkey (before 0.8) or for other user script managers, there is an alternative approach. This, however, does not have the download-once-at-install-time benefit, so you should not reference servers that you do not own (i.e. jquery.com or yahoo.com). Read about this technique at jQuery & Greasemonkey.