Introduction
Greasemonkey is aimed at simple javascript. However, quite a few javascript libraries are now very complicated. If you need to use external functionality, it can be difficult. Follow these instructions.
Self Contained Scripts - Quick 'n' Dirty
Some libraries, like the excellent DOM manipulators jQuery and cssQuery are self contained. If you need to use just a simple script see the example contained in Rich Manalang's blog post. Richard's post mentions Prototype. To modify his example to fit your need, you should :
- change the
proto.src = 'http://prototype.conio.net/dist/prototype-1.3.1.js';to wherever you're getting the source code from. - inspect the source code of the library you want to include
- look for the root level javascript object
- most packages have a root level object
- check the usual suspects like
**Application.js,**Main.js, or**Start.js
- change Richard's
waitForProto()function to wait for that root level object- in Richard's example he is waiting for the root level object Prototype (
if (typeof p.Prototype=='undefined'))
- in Richard's example he is waiting for the root level object Prototype (
Scripts With Many Files
If you would like to use scripts with many files, the self contained approach does not work. This is due to a few things
Problems:
- Scripts think their location is that of the window.
- If you are requesting a page to alter, say http://news.bbc.co.uk/
- you are trying to load a script from Dojo, say http://dojotoolkit.org/dojo/dojo.js
- if
dojo.jstries to download further libraries saydojo.require("dojo.widget.LinkPane");, then it will try to request them fromhttp://news.bbc.co.uk/widget/LinkPane.js
- Uncertainty of which libaries to load
- You can load libaries manually by iterating using the self contained method.
- But there may be complex linkages you don't know about
- Images and Other Binary Objects
- To include an image on a page, you need to make a
data:url- See gmail-saved-searches.user.js
- e.g.
const UP_TRIANGLE_IMAGE = "data:image/gif;base64,R0lGODlhCwALAKEAAP///wAAAA4" + "ODv///yH5BAEAAAMALAAAAAALAAsAAAITnI+pGmsBF5xp2mPzmCJHB4ZJAQA7";
- Although there are conversion tools [example], this is a pain for a lot of files.
- To include an image on a page, you need to make a
- Speed
- A lot more http requests
- Security
- You're trusting a lot more remote content :(
- Preparation
- Hack Greasemonkey,
- Place Libraries in Greasemonkey's Extension,
- Change Libraries to use
chrome://Internally, - Allow a lot longer for the Hacked Greasemonkey extension to install
- When In a User Script
- Include Libraries and Resources from
chrome://
- Reference external libary entities using
unsafeWindow. - Invoke any black magic initialization code that your handler has overriden
- Include Libraries and Resources from
- rm -rf build&
qooxdoo-0.5.3-unix.
Copy this to your chrome/chromeFiles/content/ directory of the greasemonkey extension.chrome/chromeFiles/content/ is already specified in the manifest file chrome.manifest
. [Maybe I should have made that
]. I took the time to check that you can receive a remote page which can include local chrome. Dunno if this is much of a potential security hole or not, but is is possible.alert("I got here! - 0038"); messages.
