[Greasemonkey] Improved Greasemonkey

Ben Karel ben at eschew.org
Mon Apr 4 02:03:53 EDT 2005


After reading

http://philringnalda.com/blog/2005/03/mark_pilgrim_goes_both_ways.php

I figured, now page script beating chrome? That just ain't right!

So, I gave Greasemonkey a pretty significant makeover ( 
http://eschew.org/projects/mozilla/greasemonkey/ )

Brief changelog, see above dir for (slightly) fuller commentary:
* Mozilla now supported; tested with 1.0. I'd imaging later versions are 
compatible.
* Consolidated Tools menuitems into a single new menu, as with Adblock.
* Replaced the 40-line convert2RegExp() [eeew...] with the latest 
Adblock version (12 lines)
* When installing a user script from the tools menu, get the script text 
from the rendered document, rather than re-downloading it. This means 
that the gzip-compression bug is fixed, and it also gets rid of the 
rather ugly DM "flash".
Also saves on the order of 100 lines of code.
* Do a full read of config.xml from disk only on first-run and on save, 
since those are the only possible change points.
* Use XPCNativeWrapper to ensure access to native functions like 
addEventListener.
* Added a dialog for users to edit scripts directly. Barebones but 
functional.

The XPCNativeWrappers also means that this copy of Greasemonkey can let 
user scripts run even if the page sets *.appendChild and 
*.addEventListener to null (Dean Edwards and Mark Pilgrim's techniques, 
respsectively).

It took a day longer than I thought it would, mostly due to Mozilla 
1.0's idiosyncracies. Oh well.

Now, no guarantees about stability, but it's been working pretty well 
for me.

I also tightened up Mark's hijacker script, but that's about as useful 
as rewriting your idle loop. As it turns out, thanks to the sheer number 
of introspection points in the DOM, concealing actual modifications is a 
rather futile challenge. Event listeners are lost when their principal 
node is removed from the DOM tree, too. Now, chrome still wins, just not 
through Greasemonkey -- a dedicated extension need never touch the DOM 
itself, and can thus remain completely undetectable to page script.

Oh, yes, there's also *cough* an icon for the Extension Manager: 
http://eschew.org/projects/mozilla/greasemonkey/monkey-banana.png



More information about the Greasemonkey mailing list