Copy SSH URL Button for github.com

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

Versione datata 05/06/2024. Vedi la nuova versione l'ultima versione.

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

// ==UserScript==
// @name        Copy SSH URL Button for github.com
// @namespace   Violentmonkey Scripts
// @match       https://github.com/*/*
// @grant       none
// @version     1.0
// @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);
    `;

    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();