VS Code Extension Downloader

在 VS Code Marketplace 页面添加直接下载按钮

이 스크립트를 설치하려면 Tampermonkey, Greasemonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

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

이 스크립트를 설치하려면 Tampermonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Userscripts와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 유저 스크립트 관리자 확장 프로그램이 필요합니다.

(이미 유저 스크립트 관리자가 설치되어 있습니다. 설치를 진행합니다!)

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

(이미 유저 스타일 관리자가 설치되어 있습니다. 설치를 진행합니다!)

// ==UserScript==
// @name         VS Code Extension Downloader
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  在 VS Code Marketplace 页面添加直接下载按钮
// @author       Trae AI
// @match        https://marketplace.visualstudio.com/items?itemName=*
// @grant        none
// @license MIT
// ==/UserScript==

(function() {
    'use strict';

    async function init() {
        // 获取 itemName 参数
        const urlParams = new URLSearchParams(window.location.search);
        const itemName = urlParams.get('itemName');
        if (!itemName) return;

        // 分割 publisher 和 extension 名称
        const [publisher, extension] = itemName.split('.');

        // 创建下载按钮
        const downloadButton = document.createElement('button');
        downloadButton.innerHTML = '下载最新版本';
        downloadButton.style.cssText = `
            background-color: #0078d4;
            color: white;
            border: none;
            padding: 8px 16px;
            border-radius: 4px;
            cursor: pointer;
            position: fixed;
            top: 20px;
            right: 20px;
            z-index: 10000;
        `;

        // 点击事件处理
        downloadButton.addEventListener('click', async () => {
            // 跳转到版本历史页面
            window.location.hash = 'version-history';

            // 等待版本历史表格加载
            await new Promise(resolve => setTimeout(resolve, 1000));

            // 获取最新版本号
            const versionCell = document.querySelector('.version-history-table-body .version-history-container-row:first-child .version-history-container-column:first-child');
            if (!versionCell) {
                alert('无法获取版本号');
                return;
            }

            const version = versionCell.textContent.trim();
            const downloadUrl = `https://marketplace.visualstudio.com/_apis/public/gallery/publishers/${publisher}/vsextensions/${extension}/${version}/vspackage`;

            // 创建下载
            const link = document.createElement('a');
            link.href = downloadUrl;
            link.download = `${itemName}-${version}.vsix`;
            document.body.appendChild(link);
            link.click();
            document.body.removeChild(link);
        });

        // 添加按钮到页面
        document.body.appendChild(downloadButton);
    }

    // 启动脚本
    init();
})();