Skip to content

Instantly share code, notes, and snippets.

@satyr
Created October 27, 2008 23:31
Show Gist options
  • Save satyr/20238 to your computer and use it in GitHub Desktop.
Save satyr/20238 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name google-one-touch
// @description Adds keyboard shortcuts to each entry.
// @namespace http://d.hatena.ne.jp/murky-satyr
// @include http://www.google.tld/*
// ==/UserScript==
var splinks = document.getElementById('mbEnd');
if(splinks) splinks.parentNode.removeChild(splinks);
addEventListener('load', function onload(){
removeEventListener('load', onload, false);
var H3 = document.getElementsByTagName('h3');
if(!H3.length) return;
var h3s = [];
Array.slice(H3, 0, 36).forEach(function(h, i){
if(h.className !== 'r') return;
h.innerHTML = <span style='font:bold 100% mono-space'>{
((i + 10) % 36).toString(36)}: </span>.toXMLString() + h.innerHTML;
h3s.push(h);
});
document.addEventListener('keydown', function(e){
var k = e.keyCode;
if(e.ctrlKey || e.altKey || /[^0-9A-Z]/.test(String.fromCharCode(k)) ||
/^(?:TEXTAREA|INPUT)$/.test(document.activeElement.tagName)) return;
var h = h3s[k < 58 ? k % 48 + 26 : k - 65];
if(!h) return;
var u = h.getElementsByTagName('a')[0].href;
e.shiftKey ? location.href = u : open(u);
}, false);
}, false);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment