MS Store Helper

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

スクリプトをインストールするには、Tampermonkey, GreasemonkeyViolentmonkey のような拡張機能のインストールが必要です。

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

スクリプトをインストールするには、TampermonkeyViolentmonkey のような拡張機能のインストールが必要です。

スクリプトをインストールするには、TampermonkeyUserscripts のような拡張機能のインストールが必要です。

このスクリプトをインストールするには、Tampermonkeyなどの拡張機能をインストールする必要があります。

このスクリプトをインストールするには、ユーザースクリプト管理ツールの拡張機能をインストールする必要があります。

(ユーザースクリプト管理ツールは設定済みなのでインストール!)

このスタイルをインストールするには、Stylusなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus などの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus tなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

(ユーザースタイル管理ツールは設定済みなのでインストール!)

このスクリプトの質問や評価の投稿はこちら通報はこちらへお寄せください
// ==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);
    }
})();