Categories
Uncategorized

Greasemonkey Hacks

I’ve just gotten a copy of Greasemonkey Hacks and I’m working my way through it. The book itself is great. It’s a really good introduction to greasemonkey and what you can do with it. Eventually, I’m hoping to may my bank usable in firefox.

The only quibble that I have is the code samples. Many of them (and they appears to be the ones written by Mark Pilgrim, the author) are really difficult to read, because they idioms are wrong. For example, nearly every for loop I have seen looks like this:

  for (var i = arTableRows.length - 1; i > = 0; i--) {
    ...
  }

Which is walking through the rows of a table, backwards. Why backwards? I have no idea. I would expect it to look more like this:

  for (var i = 0; i < arTableRows.length; i++) {
    ...
  }

Aside from a marginal efficiency gain (which smacks of micro-optimisation), I don’t see what the benefit is.

And “arTableRows” is another quibble with the code. It’s filled with hungarian notation. Great if you work at Microsoft, but unreadable to the rest of the world.

2 replies on “Greasemonkey Hacks”

I felt the same way about hungarian notation until I read Joel’s article. I haven’t yet found a good use for it yet but it does at least make sense.

Just a question as to how much JavaScript knowledge is assumed by the Greasemonkey book? I know as much JS as I know Swedish – enough to get arrested but not enough to do anything useful.

I read Joel’s article too, but it still doesn’t make it any easier on the eyes. I guess I’m completely spoiled by all the beautiful Ruby code I’ve been reading recently.

As to how much code is needed? I’d guess that if you want to understand the hacks, you need to be slightly above the cut’n’paste level. But I still reckon you could go a long way by typing in the examples and modifying them a bit. The examples are all available for download, so you don’t even have to type them in. But the book is generally pretty good at explaining what they all do.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s