Created
December 1, 2012 00:57
-
-
Save adison/4179848 to your computer and use it in GitHub Desktop.
google search change page with arrow kets(left/right)
This file contains 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
/* | |
在 Google 頁面使用方向鍵切換上一頁、下一頁 | |
Change result page with Arrow keys(left/right) on google search pages. | |
請搭配以下環境參數和 Personalized Web 參數使用 | |
env: chrome with extension "Personalized Web" ( https://chrome.google.com/webstore/detail/personalized-web/plcnnpdmhobdfbponjpedobekiogmbco ) | |
setting of Personalized Web: | |
Match URLs: ^https://www.google.com/search.* | |
Add JavaScript: add the following JS | |
*/ | |
var _detectspecialkeys = function (e){ | |
var evtobj=window.event? event : e; | |
var code = e.keyCode; | |
if (e.charCode && code == 0) | |
code = evtobj.charCode; | |
var _nav= document.getElementById('nav'); | |
var _tds=_nav.getElementsByTagName('td'); | |
var _cur=false; | |
for(var i=0;i<_tds.length;i++){ | |
if(!_cur && _tds[i].className==='cur' ) | |
_cur = i ; | |
} | |
switch(code) { | |
case 37: //left | |
if(_cur!==1) | |
window.location.href=_tds[_cur-1].getElementsByTagName('a')[0].getAttribute('href',0); | |
break; | |
case 39: //right | |
window.location.href=_tds[_cur+1].getElementsByTagName('a')[0].getAttribute('href',0); | |
break; | |
} | |
} | |
// change: | |
//add detector: if search textbox is focused, stop the arrow key handler | |
//加入判斷,焦點在搜尋框時,取消方向鍵作用 | |
var _gsfi=document.getElementsByClassName('gsfi'); | |
console.log('length' + _gsfi.length); | |
for(var i=0;i<_gsfi.length;i++){ | |
if(_gsfi[i].tagName==='INPUT'){ | |
var elem= _gsfi[i]; | |
elem.onfocus=function(e) { | |
window.onkeydown=null; | |
}; | |
elem.onblur=function(e) { | |
window.onkeydown=_detectspecialkeys; | |
}; | |
} | |
} | |
window.onkeydown = _detectspecialkeys; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment