Silkonomy

Redirect milkonomy URL

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

You will need to install a user script manager extension to install this script.

(Tôi đã có Trình quản lý tập lệnh người dùng, hãy cài đặt nó!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==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);
        });
    })();
})();