Elethor Tools Data Bridge

Fetches Elethor game data for TomatoShadow's Elethor Tools

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

// ==UserScript==
// @name         Elethor Tools Data Bridge
// @namespace    http://tampermonkey.net/
// @version      0.4
// @description  Fetches Elethor game data for TomatoShadow's Elethor Tools
// @match        http://localhost:5173/*
// @match        https://elethor.tomato.ninja/*
// @grant        GM_xmlhttpRequest
// @grant        GM_cookie
// @connect      elethor.com
// ==/UserScript==

(function() {
    'use strict';

    console.log('Elethor Tools Data Bridge loaded');

    window.addEventListener('message', function(event) {
        if (event.data && event.data.type === 'ELETHOR_SYNC_REQUEST') {
            console.log('Received sync request');

            const endpoints = {
                renown: 'https://elethor.com/game/renown',
                buffs: 'https://elethor.com/game/buffs',
                companions: 'https://elethor.com/game/companions',
                gearset: 'https://elethor.com/game/gearset',
                user: 'https://elethor.com/game/user',
                spire0: 'https://elethor.com/game/neo-spire/0',
                spire1000: 'https://elethor.com/game/neo-spire/1000',
                modifiers: 'https://elethor.com/game/neo-spire/modifiers',
                spireView: 'https://elethor.com/game/views/neo-spire',
                marketVoids: 'https://elethor.com/game/market/listings?itemId=385',
                marketPlat: 'https://elethor.com/game/market/listings?itemId=180',
                marketOmnium: 'https://elethor.com/game/market/listings?itemId=297',
                // Mining endpoints
                lasers: 'https://elethor.com/game/laser',
                gather: 'https://elethor.com/game/views/gather',
                gatherStats: 'https://elethor.com/game/gather/stats',
                skillTree: 'https://elethor.com/game/skill/tree',
            };

            const results = {};
            let count = 0;
            const total = Object.keys(endpoints).length;

            Object.entries(endpoints).forEach(([key, url]) => {
                GM_xmlhttpRequest({
                    method: 'GET',
                    url: url,
                    headers: {
                        'Accept': 'application/json',
                        'Content-Type': 'application/json',
                        'X-Requested-With': 'XMLHttpRequest'
                    },
                    onload: function(response) {
                        if (response.status === 200) {
                            try {
                                const data = response.responseText ? JSON.parse(response.responseText) : null;
                                results[key] = data;
                            } catch (e) {
                                console.error(`Failed to parse JSON for ${key}:`, e);
                                results[key] = { error: 'Failed to parse JSON' };
                            }
                        } else {
                            console.error(`HTTP error for ${key}:`, response.status, response.statusText);
                            results[key] = { error: `HTTP ${response.status}: ${response.statusText}` };
                        }

                        count++;
                        if (count === total) {
                            console.log('Elethor data sync completed');
                            window.postMessage({ type: 'ELETHOR_SYNC_RESPONSE', payload: results }, '*');
                        }
                    },
                    onerror: function(error) {
                        console.error(`Network error for ${key}:`, error);
                        results[key] = { error: 'Network error' };
                        count++;
                        if (count === total) {
                            console.log('Elethor data sync completed (with errors)');
                            window.postMessage({ type: 'ELETHOR_SYNC_RESPONSE', payload: results }, '*');
                        }
                    },
                    ontimeout: function() {
                        console.error(`Timeout for ${key}`);
                        results[key] = { error: 'Request timeout' };
                        count++;
                        if (count === total) {
                            console.log('Elethor data sync completed (with timeouts)');
                            window.postMessage({ type: 'ELETHOR_SYNC_RESPONSE', payload: results }, '*');
                        }
                    },
                    timeout: 10000 // 10 second timeout
                });
            });
        }
    }, false);

    // Test if userscript is working
    window.postMessage({ type: 'ELETHOR_USERSCRIPT_READY' }, '*');
})();