Silkonomy

Redirect milkonomy URL

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

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

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

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

이 스크립트를 설치하려면 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);
        });
    })();
})();