Greasemonkey as a Lightweight Intermediary

Simon Willison writes:

The latest release of the swiss army knife of Firefox extensions adds support for cross-domain XMLHttpRequest calls from greasemonkey scripts. What that means is that you can create a user script (a short JavaScript that will be executed whenever your browser loads specific pages) that can then pull extra data in from another server.

I’m using this for my final year project, a decentralised web annotation system that lets you annotate pages, storing your annotations locally and then sharing your public annotations as a feed (similar to the way RSS aggregators work). The trick there is to run a local web server on some port, then have the Greasemonkey user script (eventually a full extension) communicate with that local server to store and retrieve data. I’m using Ruby on Rails’ built in WEBrick server to prototype the service, and it’s working a treat.

This architecture could be easily adapted to add private bookmarks to – or to add any number of cool features to any number of other sites. Here’s another example: Google’s Desktop Search integrates results from your local drive with the search results page on Google. Using greasemonkey and a local web server tied in to OS X Tiger’s Spotlight indexer, you could add this functionality to any search site you wanted to. Just be sure to lock down the web server to only serve requests from localhost, to avoid sharing search results for your data with anyone on the network who can see your machine.

Published by

Rajesh Jain

An Entrepreneur based in Mumbai, India.