Open with VSCode

Support Open Remote Repo in GitHub Code menu!

目前為 2021-07-24 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Open with VSCode
// @namespace    http://tampermonkey.net/
// @version      1.2.0
// @description  Support Open Remote Repo in GitHub Code menu!
// @author       Sanonz <[email protected]>
// @match        https://github.com/*/*
// @icon         https://github.githubassets.com/pinned-octocat.svg
// @homepage     https://sanonz.github.io
// @supportURL   https://github.com/sanonz
// @grant        none
// @run-at       document-idle
// ==/UserScript==

(function() {
    'use strict';

    function render() {
        var ul = document.querySelector('[data-target="get-repo.modal"] > ul');

        var li = document.createElement('li');
        li.className = 'Box-row Box-row--hover-gray p-0 rounded-0';

        var a = document.createElement('a');
        a.className = 'd-flex flex-items-center color-text-primary text-bold no-underline p-3';
        a.rel = 'nofollow';
        a.href = `vscode://github.remotehub/open?url=${encodeURIComponent(location.href)}`;

        var svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
        svg.setAttribute('width', 16);
        svg.setAttribute('height', 15);
        svg.setAttribute('viewBox', '0 0 1024 1024');
        svg.setAttribute('version', '1.1');
        svg.setAttribute('class', 'octicon mr-3');
        svg.setAttribute('aria-hidden', 'true');

        var path = document.createElementNS(svg.namespaceURI, 'path');
        path.setAttribute('d', 'M746.222933 102.239573l-359.799466 330.820267L185.347413 281.4976 102.2464 329.864533l198.20544 182.132054-198.20544 182.132053 83.101013 48.510293 201.076054-151.558826 359.799466 330.676906 175.527254-85.251413V187.4944z m0 217.57952v384.341334l-255.040853-192.177494z');

        var text = document.createTextNode('Open with VSCode');

        svg.appendChild(path);
        a.appendChild(svg);
        a.appendChild(text);
        li.appendChild(a);
        ul.insertBefore(li, ul.children[0]);
    }

    window.addEventListener('pjax:complete', function(evt) {
        const pathnames = location.pathname.substr(1).split('/');
        if (pathnames.length === 2) {
            render();
        }
    });

    render();
})();