GitHub Clone Prefix

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

// ==UserScript==
// @name         GitHub Clone Prefix
// @name:zh-CN   Github上的clone前面加命令
// @name:en      GitHub Clone Prefix
// @namespace    http://tampermonkey.net/
// @version      2.0
// @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
// @description Add "git clone " before the clone URL on GitHub repository pages, making it ready for direct copying and use.
// ==/UserScript==

(function() {
    function modifyInputAndButton() {
        let inputElem = document.querySelector("#clone-with-https");
        let buttonElem = inputElem?.closest("div")?.querySelector("button");
        if (!inputElem || !buttonElem) return false;
        if (!inputElem.value.startsWith("git clone ")) inputElem.value = "git clone " + inputElem.value;
        buttonElem.addEventListener("click", async (e) => {
            e.stopImmediatePropagation();
            await navigator.clipboard.writeText(inputElem.value);
        }, true);
        return true;
    }
    if (!modifyInputAndButton()) {
        let observer = new MutationObserver(() => {
            if (modifyInputAndButton()) observer.disconnect();
        });
        observer.observe(document.body, { childList: true, subtree: true });
    }
})();