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, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

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

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

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

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==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);
})();