Skip to content

Instantly share code, notes, and snippets.

@adison
Created November 30, 2012 20:36
Show Gist options
  • Save adison/4178423 to your computer and use it in GitHub Desktop.
Save adison/4178423 to your computer and use it in GitHub Desktop.
mobile 01 方向鍵換頁
/*
請搭配以下環境參數和 Personalized Web 參數使用
環境: chrome,搭配 extension "Personalized Web" ( https://chrome.google.com/webstore/detail/personalized-web/plcnnpdmhobdfbponjpedobekiogmbco )
Personalized Web 設定
Match URLs: ^http://www.mobile01.com/topicdetail.php.*
Add JavaScript: 加入以下內容
*/
function detectspecialkeys(e){
var evtobj=window.event? event : e;
var code = e.keyCode;
if (e.charCode && code == 0)
code = evtobj.charCode;
switch(code) {
case 37:
var _href = window.location.href;
if(_href.lastIndexOf('p=') >=0){
var _count = _href.substring(_href.lastIndexOf('=')+1,_href.length);
if(parseInt(_count) >=2){
var _newCount = parseInt(_count)-1;
var _new= _href.substring(0,_href.lastIndexOf('=')+1) + _newCount;
console.log(_new);
window.location.href=_new;
}
}
break;
case 39:
var _href = window.location.href;
if(_href.lastIndexOf('p=') >=0){
var _count = _href.substring(_href.lastIndexOf('=')+1,_href.length);
var _newCount = parseInt(_count)+1;
var _new= _href.substring(0,_href.lastIndexOf('=')+1) + _newCount;
} else
var _new= _href+'&p=2';
window.location.href=_new;
break;
}
}
window.onkeydown=detectspecialkeys;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment