// ==UserScript== // @name Grepolis Data Sender (Deep Scan Edition) // @namespace http://tampermonkey.net/ // @version 3.1 // @description Full diagnostics + HTTPS endpoint for secure data transmission // @author Dimitrios // @match https://*.grepolis.com/game/* // @grant unsafeWindow // ==/UserScript== (function () { 'use strict'; console.log("🔍 [DeepScan] Initializing Grepolis data sender..."); const uw = typeof unsafeWindow !== "undefined" ? (console.log("✅ [DeepScan] unsafeWindow available"), unsafeWindow) : typeof wrappedJSObject !== "undefined" ? (console.log("✅ [DeepScan] wrappedJSObject fallback"), wrappedJSObject) : (console.log("⚠️ [DeepScan] Using default window"), window); function collectAndSendData() { try { console.log("🚀 [DeepScan] Collecting town data..."); const player = uw.Game?.player_name || "unknown"; const player_id = uw.Game?.player_id || "unknown"; const towns = uw.ITowns?.towns || {}; const townEntries = Object.values(towns); console.log(`📊 [DeepScan] Found ${townEntries.length} towns in ITowns.towns`); if (townEntries.length === 0) { console.warn("⚠️ [DeepScan] Town data structure is present but empty"); return; } const stats = townEntries.map(town => { try { const resources = town.resources(); const buildings = town.buildings()?.attributes ?? {}; return { town_id: town.id, town_name: town.name, wood: resources.wood, stone: resources.stone, iron: resources.iron, population: resources.population, points: town.getPoints(), buildings: buildings }; } catch (innerErr) { console.error("💥 [DeepScan] Error in town parsing:", innerErr); return null; } }).filter(Boolean); const payload = { player, player_id, timestamp: new Date().toISOString(), towns: stats }; console.log("📤 [DeepScan] Dispatching payload to grepo.haunter-pets.top:", payload); fetch("https://grepo.haunter-pets.top/api/grepolis-data", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(payload) }) .then(r => r.text()) .then(txt => console.log("✅ [DeepScan] Server response:", txt)) .catch(err => console.error("❌ [DeepScan] Data send failed:", err)); } catch (e) { console.error("💥 [DeepScan] Fatal error:", e); } } function waitUntilDataReady() { console.log("🕰️ [DeepScan] Checking if town data is ready..."); const townsObj = uw.ITowns?.towns; if (townsObj && Object.keys(townsObj).length > 0) { console.log("🎯 [DeepScan] Towns are ready — beginning dispatch"); collectAndSendData(); setInterval(collectAndSendData, 30000); } else { console.log("⏳ [DeepScan] Towns not ready yet — retrying in 1s"); setTimeout(waitUntilDataReady, 1000); } } window.addEventListener("load", () => { console.log("🌐 [DeepScan] Window loaded — monitoring town readiness"); waitUntilDataReady(); }); })();