GitHub Clone Prefix

Add "git clone " before the clone URL on GitHub repository pages, making it ready for direct copying and use.

目前為 2025-04-02 提交的版本,檢視 最新版本

// ==UserScript==
// @name         GitHub Clone Prefix
// @name:zh-CN   Github上的clone前面加命令
// @name:en      GitHub Clone Prefix
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description        Add "git clone " before the clone URL on GitHub repository pages, making it ready for direct copying and use.
// @description:zh-CN  在 GitHub 代码仓库页面的克隆地址前添加 "git clone ",复制即可用
// @description:en     Add "git clone " before the clone URL on GitHub repository pages, making it ready for direct copying and use.
// @author       Yog-Sothoth
// @match        https://github.com/*/*
// @grant        none
// @license      MIT
// @run-at       document-idle
// ==/UserScript==

(function() {
    'use strict';
    let xpath = "//html/body/div[1]/div[4]/div/main/turbo-frame/div/div/div/div/div[2]/div/div[2]/div/h2/a";
    let observer = new MutationObserver(() => {
        let repo = document.evaluate(xpath, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
        let input = document.evaluate("/html/body/div[4]/div/div/div/div/div/div[2]/input", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
        if (repo && input && !input.dataset.modified) {
            input.value = "git clone " + input.value;
            input.dataset.modified = "1";
        }
    });
    observer.observe(document.body, { childList: true, subtree: true });
})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址