Google access keys

By ms609 Last update Jul 30, 2011 — Installed 600 times.

There are 7 previous versions of this script.

// ==UserScript==
// @name           Google access keys
// @namespace      google.com
// @description    Allows the type of Google search to be changed quickly using "Shift - Alt acceskeys (Apple: Option key)".
// @include        http://*.google.*
// @version        0.15 - Yet more improvements from Orion751
// @version        0.14 - More improvements from Orion751
// @version        0.13 - Add more accesskeys: thanks, Orion751!
// @version        0.12 - Remove 'Scholar pro' link and improve positioning of Wikipedia link
// @exclude        http://*.google.com/ig
// @exclude        http://*.google.com/a/*
// ==/UserScript==

//TODO add j + k for next and previous pages
//TODO add a for advanced search
//TODO Consider adding access keys to GMail

var links = document.getElementsByTagName("a"); morelink=false;
for (i=0; i<links.length; i++) {
    if (links[i].innerHTML == "Scholar") {links[i].accessKey = "s"; var scholar = links[i];}

	//TODO Clean up
	//Old code for older pages that do not have the new top menu bar layout
	else if (links[i].innerHTML == "Web") {links[i].accessKey = "w";}
	else if (links[i].innerHTML == "Images") {links[i].accessKey = "i";}
	else if (links[i].innerHTML == "News") {links[i].accessKey = "n";}
	else if (links[i].innerHTML == "Maps") {links[i].accessKey = "m";}
	else if (links[i].innerHTML == "Groups") {links[i].accessKey = "g";}
	else if (links[i].innerHTML == "Shopping") {links[i].accessKey = "p";}
	else if (links[i].innerHTML == "Videos") {links[i].accessKey = "v";}

    else if (links[i].lastChild.innerHTML == "Web") {links[i].accessKey = "w";}
    else if (links[i].lastChild.innerHTML == "Images") {links[i].accessKey = "i";}
    else if (links[i].lastChild.innerHTML == "News") {links[i].accessKey = "n";}
    else if (links[i].lastChild.innerHTML == "Maps") {links[i].accessKey = "m";}
    else if (links[i].lastChild.innerHTML == "Groups") {links[i].accessKey = "g";}
    else if (links[i].lastChild.innerHTML == "Shopping") {links[i].accessKey = "p";}
    else if (links[i].lastChild.innerHTML == "Videos") {links[i].accessKey = "v";}
    else if (links[i].innerHTML == "Realtime") {links[i].accessKey = "r";}
        //TODO Fix
    else if (links[i].className == "gb3" ) {morelink = links[i];}
}

/* Just doodling around to see what would happen if I applied accesskeys to the sidebar instead...

var links = document.getElementById('ms').getElementsByTagName('li'); morelink=false;
for (i=0; i<links.length; i++) {
    if (links[i].innerHTML == "Scholar") {links[i].accessKey = "s"; var scholar = links[i];}
    else if (links[i].lastChild.innerHTML == "Web") {links[i].accessKey = "w";}
    
    else if (links[i].lastChild.textContent == "Everything") {links[i].firstChild.accessKey = "w";}
    else if (links[i].lastChild.textContent == "Images") {links[i].firstChild.accessKey = "i";}
    else if (links[i].lastChild.textContent == "News") {links[i].firstChild.accessKey = "n";}

    
    else if (links[i].lastChild.innerHTML == "News") {links[i].accessKey = "n";}
    else if (links[i].lastChild.innerHTML == "Maps") {links[i].accessKey = "m";}
    else if (links[i].lastChild.innerHTML == "Groups") {links[i].accessKey = "g";}
    else if (links[i].lastChild.innerHTML == "Shopping") {links[i].accessKey = "p";}
    else if (links[i].lastChild.innerHTML == "Videos") {links[i].accessKey = "v";}
    else if (links[i].innerHTML == "Realtime") {links[i].accessKey = "r";}
        //TODO Fix
    else if (links[i].className == "gb3" ) {morelink = links[i];}
}
*/
    
// The code beneath this line adds the "Scholar Pro" and Wikipedia links. 
// Delete everything from here down if you want rid of them!

if (morelink && typeof('morelink') != "undefined") {
    
    //TODO Fix
    //Wikipedia
    wiki = document.createElement("a");
    wiki.accessKey = ("d");
    wiki.style.fontWeight = "normal";
    wiki.className = "q";
    wiki.innerHTML = "Wikipedia";
    w = /\Wq=([^&]*)/;
    if (window.location.href.match(w)) {
        var wikisearch = w.exec(window.location.href);
        wiki.href = "http://en.wikipedia.org/w/index.php?title=" + wikisearch[1];
    } else {wiki.href = "http://en.wikipedia.org/wiki/Special:Search?fulltext=Search";}
    space = document.createElement("span");
    space.innerHTML = "  ";
    morelink.parentNode.insertBefore(wiki, morelink);
    morelink.parentNode.insertBefore(space, morelink);
}