Last active
May 23, 2023 09:44
-
-
Save Leksat/c3e3eb67d82d2e51ea8d1955592182d3 to your computer and use it in GitHub Desktop.
Copy bookmarklet for Jira
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
javascript:(function(){ | |
const ticketNumber = | |
/* If we are on a Jira board. */ | |
location.search.match('[?&]selectedIssue=(.*?)([&]|$)')?.[1] || | |
/* If we are on the ticket page. */ | |
location.pathname.split('/').pop(); | |
const ticketSummary = document.getElementsByTagName('h1')[document.getElementsByTagName('h1').length-1].textContent.trim(); | |
const ticketUrl = `${location.origin}/browse/${ticketNumber}`; | |
const html = `<a href="${ticketUrl}">${ticketNumber} [${ticketSummary}]</a>`; | |
const text = `[${ticketNumber} ${ticketSummary}](${ticketUrl})`; | |
/* Chrome requires the document to have focus in order to call navigator.clipboard.write() */ | |
const t = document.createElement("textarea"); | |
document.body.appendChild(t); | |
t.select(); | |
document.body.removeChild(t); | |
navigator.clipboard.write([ | |
new ClipboardItem({ | |
'text/html': new Blob([html], {type: 'text/html'}), | |
'text/plain': new Blob([text], {type: 'text/plain'}), | |
}), | |
]); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment