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.

スクリプトをインストールするには、Tampermonkey, GreasemonkeyViolentmonkey のような拡張機能のインストールが必要です。

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

スクリプトをインストールするには、TampermonkeyViolentmonkey のような拡張機能のインストールが必要です。

スクリプトをインストールするには、TampermonkeyUserscripts のような拡張機能のインストールが必要です。

このスクリプトをインストールするには、Tampermonkeyなどの拡張機能をインストールする必要があります。

このスクリプトをインストールするには、ユーザースクリプト管理ツールの拡張機能をインストールする必要があります。

(ユーザースクリプト管理ツールは設定済みなのでインストール!)

このスタイルをインストールするには、Stylusなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus などの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus tなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

(ユーザースタイル管理ツールは設定済みなのでインストール!)

このスクリプトの質問や評価の投稿はこちら通報はこちらへお寄せください
// ==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);
})();