Google Live Search 29

This is a script for Greasemonkey
that modifies the Google search page to make
the results show up as you type.

Steps to install:

  1. Install Greasemonkey
  2. Once that is done you can right click the following link and select
    Install User Script…: googlelivesearch.user.js

The Details

When the user types in the search field the browser fires the
input event. This event is dispatched any time the content changes
(for example when doing drag and drop or copy paste). When this happens a timer
is started and a few milliseconds later a HTTP GET request is sent
to http://www.google.com/search?q=. The
reason to use a timer here is to prevent a request to be sent after every change
and only send the request when the value of the input stabilizes. This request
is sent in the background using a XMLHttpRequest
object.

Once we get the result we remove the old results from the page using DOM
level 1 methods. Then we analyze the returned string and use
innerHTML to input the result into the current page. You have to
use innerHTML because Mozilla cannot parse text/html without
creating a view (frame/window) for it.

Udpated:

I added a hash to document.location so that when one goes back the search page the result is remembered.

  • http://me.eae.net Emil

    Nice one, seems like a silly thing but it’s actually quite helpful to see the results for the given criteria as you type, and the speed is impressive.

    Too bad I can’t get greasemonkey to run under dpa1.

  • http://erik.eae.net Erik Arvidsson

    I’m getting really tired of the internal Firefox exception that always happen when working with text inputs:

    Error: [Exception... "'Permission denied to get property XULElement.selectedIndex' when calling method: [nsIAutoCompletePopup::selectedIndex]” nsresult: “0x8057001e (NS_ERROR_XPC_JS_THREW_STRING)” location: “JS frame :: http://www.google.com/#gls=google%20live%20search :: anonymous :: line 135″ data: no]
    Source File: http://www.google.com/#gls=google%20live%20search
    Line: 135

  • http://me.eae.net Emil

    I hear you, those kind of errors are frustrating and really should never happen. Seems to occur in a quasi-random fashion too (during similar circumstances but only occasionally)… which doesn’t make things easier to track down.

  • http://erik.eae.net Erik Arvidsson

    I believe they happen any time focus() is being called from script.

    https://bugzilla.mozilla.org/show_bug.cgi?id=236791

  • http://me.eae.net Emil

    Hmm, figured it had something to do with focusing but I do seem to recall it happening when focus is gained in other ways too…

  • http://www.forgetfoo.com/ foO

    damn, i cant even tell you how many times i’ve seen that damn error in the JS Concole in firefox of late… been driving me absolutely crazy, man.

    hell, i removed my little Comment Notifier (temporarily?) because i was getting random XML “Unknown.” errors, which i was never really able to track down properly, which sucks.

    this is really kewl, btw… it’s like that “Live Search”, but for Google :)

    luv’n it… heh.

  • http://www.reifysoft.com/ Matt McCarthy

    Neat!

    Works flawlessly on the home page. I get a few errors on the search result page when I modify my search:
    – elmAdvanced has no properties / 174 several times
    – this.footerElement.parentNode has no properties / 125
    – A Greasemonkey message saying “Exception when injecting : {}”

    Doesn’t work in Turnabout for IE yet, though. Doesn’t look like it would be hard to port, though. Do you have any plans to port it? This (and equivalents for Yahoo and MSN) might be a good candidate for including with future releases.

  • http://visitjesper.homeip.net Jesper Rønn-Jensen

    Nice. This really motivates me to dive into these greasemonkey scripts.
    Adrian Holovaty created a similar script which is more-or-less directly the functionality of Google Suggest.

  • http://erik.eae.net Erik Arvidsson

    Matt: I was actually planning to spend some work on this today but I had some high priority things holding me up the entire evening/night. I’ll look at it tomorrow.

  • http://erik.eae.net Erik Arvidsson

    Matt: elmAdvanced is not from my script

    I saw the Greasemonkey exception a few times when developing this but reinstalling the script solved that for me.

    I’m still investigating the this.footerElement.parentNode error. I don’t see this but I guess some other script tampering with innerHTML might be the cause for this (innerHTML is evil)

  • Pingback: azadworks.com - Blog Archive - Google Live Search

  • Edible Energy

    I put a link up to this script on Metafilter today, and someone noticed that going to google autosuggest causes an infinite loop.

  • Rafi B.

    A solution for this error:
    Error: [Exception… “‘Permission denied to get property XULElement.selectedIndex’ when calling method: [nsIAutoCompletePopup::selectedIndex]”

    Just put autocomplete=”off” on an input you’re getting this error on,
    or use this script to go through all your necessary elements and “fix” them:

    if (document.getElementsByTagName)
    {
    var inputElements = document.getElementsByTagName(“input”);
    for (i=0; inputElements[i]; i++)
    inputElements[i].setAttribute(“autocomplete”,”off”);
    }

    Still no word from Mozilla about this awful bug.
    (https://bugzilla.mozilla.org/show_bug.cgi?id=236791)

  • http://erik.eae.net Erik Arvidsson

    Rafi: This bug has been fixed in 1.5 b1

  • ezuk

    It just doesn’t work for me… I have Greasemonkey and FF1.5 and the script is enable for http://www.google.com/* under “Manage User Scripts”. And yet, no go…

  • ezuk

    What it basically says in the Javascript console whenever I type a char and wait is:
    “Error: XMLHttpRequest is not a constructor
    Source File:
    Line: 165″

    And right when I load google it says:
    “Error: Selector expected. Ruleset ignored due to bad selector.
    Source File: http://www.google.com/
    Line: 5
    Error: Unexpected end of file while searching for closing } of invalid rule set.
    Source File: http://www.google.com/
    Line: 6″

  • http://www.vertexlogic.com Anil Sharma

    The following error seems to always occur when calling focus/ blur from a onkeydown event handler.

    Error: [Exception... "'Permission denied to set property XULElement.selectedIndex' when calling method: [nsIAutoCompletePopup::selectedIndex]” nsresult: “0x8057001e (NS_ERROR_XPC_JS_THREW_STRING)” location: “JS frame ::

  • http://erik.eae.net Erik Arvidsson

    Anil: That is a known Firefox bug which has been fixed in 1.5 I believe.

  • Juan F. Moncada

    Hi all: I had the same problem (“Permission denied to set property…”) and I’ve been able to solve it with Rafi’s suggestion on September 12th (thanks for your help). I’m using Firefox 1.5.0.1, so this issue hasn’t been solved in 1.5.

  • http://erik.eae.net Erik Arvidsson

    The bug is still in Firefox 1.5… I’m not sure about Firefox 2.0 alphas.

  • http://dylan.doxey.org/ Dylan Doxey

    Hi, in my DOM code I have generally used the convention of setting attributes like this:
    var inp = document.createElement(‘input’);
    inp.autocomplete = ‘off’;

    However this does not do the trick for the autocomplete attribute, because it is probably not added by the createElement() method.

    This does work:
    var inp = document.createElement(‘input’);
    inp.setAttribute(‘autocomplete’,’off’);

    Thanks for the tip!

    Dylan

  • http://erik.eae.net Erik Arvidsson

    The auto complete feature is a pretty strange beast. Setting this does not really do anything to the element. The auto complete system checks for an expando property called autocomplete instead.

    In Firefox there is a difference (rightly so) between JS/DOM properties and attributes and there isn’t any DOM property called autocomplete.

  • derak

    You helped me fix a bug. Thank you.

  • http://www.eer.cc EER

    You helped me fix an annoying message, thanks a lot :)

  • http://www.zanstudio.com dirar

    Not fixed in 1.8, don’t know about 2… but autocomplete = “OFF” solved the problem

  • Steve Bearman

    A simpler solution than setting ‘autocomplete’ = ‘off’ for each element is to set the property for the form itself. The property is then inherited by all the form elements.

  • http://www.grimaldionline.co.uk Spam Banjo @ The Hell Hole

    This worked for me.

    1 prev_field = document.forms['meterform'].elements[last_one] ;
    2 prev_field.setAttribute(“autocomplete”,”off”);
    3 prev_field.focus();

    If I remove line 2 I get the error. Otherwise it’s fine. I now employ this method as standard practice when manipulating field focus and it seems to work fine for me.

  • Pingback: tkdmatze » Blog Archiv » Einstiegsdroge Userscripts

  • Pingback: free website audit report, seo audit document, google seo audit, free seo audit tool, seo technical audit, seo audit service, search engine optimzation audit, free seo site audit