Last active
September 29, 2017 23:11
-
-
Save asm256/747a08b74b55887634bb to your computer and use it in GitHub Desktop.
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
// ==UserScript== | |
// @id narou_reader | |
// @name なろうをキーボードで読みたい | |
// @version 1.2 | |
// @updateURL https://gist.githubusercontent.com/asm256/747a08b74b55887634bb/raw/narou_shortcut.user.js | |
// @downloadURL https://gist.githubusercontent.com/asm256/747a08b74b55887634bb/raw/narou_shortcut.user.js | |
// @author asm__ | |
// @description nを押すと次のページへ移動します Scriptish/Greasemonkey兼用…のつもり | |
// @include https://novel18.syosetu.com/n* | |
// @include https://ncode.syosetu.com/n* | |
// @require https://gist.github.com/54a5327db50607678b62.txt | |
// @run-at document-end | |
// ==/UserScript== | |
var next =GM_xpath({ | |
path:"//div[@class='novel_bn']/a[contains(text(),'次へ')]" | |
}); | |
var index=GM_xpath({path: | |
"//div[@class='novel_bn']/a[contains(text(),'目次')]" | |
}); | |
var before=GM_xpath({path: | |
"//div[@class='novel_bn']/a[contains(text(),'前へ')]" | |
}); | |
if(index){ | |
var disableKey = false; | |
var INPUTS = ['INPUT', 'TEXTAREA']; | |
var method = window.sidebar ? 'keypress' : 'keydown'; | |
document.addEventListener(method, function (e) { | |
/* | |
document.title = 'keyCode: ' + e.keyCode + ' charCode: ' + e.charCode + ' which: ' + e.which | |
+ ","+String.fromCharCode(e.which); | |
/**/ | |
var pressed = String.fromCharCode(e.which).toLowerCase(); | |
var ckey = e.keyCode; | |
pressed = (e.ctrlKey ? 'C-' : '') + (e.altKey ? 'A-' : '') + (e.shiftKey ? 'S-' : '') + pressed; | |
if (!disableKey) { | |
disableKey = true; | |
if (INPUTS.indexOf(e.target.tagName) != -1 ) | |
return; | |
if(pressed == 'n' && next) | |
next.click(); | |
if(pressed == 'x') | |
index.click(); | |
if(pressed == 'b' && before) | |
before.click(); | |
if(ckey == 37 && before) | |
before.click(); | |
if(ckey == 39 && next) | |
next.click(); | |
disableKey = false; | |
} | |
}, false); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment