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와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Userscripts와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 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 });
    }
})();