Copy Jira Issue ID

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

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Copy Jira Issue ID
// @namespace    naatan.copy.jira.id
// @version      1.1.0
// @description  Adds a copy button alongside the "Copy link" button that copies the ticket ID to your clipboard.
// @author       Nathan Rijksen
// @match        https://*.atlassian.net/*
// @grant        none
// ==/UserScript==

(function() {
    setInterval(() => {
        let rx = /\/browse\/([A-Z]+\-\d+)/;
        let crumbs = document.querySelectorAll("nav[aria-label=\"Issue breadcrumbs\"] ol > div:last-child");
        for (let crumb of crumbs) {
          if (crumb.getAttribute("_seen") == "true") {
            continue;
          }
          crumb.setAttribute("_seen", "true");

          let link = crumb.querySelector("a[href]");

          let match = rx.exec(link.getAttribute("href"));
          if (!match) {
            continue;
          }

          let copyBtnDiv = document.createElement("div");
          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>'
          copyBtnDiv.onclick = ((copyBtnDiv, id)=>{
              copyBtnDiv.firstChild.style.backgroundColor = "lightgray";
              setTimeout(()=>{copyBtnDiv.firstChild.style.backgroundColor = "";}, 2000)
              navigator.clipboard.writeText(id);
          }).bind(null, copyBtnDiv, match[1]);

          let btwrap = crumb.querySelector(".issue_view_permalink_button_wrapper");
          if (btwrap) {
            btwrap.appendChild(copyBtnDiv);
          } else {
            crumb.appendChild(copyBtnDiv);
          }
        }
    }, 2000);
})();