// ==UserScript==
// @name          Google Cache plus
// @namespace     http://persistent.info/greasemonkey
// @description	  Click on next search word position
// @include       http://*/search?q=cache*

// ==/UserScript==

(function() {
    var buf = location.search;
    var pos_start = buf.indexOf("+");
    var pos_end   = buf.indexOf("&");
    var str = buf.substring(pos_start + 1, pos_end);
    var searchwords = new Array();
    searchwords = str.split("+");
    for (i = 0; i < searchwords.length; i++) {
        searchwords[i] = decodeURI(searchwords[i].toLowerCase());
    }

    var el = document.getElementsByTagName("b");
    var idx = 0;
    for (i = 0; i < el.length; i++) {
        //  toLowerCase()
        for (j = 0; j < searchwords.length; j++) {
            if (el[i].innerHTML.toLowerCase() == searchwords[j]) {
                el[i].innerHTML = "<a name='idx" + idx + "'>" + el[i].innerHTML + "</a>";
                idx++;
            }
        }
    }

    var k = 0;
    window.addEventListener("click", function(e) {
        location.hash = "idx" + k;
        k++;
        k = k > idx ? 0 : k;
    }, false);
})();

