MS Store Helper

将微软商店的应用链接粘贴到store.rg-adguard.net,并自动解析下载地址。Paste the Microsoft Store app link into store.rg-adguard.net to automatically resolve the download URL.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         MS Store Helper
// @namespace    http://tampermonkey.net/
// @description  将微软商店的应用链接粘贴到store.rg-adguard.net,并自动解析下载地址。Paste the Microsoft Store app link into store.rg-adguard.net to automatically resolve the download URL.
// @license      MIT
// @version     1.0
// @match       https://apps.microsoft.com/*
// @match       https://store.rg-adguard.net/*
// @grant        GM_setValue
// @grant        GM_getValue
// @grant        GM_deleteValue
// ==/UserScript==

(function () {
    'use strict';

    // =========================
    // 1️⃣ Microsoft Store 页面
    // =========================
    if (location.host.includes("apps.microsoft.com")) {
        function getProductId() {
            // 从路径中提取 /detail/ 后面的部分,例如 /detail/9NBLGGH4NNS1?hl=...
            const match = location.pathname.match(/\/detail\/([^/?]+)/);
            return match ? match[1] : null;
        }

        function addBtn() {
            var btn = document.createElement("button");
            btn.innerText = "获取 MSIX 下载地址";
            btn.style.cssText = `
                position: fixed; top: 100px; right: 20px; z-index: 9999;
                padding: 10px 15px; background: #0078d7; color: white;
                border: none; border-radius: 6px; cursor: pointer;
                font-size: 14px; box-shadow: 0 2px 5px rgba(0,0,0,0.2);
            `;

            btn.onclick = () => {
                var pid = getProductId();
                if (!pid) {
                    alert("未找到 ProductId");
                    return;
                }

                GM_setValue("rg_pid", pid);
                window.open("https://store.rg-adguard.net/", "_blank");
            };
            document.body.appendChild(btn);
        }
        window.addEventListener("load", addBtn);
    }

    // =========================
    // 2️⃣ RG-Adguard 页面
    // =========================
    if (location.host.includes("store.rg-adguard.net")) {
        function autoSubmit() {
            var pid = GM_getValue("rg_pid", null);
            if (!pid) return;

            var timer = setInterval(() => {
                var type = document.querySelector("#type");
                var url = document.querySelector("#url");
                var ring = document.querySelector("#ring");
                var btn = document.querySelector("input[type=button]");

                if (type && url && ring && btn) {
                    clearInterval(timer);

                    url.value = "https://www.microsoft.com/store/productId/" + pid;
                    type.value = "url";
                    ring.value = "Retail";

                    GM_deleteValue("rg_pid");

                    // 🔥 自动点击生成
                    btn.click();
                }

            }, 300);
        }
        window.addEventListener("load", autoSubmit);
    }
})();