From a90e637640c700f5d6aea790e5e7f5c82588352b Mon Sep 17 00:00:00 2001 From: haunter Date: Thu, 31 Jul 2025 13:29:10 +0000 Subject: [PATCH] Add Grepolis_Data_Sender.js --- Grepolis_Data_Sender.js | 97 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 Grepolis_Data_Sender.js diff --git a/Grepolis_Data_Sender.js b/Grepolis_Data_Sender.js new file mode 100644 index 0000000..71731fd --- /dev/null +++ b/Grepolis_Data_Sender.js @@ -0,0 +1,97 @@ +// ==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(); + }); +})();