Hack #55. Autocomplete Search Terms as You Type
Google can suggest your search terms before you even finish typing them.
It's true: Google is clairvoyant. It can guess what you're going to search for even before you've typed it. Well, maybe that overstates it. But it can certainly take an educated guess, based on the popularity and number of results of certain keywords.
Don't believe me? Visit http://www.google.com/webhp?complete=1 and start typing, and Google will autocomplete your query after you've typed just a few characters. This is insanely cool, and virtually nobody knows about it. And even people "in the know" need to visit a special page to use it. This hack makes this functionality work everywhere—even on the Google home page (http://www.google.com).
The Code
This user script runs on all Google pages, but it works only on pages with a search form. Of course, being Google, this is most pages, including the home page and web search result pages.
This hack doesn't do any of the autocompletion work itself. It relies entirely on Google's own functionality for suggesting completions for partial search terms, defined entirely in http://www.google.com/ac.js. All we need to do is create a <script>
element pointing to Google's own code, and insert it into the page. Then, we tell Google to activate it by adding another <script>
element that calls Google's own InstallAC
function.
Save the following user script as google-autocomplete.user.js:
// ==UserScript== // @name Google Autocomplete ...
Get Greasemonkey Hacks now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.