Adding a JS library to existing greasemonkey scripts

1314626301000 » Tagged as: Greasemonkey , JavaScript , jQuery

So the other day, I posted about how adding jQuery to a greasemonkey scripts has become pretty easy. It wasn’t always like  that. The same approach can also be used to add YUI, Prototype etc to any GreaseMonkey script. Now suppose you want to add such a library to existing GreaseMonkey code? Well it’s a bit of a nuisance but can be done.

First go to ‘Manage user scripts’ via the Grease menu  and then right click on the script of your choice to find it’s containing folder.

Second step is to download the library (eg, jQuery, YUI etc) of your choice and place it in the same folder as your script.

Now edit the script and add the appropriate @require header eg: // @require        http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js

close your browser and go up to the parent folder of your script, there you will find a file named config.xml , open it with your favorite xml or text editor.

Find the element that describes your script, add a require child node  like this: <Require filename=”jquerymin.js”/> replacing jquery.min.js with the name of the file that you just downloaded.

Now go have that cup of tea. Tea is better than coffee you know. Tea’s got caffeine too.

comments powered by Disqus