Open With VSCode

快速将 GitHub 项目下载到本地,并支持选择 VSCode 或 VSCode Insiders

当前为 2025-03-28 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Open With VSCode
// @name:en      Open With VSCode
// @version      1.1.1
// @description  快速将 GitHub 项目下载到本地,并支持选择 VSCode 或 VSCode Insiders
// @description:en  Quickly download GitHub project to local and choose VSCode or VSCode Insiders
// @author       hoorn
// @icon         https://code.visualstudio.com/favicon.ico
// @license      MIT
// @compatible   chrome Latest
// @compatible   firefox Latest
// @compatible   edge Latest
// @noframes
// @grant        window.onurlchange
// @match        https://github.com/*
// @namespace https://greasyfork.org/users/1276388
// ==/UserScript==

(() => {
    "use strict";

    const $ = document.querySelector.bind(document);

    function openWithVSCode() {
        const actions = $('.pagehead-actions');
        if (!actions || $('#openwithvscode-button')) return;

        const btnHTML = `
            <li>
                <div class="BtnGroup">
                    <a id="openwithvscode-button" class="btn btn-sm BtnGroup-item">Open with VSCode</a>
                    <a id="openwithvscodeinsiders-button" class="btn btn-sm BtnGroup-item">Open with VSCode Insiders</a>
                </div>
            </li>`;
        actions.insertAdjacentHTML('afterBegin', btnHTML);

        const projectUrl = window.location.href + ".git";

        document.getElementById('openwithvscode-button').addEventListener('click', function (e) {
            e.preventDefault();
            window.location.href = `vscode://vscode.git/clone?url=${projectUrl}`;
        });

        document.getElementById('openwithvscodeinsiders-button').addEventListener('click', function (e) {
            e.preventDefault();
            window.location.href = `vscode-insiders://vscode.git/clone?url=${projectUrl}`;
        });
    }

    openWithVSCode();
})();