Clone in VSCode

Clone Github respository in VSCode

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

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.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         Clone in VSCode
// @namespace    https://github.com/spacemeowx2
// @version      0.2
// @description  Clone Github respository in VSCode
// @author       space
// @match        https://github.com/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    function createButton(actions, uri) {
        const li = document.createElement('li');
        const button = document.createElement('button');
        button.className = 'btn btn-sm'; // js-toggler-target
        button.innerText = 'Clone in VSCode';
        button.addEventListener('click', () => {
            location.href = `vscode://vscode.git/clone?url=${encodeURIComponent(uri)}`
        })
        li.append(button);
        actions.append(li);
    }
    function getGitUri() {
        const [emptyUri] = [...document.querySelectorAll('button.js-git-protocol-clone-url')].map(i => i.getAttribute('data-url')).filter(i => i.startsWith('git'))
        const [normalUri] = [...document.querySelectorAll('input[data-autoselect]')].map(i => i.value).filter(i => i.startsWith('git'))
        return emptyUri || normalUri
    }
    const actions = document.querySelector('.pagehead-actions')
    if (actions) {
        const uri = getGitUri();
        if (uri) {
            createButton(actions, uri);
        }
    }
})();