GitHub Clone Prefix

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

Verze ze dne 02. 04. 2025. Zobrazit nejnovější verzi.

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

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

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

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

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

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.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

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