O'Reilly logo

Greasemonkey Hacks by Mark Pilgrim

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Hack #58. Add Keyboard Shortcuts to Google Search Results

If you search frequently and type as quickly as you think, you'll appreciate this keyboard-only hack.

I love Google. I use Google 50 times a day…literally. I actually used Google once to look up my own phone number. I was placing an order over the phone when the customer service representative asked me for my home phone, and I totally drew a blank. Has that ever happened to you? I should really get one of those weblog thingies all the kids are talking about, so I can regurgitate personal anecdotes like this in a virtual medium, instead of wasting all this paper. But I digress.

As I was saying, I search a lot, and I type very quickly. And if I'm looking for very specific things, and Google is so very good at finding them, I usually find what I'm looking for in the first page of search results, which means that this hack is perfect for me, because it numbers the search results and lets me follow them without moving my hands off the keyboard.

The Code

This user script runs on all Google pages. It uses an XPath query to find all the search results (they're each wrapped in a <p class="g"> element), and then inserts red numbers beside each search result, from 1 to 9, then 0 for the 10th result. The last line of the script ties it all together by registering a global onkeydown event handler that checks whether you typed a number, and if so, finds the associated search result and follows the link.

Save the following user script as

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required