Skip to content

Instantly share code, notes, and snippets.

@neongreen
Last active December 4, 2017 16:07
Show Gist options
  • Save neongreen/783f5fe5634f052c085bc9a22a93e7ca to your computer and use it in GitHub Desktop.
Save neongreen/783f5fe5634f052c085bc9a22a93e7ca to your computer and use it in GitHub Desktop.
GoToIssue.user.js
// ==UserScript==
// @name Youtrack go-to-issue
// @namespace http://tampermonkey.net/
// @version 0.4
// @description Go to issue quickly
// @author Artyom
// @match https://issues.serokell.io/*
// @match https://iohk.myjetbrains.com/youtrack/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
var issue = '';
var lastGPress = null;
var parseIssue = function (c) {
var matches;
// a four-digit number that starts with 1, 2 or 3
matches = c.match("^([1-3][0-9]{3})$");
if (matches) return("CSL-" + matches[1]);
// a three-digit number that doesn't start with 1, 2 or 3
matches = c.match("^([04-9][0-9]{2})$");
if (matches) return("CSL-" + matches[1]);
// an arbitrary number that ends with a “-” or “.”
matches = c.match("^([0-9]+)[-.]$");
if (matches) return("CSL-" + matches[1]);
// project code (2–6 letters), an optional “-” and a three-digit number
matches = c.match("^([a-zA-Z]{2,6})-?([0-9]{3})$");
if (matches) return(matches[1] + "-" + matches[2]);
// project code (2–6 letters), an optional “-” and an arbitrary number ending with a “-” or a “.”
matches = c.match("^([a-zA-Z]{2,6})-?([0-9]+)[-.]$");
if (matches) return(matches[1] + "-" + matches[2]);
return undefined; };
var goToIssue = function (c) {
if (parseIssue(c)) {
if (window.location.href.match(/serokell/))
window.location.href = "https://issues.serokell.io/issue/" + parseIssue(c);
if (window.location.href.match(/iohk/))
window.location.href = "https://iohk.myjetbrains.com/youtrack/issue/" + parseIssue(c);
} };
$(document).on("keypress", function (e) {
var code = e.keyCode || e.which;
var isInput = ($(document.activeElement).is('input') || $(document.activeElement).is('textarea')) &&
! ($(document.activeElement).is('.command-query'));
if ((code == 'g'.codePointAt() || code == 'п'.codePointAt()) && !isInput) {
issue = '';
lastGPress = Date.now(); } else
if (Date.now() - lastGPress <= 5000) {
issue = issue + String.fromCharCode(code);
if (parseIssue(issue)) {
goToIssue(issue);
issue = ''; } }
else
issue = '';
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment