Copy SSH URL Button for github.com

Adds a button to copy SSH clone URL on GitHub repositories when logged out.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला 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        Copy SSH URL Button for github.com
// @namespace   Violentmonkey Scripts
// @match       https://github.com/*/*
// @grant       none
// @version     1.1
// @author      Matthew Hugley
// @description Adds a button to copy SSH clone URL on GitHub repositories when logged out.
// @license     BSD 3-Clause
// ==/UserScript==

function addCopySSHButton() {
    const button = document.createElement("button");
    button.textContent = "Copy SSH URL";
    button.style.cssText = `
        position: absolute;
        left: 50%;
        top: 2%;
        transform: translateX(-50%);
        z-index: 1000;
        padding: 10px 20px;
        border: none;
        border-radius: 5px;
        background-color: #007bff;
        color: white;
        cursor: pointer;
        box-shadow: 0 2px 5px rgba(0,0,0,0.2);
        transition: filter 0.15s;
    `;

    button.onmouseover = function () {
        button.style.transform = "translateX(-50%) scale(0.97)";
    };

    button.onmouseout = function () {
        button.style.transform = "translateX(-50%)";
    };

    button.onclick = function () {
        const repoUrl = window.location.href;
        const sshUrl = repoUrl.replace("https://github.com/", "[email protected]:").replace(/\/$/, "") + ".git";
        navigator.clipboard.writeText(sshUrl).then(
            function () {
                alert("SSH URL copied to clipboard:\n" + sshUrl);
            },
            function (err) {
                console.error("Could not copy SSH URL:", err);
            }
        );
    };

    document.body.appendChild(button);
}

addCopySSHButton();