Jeff Barr's Blog

Things I Like..

Greasemonkey 0.5 Beta

I spent part of my spare time this past week working on a Greasemonkey script. The script simplifies the process of finding RSS and Atom feeds and suggesting them to Syndic8. I’ll write up full documentation very soon.

Despite the odd name, Greasemonkey embodies a very cool and somewhat unique concept, something that I am starting to think of as low-budget, client-side application integration. In the late 90′s, “EAI” or Enterprise Application Integration, was all the rage. Companies that had the need to make disparate applications work together would spend tens of thousands of dollars on complex, fragile software to make it happen. Sometimes it worked, and sometimes it didn’t. When it didn’t, they would call in armies of even more expensive consultants.

Now, I’ll be the first to say that Greasemonkey in its present form isn’t quite ready to replace expensive, commercial EAI software. However, I do believe that it belongs in the enterprise developer’s tookit of possible solutions, and I also believe that Greasemonkey will gain features, power, and respect over the coming months and that now is the time to learn more about it.

Greasemonkey is a “last chance” tool for application extension, modification, and customization. Once Greasemonkey is loaded into Firefox, it can play host to any number of specially written user scripts. Scripts are written in JavaScript and include a set of rules (regular expressions) which determine the set of pages that they apply to. For example, a special purpose script can be set up to run only when a page within the amazon.com domain has been loaded.

Each time the browser loads a page, Greasemonkey is activated. It then finds the scripts that apply to the page, and runs each of them. The scripts have full read-write access to the internal HTML structure of the page (also known as the DOM or Document Object Model). By exploiting the power of the DOM and of other high-level programming tools such as XPath and XQuery, scripts can be small, efficient, and easy to write.

A huge collection of pre-written scripts can be found at www.greasemonkeyed.com . Even though Greasemonkey is less than a year old and is still considered beta quality, the diversity and power of the scripts is impressive. Broadly speaking, most of them can be categorized like this:

  1. Extension – Scripts that take add new features to a page.
  2. Restriction – Scripts that remove features from a page.
  3. Repair – Scripts that “fix” a page based on a developer’s perception that it is broken or sub-optimal.
  4. Integration – Scripts that take data from two or more web sites and present them

At some point I could see the need for what we could call “Enterprise Greasemonkey,” a tightly packaged version of Greasemonkey with a number of scripts installed and locked in to place. This would give system administrators the ability to deploy specialized versions of Firefox to users who don’t need to know how to install, customize, or disable Greasemonkey scripts.

The future is bright now is a good a time as any to start learning how to write Greasemonkey scripts. Here are some resources to get you started:

So there you have it. Tomorrow I’ll tell you about my first script and I’ll show you how it works.