Skip to content

Instantly share code, notes, and snippets.

@Leksat
Last active May 23, 2023 09:44
Show Gist options
  • Save Leksat/c3e3eb67d82d2e51ea8d1955592182d3 to your computer and use it in GitHub Desktop.
Save Leksat/c3e3eb67d82d2e51ea8d1955592182d3 to your computer and use it in GitHub Desktop.
Copy bookmarklet for Jira
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