Silkonomy

Redirect milkonomy URL

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Silkonomy
// @version      2.1
// @description  Redirect milkonomy URL
// @author       AlphB
// @match        https://milkonomy.pages.dev/*
// @match        https://milkonomy.cnnewnew.top/*
// @match        https://hyhfish.github.io/milkonomy/*
// @connect      www.milkywayidle.com
// @connect      test.milkywayidle.com
// @connect      www.milkywayidlecn.com
// @connect      test.milkywayidlecn.com
// @connect      alphb.cn
// @grant        GM.xmlHttpRequest
// @grant        GM_getValue
// @grant        GM_setValue
// @icon         https://tupian.li/images/2025/09/30/68dae3cf1fa7e.png
// @license      CC-BY-NC-SA-4.0
// @namespace    http://tampermonkey.net/
// @run-at       document-start
// ==/UserScript==

(function () {
    if (!GM_getValue('URL')) {
        GM_setValue('URL', prompt('输入新URL', 'https://www.milkywayidlecn.com/game_data/marketplace.json'));
        alert('设置完成,请手动刷新页面以生效!');
        return;
    }
    const targetUrl = GM_getValue('URL');
    const originalFetch = window.fetch;
    let lastData;

    window.fetch = function (...args) {
        let input = args[0];
        let options = args[1] || {};

        let requestUrl;
        if (typeof input === 'string') {
            requestUrl = input;
        } else if (input instanceof Request) {
            requestUrl = input.url;
        } else {
            return originalFetch.apply(this, arguments);
        }

        if (requestUrl !== 'https://www.milkywayidle.com/game_data/marketplace.json' && requestUrl !== 'https://www.milkywayidlecn.com/game_data/marketplace.json') {
            return originalFetch.apply(this, arguments);
        }

        console.log(`Redirecting request: ${requestUrl} -> ${targetUrl}`);

        return new Promise((resolve) => {
            const requestData = {
                method: options.method || 'GET',
                url: targetUrl,
                headers: options.headers || {},
                data: options.body,
                responseType: 'json',
                timeout: options.timeout || 0
            };

            requestData.onload = function (response) {
                delete localStorage["game-market-data"];
                const responseData = response.response;
                responseData.timestamp = new Date().getTime() / 1000;
                lastData = JSON.stringify(responseData);
                const fetchResponse = new Response(
                    response.responseText ? JSON.stringify(responseData) : null,
                    {
                        status: response.status,
                        statusText: response.statusText
                    }
                );
                resolve(fetchResponse);
            };

            GM.xmlHttpRequest(requestData);
        });
    };
    unsafeWindow.fetch = window.fetch;

    (function showButton() {
        const button1 = document.createElement('button');

        button1.textContent = '打印当前API内容';

        button1.style.position = 'fixed';
        button1.style.bottom = '20px';
        button1.style.right = '20px';
        button1.style.zIndex = '9999';

        button1.addEventListener('click', () => {
            alert('数据源:' + targetUrl);
            alert(lastData);
        });

        const button2 = document.createElement('button');

        button2.textContent = '重设URL';

        button2.style.position = 'fixed';
        button2.style.bottom = '40px';
        button2.style.right = '20px';
        button2.style.zIndex = '9999';

        button2.addEventListener('click', () => {
            GM_setValue('URL', prompt('输入新URL', 'https://www.milkywayidlecn.com/game_data/marketplace.json'));
            alert('设置完成,请手动刷新页面以生效!');
        });

        window.addEventListener('load', () => {
            document.body.appendChild(button1);
            document.body.appendChild(button2);
        });
    })();
})();