Copy Jira Issue ID

Adds a copy button alongside the "Copy link" button that copies the ticket ID to your clipboard.

  1. // ==UserScript==
  2. // @name Copy Jira Issue ID
  3. // @namespace naatan.copy.jira.id
  4. // @version 1.1.0
  5. // @description Adds a copy button alongside the "Copy link" button that copies the ticket ID to your clipboard.
  6. // @author Nathan Rijksen
  7. // @match https://*.atlassian.net/*
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. (function() {
  12. setInterval(() => {
  13. let rx = /\/browse\/([A-Z]+\-\d+)/;
  14. let crumbs = document.querySelectorAll("nav[aria-label=\"Issue breadcrumbs\"] ol > div:last-child");
  15. for (let crumb of crumbs) {
  16. if (crumb.getAttribute("_seen") == "true") {
  17. continue;
  18. }
  19. crumb.setAttribute("_seen", "true");
  20.  
  21. let link = crumb.querySelector("a[href]");
  22.  
  23. let match = rx.exec(link.getAttribute("href"));
  24. if (!match) {
  25. continue;
  26. }
  27.  
  28. let copyBtnDiv = document.createElement("div");
  29. copyBtnDiv.innerHTML = '<button class="css-zs8b2e" type="button" tabindex="0"><span class="css-113mohm"><span role="img" aria-label="Copy link to issue" class="css-hakgx8" style="--icon-primary-color:green; --icon-secondary-color:var(--background-default, #FFFFFF);"><svg width="24" height="24" viewBox="0 0 24 24" role="presentation"><g fill="currentColor" fill-rule="evenodd"><path d="M12.856 5.457l-.937.92a1.002 1.002 0 000 1.437 1.047 1.047 0 001.463 0l.984-.966c.967-.95 2.542-1.135 3.602-.288a2.54 2.54 0 01.203 3.81l-2.903 2.852a2.646 2.646 0 01-3.696 0l-1.11-1.09L9 13.57l1.108 1.089c1.822 1.788 4.802 1.788 6.622 0l2.905-2.852a4.558 4.558 0 00-.357-6.82c-1.893-1.517-4.695-1.226-6.422.47"></path><path d="M11.144 19.543l.937-.92a1.002 1.002 0 000-1.437 1.047 1.047 0 00-1.462 0l-.985.966c-.967.95-2.542 1.135-3.602.288a2.54 2.54 0 01-.203-3.81l2.903-2.852a2.646 2.646 0 013.696 0l1.11 1.09L15 11.43l-1.108-1.089c-1.822-1.788-4.802-1.788-6.622 0l-2.905 2.852a4.558 4.558 0 00.357 6.82c1.893 1.517 4.695 1.226 6.422-.47"></path></g></svg></span></span></button>'
  30. copyBtnDiv.onclick = ((copyBtnDiv, id)=>{
  31. copyBtnDiv.firstChild.style.backgroundColor = "lightgray";
  32. setTimeout(()=>{copyBtnDiv.firstChild.style.backgroundColor = "";}, 2000)
  33. navigator.clipboard.writeText(id);
  34. }).bind(null, copyBtnDiv, match[1]);
  35.  
  36. let btwrap = crumb.querySelector(".issue_view_permalink_button_wrapper");
  37. if (btwrap) {
  38. btwrap.appendChild(copyBtnDiv);
  39. } else {
  40. crumb.appendChild(copyBtnDiv);
  41. }
  42. }
  43. }, 2000);
  44. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址