Created
July 17, 2023 06:16
-
-
Save mu88/ec87ec748fca54dbeab889dbb002fba0 to your computer and use it in GitHub Desktop.
Copy Jira ticket identifier
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 Copy Jira ticket identifier | |
// @namespace http://tampermonkey.net/ | |
// @version 1.0 | |
// @description Concats the ticket number and title of a Jira ticket | |
// @author mu88 | |
// @match https://<<Jira>>/browse/* | |
// @icon https://<<Jira>>/s/<<Change>>/_/images/fav-generic.png | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
var containingElement = document.getElementById('opsbar-jira.issue.tools'); | |
var clickElement = document.createElement('a'); | |
clickElement.onclick = click; | |
clickElement.id = 'jira-copy-ticket-identifier'; | |
clickElement.href = '#'; | |
clickElement.classList.add('aui-button'); | |
clickElement.classList.add('toolbar-trigger'); | |
clickElement.innerText='Copy ticket identifier'; | |
containingElement.appendChild(clickElement); | |
function click () { | |
var ticketNumber = document.getElementById('key-val').innerText; | |
var ticketTitle = document.getElementById('summary-val').innerText; | |
var ticketUrl = window.location; | |
var concatenatedIdentifier = ticketNumber + ': ' + ticketTitle; | |
function listener(e) { | |
e.clipboardData.setData("text/html", '<a href="' + ticketUrl + '">' + concatenatedIdentifier +'</a>'); | |
e.clipboardData.setData("text/plain", concatenatedIdentifier); | |
e.preventDefault(); | |
} | |
document.addEventListener("copy", listener); | |
document.execCommand("copy"); | |
document.removeEventListener("copy", listener); | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment