Created
May 27, 2019 04:00
-
-
Save GitHub30/7059269be3054d719c8ca9924be43f59 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== | |
// @name GitHub Stars shortcut | |
// @namespace http://tampermonkey.net/ | |
// @version 0.1 | |
// @description Press p to move Prev. Press n to move Next | |
// @author You | |
// @match https://github.com/GitHub30?*tab=stars | |
// @grant none | |
// ==/UserScript== | |
// https://wiki.greasespot.net/XPath_Helper | |
function $x() { | |
var x=''; | |
var node=document; | |
var type=0; | |
var fix=true; | |
var i=0; | |
var cur; | |
function toArray(xp) { | |
var final=[], next; | |
while (next=xp.iterateNext()) { | |
final.push(next); | |
} | |
return final; | |
} | |
while (cur=arguments[i++]) { | |
switch (typeof cur) { | |
case "string": x+=(x=='') ? cur : " | " + cur; continue; | |
case "number": type=cur; continue; | |
case "object": node=cur; continue; | |
case "boolean": fix=cur; continue; | |
} | |
} | |
if (fix) { | |
if (type==6) type=4; | |
if (type==7) type=5; | |
} | |
// selection mistake helper | |
if (!/^\//.test(x)) x="//"+x; | |
// context mistake helper | |
if (node!=document && !/^\./.test(x)) x="."+x; | |
var result=document.evaluate(x, node, null, type, null); | |
if (fix) { | |
// automatically return special type | |
switch (type) { | |
case 1: return result.numberValue; | |
case 2: return result.stringValue; | |
case 3: return result.booleanValue; | |
case 8: | |
case 9: return result.singleNodeValue; | |
} | |
} | |
return fix ? toArray(result) : result; | |
} | |
(function() { | |
'use strict'; | |
var shortcutKey = ''; | |
var disableKey = false; | |
var INPUTS = ['INPUT', 'TEXTAREA']; | |
document.addEventListener('keydown', function (e) { | |
var pressed = String.fromCharCode(e.which).toLowerCase(); | |
pressed = (e.ctrlKey ? 'C-' : '') + (e.altKey ? 'A-' : '') + (e.shiftKey ? 'S-' : '') + pressed; | |
if (INPUTS.indexOf(e.target.tagName) == -1 && (pressed == 'p' || pressed == 'n')) { | |
e.preventDefault(); | |
if (!disableKey) { | |
disableKey = true; | |
// 処理 | |
if(pressed == 'p' && $x('//a[text()="Previous"]').length) $x('//a[text()="Previous"]')[0].click(); | |
if(pressed == 'n' && $x('//a[text()="Next"]').length) $x('//a[text()="Next"]')[0].click(); | |
disableKey = false; | |
} | |
} | |
}, false); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment