复制 GitHub 仓库名

在 GitHub 页面上添加一个按钮,点击后可以复制仓库名(owner/repo)

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

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

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Copy GitHub Repo Name
// @name:en      Copy GitHub Repo Name
// @name:zh-CN   复制 GitHub 仓库名
// @name:zh-TW   複製 GitHub 倉庫名
// @name:zh      複製 GitHub 倉庫名
// @namespace    http://tampermonkey.net/
// @version      2025-12-02
// @description  Create a button to copy the repo name (owner/repo) on GitHub
// @description:en  Create a button to copy the repo name (owner/repo) on GitHub
// @description:zh-CN  在 GitHub 页面上添加一个按钮,点击后可以复制仓库名(owner/repo)
// @description:zh-TW  在 GitHub 頁面上添加一個按鈕,點擊後可以複製倉庫名(owner/repo)
// @description:zh  在 GitHub 頁面上添加一個按鈕,點擊後可以複製倉庫名(owner/repo)
// @author       Elvis Mao
// @match        https://github.com/*
// @icon         https://emtech.cc/icons/apple-touch-icon.png
// @grant        none
// @license           Apache-2.0
// @homepageURL       https://github.com/Edit-Mr/SSS/tree/main
// @supportURL        https://github.com/Edit-Mr/SSS/issues
// ==/UserScript==

(function () {
    "use strict";

    let button = document.createElement("button");
    button.style.cssText =
        "margin:0; padding: 0; font-size: 1em; border:0; outline:0;background:transparent;";
    button.textContent = "🔗";
    button.addEventListener("click", function () {
        try {
            button.textContent = "✅";
            navigator.clipboard.writeText(
                location.pathname.split("/").slice(1, 3).join("/")
            );
            setTimeout(() => {
                button.textContent = "🔗";
            }, 1000);
        } catch (e) {
            button.textContent = "❌";
            console.error("Failed to copy repo name");
        }
    });
    document.querySelector("#repo-title-component strong").style = "display: inline!important"
    document.querySelector("#repo-title-component strong").appendChild(button);
})();