David Findlay

greasemonkeying my backpack

For a while now I've been maintaining a running log on a Backpack page. I like Backpack because it's quick and convenient to use. However, for my running log I could really use a little bit of spreadsheet functionality, to sum the miles I've run in a given month for me, and that's just not Backpack's bag (pardon the pun).

So, since I'm reading Ajax in Action at the moment, it seemed like a good time to play a little bit with JavaScript and greasemonkey. If you're not familiar with it, greasemonkey is a Firefox extension that allows you to apply custom JavaScript to webpages. You install scripts that you write or download, into greasemonkey. You then tell it, via one or more regular expressions, which pages the scripts should be applied to. I use a few greasemonkey scripts already, for viewing images (Greased Lightbox), tweaking Flickr's interface, and so on.

So I decided I would write my own greasemonkey script to do all that bothersome addition for me on my running log. After a few false starts, caused by me trying to use FireBug's console for logging, which isn't exposed in greasemonkey, I got it to work:

greasemonkeybackpack

The text in green at the bottom is generated by the script (the total above it in black is my previous hard-coded one). The script isn't done yet; for one it has next to no error handling. Also, because of the ajax nature of Backpack, my totals get lost whenever I edit the page, forcing me to do a full page refresh to get them back. So, I might add a keyboard shortcut to turn the totals on and off next.

FWIW, here's the script in all its "glory". Try not to laugh at my JavaScript skills or lack thereof.