github-copy-title-link

Copy the title and URL of the Pull request and Issue pages. Then, you can paste them directly into Google Docs.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         github-copy-title-link
// @namespace    https://github.com
// @version      0.0.2
// @description  Copy the title and URL of the Pull request and Issue pages. Then, you can paste them directly into Google Docs.
// @include      /^https://github.com/.*/
// @author       proshunsuke
// @license      MIT
// @grant        none
// ==/UserScript==
(() => {
  // pnp:/home/pro_shunsuke/Documents/github-copy-title-link/src/feedback.ts
  var duration = 2e3;
  var feedback = (copyElement2) => {
    const message = copyElement2.getAttribute("data-copy-feedback");
    if (!message)
      return;
    const originalLabel = copyElement2.getAttribute("aria-label");
    const direction = copyElement2.getAttribute("data-tooltip-direction") || "s";
    copyElement2.setAttribute("aria-label", message);
    copyElement2.classList.add("tooltipped", `tooltipped-${direction}`);
    if (!(copyElement2 instanceof HTMLElement))
      return;
    setTimeout(() => {
      if (originalLabel) {
        copyElement2.setAttribute("aria-label", originalLabel);
      } else {
        copyElement2.removeAttribute("aria-label");
      }
      copyElement2.classList.remove("tooltipped", `tooltipped-${direction}`);
    }, duration);
  };

  // pnp:/home/pro_shunsuke/Documents/github-copy-title-link/src/copy.ts
  var createNode = (copyElement2, title, url) => {
    const node = document.createElement("a");
    node.href = url;
    node.style.textDecoration = "underline";
    node.style.color = "#1155cc";
    node.style.fontSize = "14.63px";
    node.appendChild(document.createTextNode(title));
    return node;
  };
  var copyTitleLink = (copyElement2) => {
    const body = document.body;
    if (!body)
      return Promise.reject(new Error());
    const titleElement = document.querySelector(".js-issue-title");
    if (!titleElement)
      return Promise.reject(new Error());
    const title = titleElement.innerText.trim();
    const url = location.href.replace(/\/pull\/(\d*).*/g, "/pull/$1");
    const node = createNode(copyElement2, title, url);
    body.appendChild(node);
    const range = document.createRange();
    range.selectNodeContents(node);
    const selection = window.getSelection();
    if (!selection)
      return Promise.reject(new Error());
    selection.removeAllRanges();
    selection.addRange(range);
    document.execCommand("copy");
    node.remove();
    return Promise.resolve();
  };
  var copy = (event) => {
    const copyElement2 = event.currentTarget;
    if (!(copyElement2 instanceof HTMLDivElement))
      return;
    copyTitleLink(copyElement2).then(() => feedback(copyElement2)).catch(() => {
    });
  };

  // pnp:/home/pro_shunsuke/Documents/github-copy-title-link/src/index.ts
  var createCopyTitleLinkElement = () => {
    const copyElement2 = document.createElement("div");
    copyElement2.setAttribute("data-copy-feedback", "Copied!");
    copyElement2.setAttribute("tabindex", "0");
    copyElement2.setAttribute("role", "button");
    copyElement2.innerHTML = "Copy title link";
    return copyElement2;
  };
  var appendNodeToHeader = (copyElement2) => {
    const aTag = document.createElement("a");
    aTag.classList.add("js-selected-navigation-item", "Header-link", "mt-md-n3", "mb-md-n3", "py-2", "py-md-3", "mr-0", "mr-md-3", "border-top", "border-md-top-0", "border-white-fade");
    aTag.setAttribute("href", "#");
    aTag.appendChild(copyElement2);
    const ariaGlobalSel = document.querySelectorAll("[aria-label=Global]")[0];
    ariaGlobalSel.appendChild(aTag);
  };
  var copyElement = createCopyTitleLinkElement();
  appendNodeToHeader(copyElement);
  copyElement.addEventListener("click", copy);
})();