Created
April 26, 2015 15:17
-
-
Save mbildner/c30fdc6b61d2a2cb19ae to your computer and use it in GitHub Desktop.
Fix google search results tab order
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;(function(document){ | |
'use strict'; | |
function qsArr (qsString) { | |
return [].slice.call(document.querySelectorAll(qsString)); | |
} | |
function getSearchResults () { | |
return qsArr('#rso h3 a'); | |
} | |
function getTabIndex (element) { | |
return +element.getAttribute('tabindex'); | |
} | |
function setTabIndex (element, index) { | |
element.setAttribute('tabindex', index.toString()); | |
return index; | |
} | |
function incrTabIndex(element, offset) { | |
var current = getTabIndex(element); | |
var incremented = current + offset; | |
setTabIndex(element, incremented); | |
return incremented; | |
} | |
var searchResultLinks = getSearchResults(); | |
var offset = searchResultLinks.length; | |
var existingTabs = qsArr('[tabindex]'); | |
existingTabs.forEach(function (element) { | |
incrTabIndex(element, offset); | |
}); | |
searchResultLinks.forEach(function (element, index) { | |
setTabIndex(element, index + 1); | |
}); | |
})(document); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Compiled using Google Closure Service: