SearchJump Improved

By yuguang Last update Aug 23, 2009 — Installed 141 times. Daily Installs: 0, 0, 0, 1, 2, 0, 1, 0, 1, 0, 0, 3, 0, 0, 2, 2, 0, 0, 4, 0, 0, 0, 0, 2, 0, 0, 3, 0, 0, 0, 0, 0

There are 7 previous versions of this script.

// ==UserScript==
// @name          SearchJump
// @description      Allows you to jump quickly between search results on different engines.
// ==/UserScript==


// Modifications
// ---------------------------------
// searchenginearray[i][0] - Search engine name
// searchenginearray[i][1] - Querystring variable key for keywords entered
// searchenginearray[i][2] - URL portion identifying search from this engine
// searchenginearray[i][3] - Search URL ("--keywords--" to be replaced by searched-for keywords)
// searchenginearray[i][4] - Whether to show this engine in list or not
// searchenginearray[i][5] - Search engine favicon



(function() {

    var searchenginearray = new Array();
    var lg = new Array();

    searchenginearray[0] = new Array('Bing', 'q', 'google.', 'http://search.msn.com/results.aspx?q=--keywords--&FORM=QBHP', 1, 'http://search.msn.com/favicon.ico');
    searchenginearray[1] = new Array('Ask', 'q', 'ask.', 'http://web.ask.com/web?q=--keywords--&qsrc=0&o=0', 1, 'http://www.ask.com/favicon.ico');
    searchenginearray[2] = new Array('Yahoo Directory', 'p', 'google.', 'http://search.yahoo.com/search/dir?p=--keywords--', 0, 'http://www.yahoo.com/favicon.ico');
    searchenginearray[3] = new Array('DMOZ', 'search', 'google.', 'http://search.dmoz.org/cgi-bin/search?search=--keywords--', 1, 'http://dmoz.org/favicon.ico');
    searchenginearray[4] = new Array('ChaCha', '', 'google.', 'http://www.chacha.com/search/--keywords--', 1, 'http://www.chacha.com/favicon.ico');
    searchenginearray[5] = new Array('Zuula', 'st', 'google.', 'http://www.zuula.com/SearchResult.jsp?bst=1&prefpg=1&st=--keywords--&x=0&y=0', 1, 'http://www.zuula.com/favicon.ico');
    searchenginearray[6] = new Array('Clusty', 'query', 'clusty.', 'http://clusty.com/search?input-form=clusty-simple&v%3Asources=webplus&query=--keywords--', 1, '');
    searchenginearray[7] = new Array('WolframAlpha', 'i', 'google.', 'http://www01.wolframalpha.com/input/?i=--keywords--', 1, 'http://www.wolframalpha.com/favicon.ico');
    searchenginearray[8] = new Array('searchme', 'q', 'google.', 'http://www.searchme.com/lite/?q=--keywords--', 0, 'http://www.searchme.com/favicon.ico');    
    searchenginearray[9] = new Array('Footnote', 'query', 'go.footnote.', 'http://go.footnote.com/results.php?query=--keywords--&vs=1&s_given-name=&s_surname=&gteq_year=&lteq_year=&s_place=', 1, 'http://go.footnote.com/favicon.ico');    
    searchenginearray[10] = new Array('Scour', '', 'google.', 'http://www.scour.com/search/web/--keywords--', 1, 'http://www.scour.com/favicon.ico');
    searchenginearray[11] = new Array('Viewzi', '', 'google.', 'http://www.viewzi.com/search/power_grid/--keywords--', 1, 'http://www.viewzi.com/favicon.ico');    
    searchenginearray[12] = new Array('Delicious', 'p', 'google.', 'http://delicious.com/search?p=--keywords--&u=&chk=&context=&fr=del_icio_us&lc=0', 1, 'http://delicious.com/favicon.ico');        
    searchenginearray[13] = new Array('Quintura', 'request', 'google.', 'http://quintura.com/?request=--keywords--&lng=en&r1=from&r2=browser', 1, 'http://quintura.com/favicon.ico');
    searchenginearray[14] = new Array('DeepDyve', 'query', 'google.', 'http://www.deepdyve.com/search?query=--keywords--&subjectArea[]=wikipedia&subjectArea[]=clean_technology_and_energy&subjectArea[]=it_and_engineering&subjectArea[]=web&subjectArea[]=other', 1, 'http://deepdyve.com/favicon.ico');
    searchenginearray[15] = new Array('Kosmix', '', 'google.', 'http://www.kosmix.com/topic/--keywords--', 1, 'http://kosmix.com/favicon.png');
    searchenginearray[16] = new Array('Google Squared', 'q', 'google.', 'http://www.google.com/squared/search?q=--keywords--', 1, 'http://google.com/favicon.ico');	
    searchenginearray[17] = new Array('blinkx', '', 'google.', 'http://www.blinkx.com/videos/--keywords--', 0, 'http://blinkx.com/favicon.ico');	
    
    searchenginearray.sort();

    var r = escape(document.referrer);
    var u = escape(document.location.href);
    var b = document.getElementById("searchSideBar");
    var d = document.location.host;
    var q = document.location.search;
    var e = -1;
    var t = '';

    var toggle = 'left';
    var togglew;
    var clicks = 0;

    var keywords = '';
    var qvar;

    var linkstyle = '';
    var footerlinkstyle = "text-align: left; white-space: nowrap; text-decoration: none; background: #fff; margin: 0 10px 3px 10px; padding: 3px 8px 3px 8px; display: block; color: #00c; font-size: 80%;";

    for (i = 0; i < searchenginearray.length; i++) {
        t = searchenginearray[i][2];
        if (d.indexOf(t) != -1) {
            e = i;
        }
    }

    q = q.slice(1);

    if ((q.length > 0) && (e != -1)) {
        // There's a querystring and it's a search referral
        var qspairs = q.split('&');
        for (k = 0; k < qspairs.length; k++) {
            qvar = qspairs[k].split('=');
            if (qvar[0] == searchenginearray[e][1]) {
                qvar[0] = '';
                keywords = qvar.join('=').slice(1);
            }
        }
    }

    function make_boxes() {
        if ((!b) && (keywords != '')) {
            b = document.createElement("div");
            b.setAttribute("id","searchSideBar");
            b.setAttribute("style","position: fixed; bottom: 20px; right: 0; padding: 10px 0; background: #eee; border: 1px solid #ccc; border-right: 0; width: 150px; overflow: hidden;");

                for (i = 0; i < searchenginearray.length; i++) {

                    if (searchenginearray[i][4] == 1) {

                        linkstyle = "text-align: left; white-space: nowrap; text-decoration: none; background:  url('" + searchenginearray[i][5] + "') #FFF 1px center no-repeat; margin: 0 10px 3px 10px; padding: 3px 8px 3px 20px; display: block; color: #00c; font-size: 80%; outline: none; -moz-outline-style: none;";
                    
                        lg[i] = document.createElement("a")
                        lg[i].setAttribute("href", searchenginearray[i][3].replace('--keywords--', keywords));
                        lg[i].setAttribute("onClick","window.open(this.href,'newwin'); return false;");
                        lg[i].setAttribute("style", linkstyle);
                        addtext(lg[i], searchenginearray[i][0]);
                        b.appendChild(lg[i]);

                    }

                }

                ls = document.createElement("span")
                ls.setAttribute("style", "text-decoration: none; margin: 0 10px 3px 10px; padding: 3px 8px 3px 8px; display: block; color: #ddf; font-size: 80%; overflow: hidden;");
                addtext(ls, " ");
                b.appendChild(ls);

                li = document.createElement("a")
                li.setAttribute("href","http://yuguang.byethost11.com/wp/");
                li.setAttribute("style", footerlinkstyle);
                addtext(li, "Info / Updates");
                b.appendChild(li);

                lc = document.createElement("a")
                lc.setAttribute("style", footerlinkstyle);
                lc.setAttribute("href","#");
                lc.setAttribute("onClick","return false;");
                addtext(lc, 'Hide \u00BB');
                b.appendChild(lc);
                lc.style.textAlign = 'right';

            document.body.appendChild(b);
            b.addEventListener("click", toggle_box, false);
            return true;
        }
    }

    function toggle_box() {
        // Toggle tells you which way the box was last moved
        clicks++;
        togglew = eval(b.style.width.replace(/px/,""));
        if(clicks == 2) {
            if (toggle == 'right') {
                for (i = togglew; i < 150; i++) {
                    b.style.width = (i) + 'px';
                }
                toggle = 'left';
            } else {
                for (i = togglew; i > 5; i--) {
                    b.style.width = (i) + 'px';
                }
                toggle = 'right';
            }
            clicks = 0;
        }
        else if (toggle == 'right') {
            for (i = togglew; i < 150; i++) {
                b.style.width = (i) + 'px';
            }
            toggle = 'left';
        }
    }

    function go() {
        make_boxes();
    }

    function addtext(obj, text) {
        var content = document.createTextNode(text);
        obj.appendChild(content)
    }

    function addEvent(objObject, strEventName, fnHandler) { 
        // DOM-compliant way to add an event listener 
        if (objObject.addEventListener) 
            objObject.addEventListener(strEventName, fnHandler, false); 
        // IE/windows way to add an event listener 
        else if (objObject.attachEvent) 
            objObject.attachEvent("on" + strEventName, fnHandler); 
    }
    
    window.addEventListener("load", go(), false);

})();