Created
August 25, 2016 18:17
-
-
Save hmil/af5ade240b74b5ed3ead3c8684550221 to your computer and use it in GitHub Desktop.
Open a jira ticket in a new tab
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
/** | |
* === Goto JIRA === | |
* Handy userscript to visit a JIRA ticket. | |
* | |
* Installation: | |
* Embed this piece of javascript prefixed with javascript: in a bookmark. | |
* | |
* Usage: | |
* 1. Highlight a piece of text containing the jira ticket number you want to visit | |
* 2. Click on the bookmarklet to open the ticket in a new tab | |
*/ | |
(function(ctx) { | |
function createEl() { | |
var el = ctx.document.createElement('div'); | |
el.style.position = "fixed"; | |
el.innerText = "Highlight a JIRA ticket number..."; | |
el.style.top = "0"; | |
el.style.backgroundColor = "red"; | |
el.style.fontSize = "23pt"; | |
return el; | |
} | |
function init() { | |
var jira_base = "https://singularity.jira.com/browse/"; | |
var data = ctx.JIRA_USERSCRIPT_DATA; | |
if (typeof data == 'undefined') { | |
data = ctx.JIRA_USERSCRIPT_DATA = { | |
bound: false, | |
handler: function() { | |
var sel = ctx.getSelection().toString(); | |
var match; | |
if (match = sel.match(/([A-Z]{3,10}-\d{5,7})/)) { | |
ctx.open(jira_base + match[0]); | |
unbind(); | |
return true; | |
} | |
return false; | |
}, | |
el: createEl() | |
}; | |
} | |
return data; | |
} | |
function unbind() { | |
ctx.removeEventListener('mouseup', data.handler); | |
data.bound = false; | |
data.el.parentElement.removeChild(data.el); | |
} | |
function bind() { | |
ctx.addEventListener('mouseup', data.handler); | |
data.bound = true; | |
ctx.document.body.appendChild(data.el); | |
} | |
var data = init(); | |
if (data.bound) { | |
unbind(); | |
} else if (!data.handler()) { | |
bind(); | |
} | |
}(window)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment