Skip to content

Instantly share code, notes, and snippets.

@rudiedirkx
Created November 22, 2013 13:17
Show Gist options
  • Save rudiedirkx/7599720 to your computer and use it in GitHub Desktop.
Save rudiedirkx/7599720 to your computer and use it in GitHub Desktop.
Google Search TAB
ready(function() {
if ( location.pathname == '/search' ) {
var s = document.getElementById('gbqfq');
if ( s ) {
s.focus();
s.addEventListener('keydown', function(e) {
if ( e.keyCode == 9 ) {
e.preventDefault();
var rso = document.getElementById('rso'),
firstA = rso ? rso.querySelector('a') : null;
firstA.focus();
}
});
}
[].forEach.call(document.querySelectorAll('#rso li.g'), function(li) {
li.addEventListener('keydown', function(e) {
if ( e.target.webkitMatchesSelector('h3 a') && ( e.keyCode == 37 || e.keyCode == 39 ) ) {
e.preventDefault();
var sel = e.keyCode == 37 ? 'previous' : 'next',
focusLI = li[sel + 'ElementSibling'],
focus = focusLI ? focusLI.querySelector('h3 a') : null;
if ( sel == 'previous' && !focus ) {
focus = s;
}
focus && focus.focus();
}
}, true);
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment