Silkonomy

Redirect milkonomy URL

Voor het installeren van scripts heb je een extensie nodig, zoals Tampermonkey, Greasemonkey of Violentmonkey.

Voor het installeren van scripts heb je een extensie nodig, zoals {tampermonkey_link:Tampermonkey}.

Voor het installeren van scripts heb je een extensie nodig, zoals Tampermonkey of Violentmonkey.

Voor het installeren van scripts heb je een extensie nodig, zoals Tampermonkey of Userscripts.

Voor het installeren van scripts heb je een extensie nodig, zoals {tampermonkey_link:Tampermonkey}.

Voor het installeren van scripts heb je een gebruikersscriptbeheerder nodig.

(Ik heb al een user script manager, laat me het downloaden!)

Voor het installeren van gebruikersstijlen heb je een extensie nodig, zoals {stylus_link:Stylus}.

Voor het installeren van gebruikersstijlen heb je een extensie nodig, zoals {stylus_link:Stylus}.

Voor het installeren van gebruikersstijlen heb je een extensie nodig, zoals {stylus_link:Stylus}.

Voor het installeren van gebruikersstijlen heb je een gebruikersstijlbeheerder nodig.

Voor het installeren van gebruikersstijlen heb je een gebruikersstijlbeheerder nodig.

Voor het installeren van gebruikersstijlen heb je een gebruikersstijlbeheerder nodig.

(Ik heb al een beheerder - laat me doorgaan met de installatie!)

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