Sunday, May 29, 2005

Announcing, beta 2 of Monkeybox, my port of Adrian's Greasemonkey compiler.

A web interface is available here: http://monkeybox.lachie.info
The compiler itself:
monkeybox_0.2beta2.zip

My original aim was to vary Adrian's python code to handle compilation of multiple greasemonkey scripts into a single Firefox extension. As usual, things have changed a fair bit since then.

The compiler is written in Ruby (because its hip and somewhat gorgeous ;) It uses templates rather than programmatic construction. Each added user script can be switched on and off via the generated extension's options panel.

Monkeybox's most interesting feature is the way it implements the essential greasemonkey business. I packaged the reusable parts of greasemonkey as an xpcom component. Monkeybox, therefore, supports all of greasemonkey's special features (i.e. the GM_* functions)

The interface is as follows

// add/get a script to/from the singleton
void setScript( string yourGUID, string scriptKey, Object scriptDescription );
Object getScript( string yourGUID, string scriptKey );

// en/disable a specific script
void setScriptEnabled( string yourGUID, string scriptKey, boolean enabled );

// en/disable a whole GUID-keyed client's scripts (not yet implemented)
void setClientEnabled( string yourGUID, boolean enabled );

Its a very neat separation of concerns - and works pretty well - but there are a few issues which might turn out to be down-sides in time, such as scoping and the security context in which user scripts run.

Here's a fairly vauge overview of the architecture:


One special nicety of this arrangement is that you can protoype scripts very easily straight from a local html file (the Monkeybox archive contains an example in test_component.html).

Although my implementation is pretty experimental, I think it would be really cool if the official Greasemonkey became an xpcom component. Greasemonkey as a reusable engine... hmmm.

The implementation is pretty patchy so far, but I wanted to get it out there. There are some known issues:
  • reinstallation of a script should be much smarter (if you install it with a different name, same guid, bad things can happen)
  • security model... it need tweaking/investigation
  • what happens when multiple extensions have different versions of the greasemonkey-singleton?
Feedback is always welcome... lachiec uses gmail spot com

2 Comments:

Blogger Will said...

Hi Lachie,

Thanks for sharing your code!

If you don't have rubyzip installed you see the error:
c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:18:in `require' from monkeybox.rb:6

Solution:
* gem install rubyzip


With the Ruby One-Click installer (ruby182-15 2005-04-20) you get the following error:

....../rubygems/custom_require.rb:18:in `require__': No such file to load -- iconv (LoadError)

Solution: Download ruby-1.8.2-i386-mswin32.zip from
http://www.garbagecollect.jp/ruby/mswin32/en/download/release.html

Extract ICONV.rb and iconv.so
cp ICONV.rb /ruby/lib/ruby/1.8/rexml/
cp iconv.so /ruby/lib/ruby/1.8/i386-mswin32/

(This problem is discussed on http://wiki.rubyonrails.com/rails/show/iconv )

6:35 PM  
Blogger banner ads said...

There is alot of Blogs, I never guessed I'd find some usefull information.

Thanks.
I'll be back later to see if anymore good updates are available.

4:22 AM  

Post a Comment

<< Home