Keyboard shortcut for Google’s “did you mean”

Update: This doesn't work since the introduction of Google Instant Search.

Keyboard shortcut for Google’s “did you mean”

This post could also be titled "My first Greasemonkey script"...

When google thinks you might have spelled your search query incorrectly it gives a suggested correction at the top of the results page. This happens a lot with me; I'm a heavy user of the "did you mean" link. I'm also a big fan of keyboard shortcuts. So I thought I'd see if there was a way to follow that link easily with a keyboard shortcut. I couldn't find a simple solution like a firefox add-on or a greasemonkey script so I decided to look into how you write greasemonkey scripts and make my own.

What is greasemonkey?

Greasemonkey is an add-on for firefox that lets people write their own code to improve the websites they visit. A very crude example might be, if you think the font size on a favourite website is too small you can write a scrip that will make the font bigger.

Of course, you don't need to know how to code because there are loads of great coders out there writing greasemonkey scripts and there might well be one out there that does just what you want. For example I fond one that turns any post codes on a page into links to google maps. Very handy.

My very own script

I couldn't find one that gave me a keyboard shortcut for "did you mean" so I wrote my very first greasemonkey script. Once you've installed greasemonkey you can install my script here:

Keyboard shortcut for Google's 'did you mean'

I suspect this this is a good example of some very bad coding practices. If anyone wants to take it and make it better feel free. Features include:

  • hitting 'd' follows the "did you mean" link.
  • function is disabled if the search box has focus.

Do you have any favourite greasemonkey scripts? Let me know in the comments.

Here's the code:

// ==UserScript==
  1. // @name           Keyboard shortcut for Google's 'did you mean'
  2. // @namespace      eh
  3. // @include        http://www.google.co.uk/*
  4. // ==/UserScript==
  5.  
  6. var allAs, thisA;
  7. allAs = document.evaluate(
  8.     "//a[@class='spell']",
  9.     document,
  10.     null,
  11.     XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,
  12.     null);
  13. document.addEventListener('keypress', function(event) {
  14.  
  15.  if( event.which==0144 && event.target.type != "text" && event.target.type != "textarea") {
  16.     thisA = allAs.snapshotItem(0);
  17.  link=thisA.getAttribute('href');
  18.  link="http://www.google.co.uk" + link;
  19.  window.location.href = link;
  20.  }
  21. }, true);

Tags: , , ,