Hack 51. Link to Other Search Engines from Google

 < Day Day Up > 

Make Google even more useful by adding links to competitors.

When Google was young and scrappy (circa 2001), it had an interesting feature. At the bottom of the search results page, Google offered links to try your search on the other major search engines of the day: AltaVista, Hot-bot, Excite, and a few others. The thinking behind it was that maybe you didn't find what you were looking for this time, but you should still try Google first on your next search.

Google is all grown up now, and they are the undisputed king of web search. Somewhere along the way to the top, they quietly dropped this feature. This hack brings it back.

6.6.1. The Code

This user script runs on Google search result pages. It retrieves the original query from the search form at the top of the page, then constructs a list of links to other search engines and inserts them at the top of the search results.

Save the following user script as tryyoursearchon.user.js:

 // ==UserScript== // @name    Try Your Search On // @namespace    http://diveintomark.org/projects/greasemonkey/ // @description    Link to competitors from Google search results // @include    http://www.google.tld/search* // ==/UserScript== // based on Butler // http://diveintomark.org/projects/butler/ function getOtherWebSearches(q) { q = escape(q); return '' + '<a href="http://search.yahoo.com/search?p=' + q + '">Yahoo</a>, ' + '<a href="http://web.ask.com/web?q=' + q + '">Ask Jeeves</a>, ' + '<a href="http://alltheweb.com/search?q=' + q + '">AlltheWeb</a>, ' + '<a href="http://s.teoma.com/search?q=' + q + '">Teoma</a>, ' + '<a href="http://search.msn.com/results.aspx?q=' + q + '">MSN</a>, ' + '<a href="http://search.lycos.com/default.asp?query=' + q + '">Lycos</a>, ' + '<a href="http://technorati.com/cosmos/search.html?url=' + q + '">Technorati</a>, ' + '<a href="http://feedster.com/search.php?q=' + q + '">Feedster</a>, ' + '<a href="http://daypop.com/search?q=' + q + '">Daypop</a>, ' + '<a href="http://bloglines.com/search?t=1&amp;q=' + q + '>Bloglines</a>'; } function addOtherWebSearches() { var elmHeader = document.evaluate("//table[@bgcolor='#e5ecf9']", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue; if (!elmHeader) return; var q = document.forms.namedItem('gs').elements.namedItem('q').value; var elmOther = document.createElement('div'); var html = '<p style="font-size: small">Try your search on '; html += getOtherWebSearches(q); html += '</p>'; elmOther.innerHTML = html; elmHeader.parentNode.insertBefore(elmOther, elmHeader.nextSibling); } addOtherWebSearches(); 

6.6.2. Running the Hack

After installing the user script (Tools Install This User Script), go to http://www.google.com and search for anything. At the top of the search results, youll see a line with links to execute the same query on other search engines, as shown in Figure 6-9.

Figure 6-9. "Try your search on" other search engines


6.6.3. Hacking the Hack

Of course, Google can do more than just search the Web. It also lets you search for images. And of course there are lots of other image search engines. Some specialize in free images, others in commercial images. Some sites, such as Flickr (http://www.flickr.com) let you publish your own photos and search photos that other people have published. It sounds like Google Image Search needs a makeover.

Save the following user script as tryyoursearchon2.user.js:

 // ==UserScript== // @name Try Your Search On // @namespace http://diveintomark.org/projects/greasemonkey/ // @description Link to competitors from Google web and image search // @include http://www.google.tld/search* // @include http://images.google.tld/images* // ==/UserScript== function getOtherWebSearches(q) { q = escape(q); return '' + '<a href="http://search.yahoo.com/search?p=' + q + '">Yahoo</a>, ' + '<a href="http://web.ask.com/web?q=' + q + '">Ask Jeeves</a>, ' + '<a href="http://alltheweb.com/search?q=' + q + '">AlltheWeb</a>, ' + '<a href="http://s.teoma.com/search?q=' + q + '">Teoma</a>, ' + '<a href="http://search.msn.com/results.aspx?q=' + q + '">MSN</a>, ' + '<a href="http://search.lycos.com/default.asp?query=' + q + '">Lycos</a>, ' + '<a href="http://technorati.com/cosmos/search.html?url=' + q + '">Technorati</a>, ' + '<a href="http://feedster.com/search.php?q=' + q + '">Feedster</a>, ' + '<a href="http://www.daypop.com/search?q=' + q + '">Daypop</a>, ' + '<a href="http://bloglines.com/search?t=1&amp;q=' + q + '>Bloglines</a>'; } function addOtherWebSearches() { var elmHeader = document.evaluate("//table[@bgcolor='#e5ecf9']", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue; if (!elmHeader) return; var q = document.forms.namedItem('gs').elements.namedItem('q').value; var elmOther = document.createElement('div'); var html = '<p style="font-size: small">Try your search on '; html += getOtherWebSearches(q); html += '</p>'; elmOther.innerHTML = html; elmHeader.parentNode.insertBefore(elmOther, elmHeader.nextSibling); } function getOtherImageSearches(q) { q = escape(q); return '' + '<a href="http://images.search.yahoo.com/search/images?p=' + q + '">Yahoo</a>, ' + '<a href="http://pictures.ask.com/pictures?q=' + q + '">Ask Jeeves</a>, ' + '<a href="http://www.alltheweb.com/search?cat=img&q=' + q + '">AlltheWeb</a>, ' + '<a href="http://search.msn.com/images/results.aspx?q=' + q + '">MSN</a>, ' + '<a href="http://www.picsearch.com/search.cgi?q=' + q + '">PicSearch</a>, ' + '<a href="http://www.ditto.com/searchResults.asp?ss=' + q + '">Ditto</a>, ' + '<a href="http://www.creatas.com/searchResults.aspx?' + 'searchString=' + q + '">Creatas</a>, ' + '<a href="http://www.freefoto.com/search.jsp?queryString=' + q + '">FreeFoto</a>, ' + '<a href="http://www.webshots.com/search?query=' + q + '">WebShots</a>, ' + '<a href="http://nix.larc.nasa.gov/search?qa=' + q + '">NASA</a>, ' + '<a href="http://www.flickr.com/photos/search/text:' + q + '">Flickr</a>';    return s; } function addOtherImageSearches() { var elmTable = document.evaluate(  "//a[starts-with(@href, '/images?q=')]/ancestor::table" + "[@width='100%'][@border='0'][@cellpadding='0'][@cellspacing='0']", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue; if (!elmTable) { return; } var elmTR = document.createElement('tr'); var q = document.forms.namedItem('gs').elements.namedItem('q').value; var html = '<td align="left"><span style="font-size: small">' + 'Try your search on '; html += getOtherImageSearches(q); html += '</span></td>'; elmTR.innerHTML = html; elmTable.appendChild(elmTR); } if (/^http:\/\/www\.google\.[\w\.]+\/search/i.test(location.href)) { addOtherWebSearches(); } else if (/^http:\/\/images\.google\.[\w\.]+\/images/i.test(location.href)) { addOtherImageSearches(); } 

After installing the user script (Tools Install This User Script), go to http://images.google.com and search for something. At the top of the image results, youll see a line with links to other image search engines and photo sites, as shown in Figure 6-10.

Figure 6-10. "Try your search on" other image search engines


Just click the search engine you want to use, and you will jump straight to the search results page for the same keywords.

     < Day Day Up > 


    Greasemonkey Hacks
    Greasemonkey Hacks: Tips & Tools for Remixing the Web with Firefox
    ISBN: 0596101651
    EAN: 2147483647
    Year: 2005
    Pages: 168
    Authors: Mark Pilgrim

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net