Last active
April 29, 2020 08:41
-
-
Save kaveenr/28a3424ec3aa9c5e477c2441046b06b3 to your computer and use it in GitHub Desktop.
Github Issue QuickKey Script For Tampermonkey
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
// ==UserScript== | |
// @name Github Issue QuickKey | |
// @namespace http://kaveenrodrigo.com/ | |
// @version 0.1 | |
// @description Quickly cycle through issues using Ctrl + NumPad plus/minus | Ctrl + Enter to jump to issue | |
// @author Kaveen Rodrigo | |
// @match https://github.com/*/*/issues/* | |
// @match https://github.com/*/*/pull/* | |
// @grant unsafeWindow | |
// ==/UserScript== | |
const IS_DEBUG = false; | |
(function() { | |
'use strict'; | |
document.addEventListener('keyup', handleKey, false); | |
function handleKey(event){ | |
if (!event.ctrlKey){ | |
return; | |
} | |
var url = unsafeWindow.location.href; | |
var nextUrl = null; | |
if (IS_DEBUG) console.log(event); | |
switch (event.keyCode) { | |
case 107: | |
nextUrl = getIssueURL(url, true, null); | |
break; | |
case 109: | |
nextUrl = getIssueURL(url, false, null); | |
break; | |
case 13: | |
var nextId = parseInt(prompt("Jump To ID")); | |
if(!Number.isInteger(nextId)) return; | |
nextUrl = getIssueURL(url, false, nextId); | |
break; | |
default: | |
return; | |
} | |
unsafeWindow.location.href = nextUrl; | |
} | |
function getIssueURL(location, isNext, skip){ | |
var urlParts = location.split("/"); | |
var issueIndice = urlParts.length - 1; | |
var issueId = parseInt(urlParts[issueIndice]) | |
if (skip == null) { | |
urlParts[issueIndice] = isNext ? (issueId + 1) : (issueId -1); | |
} else { | |
urlParts[issueIndice] = skip; | |
} | |
return urlParts.join("/"); | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment