Greasemonkey just saved a few years of my life
January 10th, 2008
I’m a big fan of Google Reader. Let’s just say I’m subscribed to more than a few feeds. I use the keyboard shortcuts to quickly read and scan through my reading list. To keep my pace I’ve come to open articles that I want to think about more, or ones that I want to read more in depth in background tabs. Usually this involves the laborious task of moving my hand from the keyboard and middle-clicking with the mouse. Painful. Time-wasting. Distracting.
Enough is enough, so I decided to create a Greasemonkey script to bind a keyboard shortcut to opening an article in a background tab. But, what magical javascript incantation is required to open a tab?
Turns out that Greasemonkey doesn’t only allow you to add functionality via javascript to any webpage, it also provides privileged functionality that is not available to normal javascript running in a webpage. One of those methods is, opening a url in a background tab .
All the hard work goes to Sunny Wu who provided the solution. I tweaked his version to use the “h” character instead of “v”.
I wasn’t sure what kind of event this handler receives and so I wasn’t sure how to determine that a “h” was pressed. Firebug to the rescue, I just added the following line to just print out the value to the Firebug console.
console.info("key=", event.which);
Sidenote: Ever wonder what event is sent for crazy modifiers like shift+3 or shift+s? I thought it might be something complicated—where you’d check if modifier keys were pressed on the keyboard event. I was thinking too much. Shift+3 ends up sending a #, shift+s sends a capital S. Who would have thought?!
Just change the first “if” to compare against 104 instead of 118 and h is the man.
I changed to h since, well, first, v currently opens the article in another tab that immediately takes focus—handy at times. Second, well, if I use h instead, I can navigate mostly with just my right hand :)

Sorry, comments are closed for this article.