// ==UserScript== // @name Copy Jira Issue link as markdown // @version 1.0.2 // @description Adds a copy button alongside the "Copy link" button that copies the ticket link as a markdown to your clipboard. // @author relayism // @match https://*.atlassian.net/* // @grant none // @namespace https://greasyfork.org/users/452041 // @downloadURL https://update.greasyfork.icu/scripts/444553/Copy%20Jira%20Issue%20link%20as%20markdown.user.js // @updateURL https://update.greasyfork.icu/scripts/444553/Copy%20Jira%20Issue%20link%20as%20markdown.meta.js // ==/UserScript== // fork of "Copy Jira Issue ID" by Nathan Rijksen (function() { setInterval(() => { let rx = /\/browse\/([A-Z]+\-\d+)/; let links = document.querySelectorAll("nav[aria-label=\"Breadcrumbs\"] ol > div:last-child a[href]"); for (let link of links) { if (link.getAttribute("_seen") == "true") { continue; } link.setAttribute("_seen", "true"); let match = rx.exec(link.getAttribute("href")); if (!match) { continue; } let copyBtnDiv = document.createElement("div"); copyBtnDiv.style.cssText="padding-left: 10px; padding-top: 2px;" copyBtnDiv.innerHTML = '' copyBtnDiv.onclick = ((copyBtnDiv, id)=>{ copyBtnDiv.firstChild.style.backgroundColor = "lightgray"; setTimeout(()=>{copyBtnDiv.firstChild.style.backgroundColor = "";}, 2000) const issueTitle=document.querySelector('[data-test-id="issue.views.issue-base.foundation.summary.heading"]').innerText; const headerLinks = [...document.querySelectorAll("#jira-issue-header * [href]")] const lastHeaderLink = headerLinks[headerLinks.length -1]; navigator.clipboard.writeText(`[${issueTitle}](${lastHeaderLink})`); }).bind(null, copyBtnDiv, match[1]); let btwrap = link.parentElement.parentElement.querySelector(".issue_view_permalink_button_wrapper"); if (btwrap) { btwrap.appendChild(copyBtnDiv); } else { link.parentElement.appendChild(copyBtnDiv); } } }, 2000); })();