From aec99fa00dce2f5065c8568a20e5a9e5fb06d995 Mon Sep 17 00:00:00 2001 From: haunter Date: Wed, 22 Apr 2026 23:19:28 +0300 Subject: [PATCH] major update to client/faster --- GrepolisRemoteControl.user.js | 36 ++++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/GrepolisRemoteControl.user.js b/GrepolisRemoteControl.user.js index 10e6ebe..de541cf 100644 --- a/GrepolisRemoteControl.user.js +++ b/GrepolisRemoteControl.user.js @@ -1,7 +1,7 @@ // ==UserScript== // @name Grepolis Remote Control // @namespace http://tampermonkey.net/ -// @version 3.1 +// @version 3.2 // @description Polls grepo.haunter-pets.top for remote commands and executes them in-game (Multi-Player) // @author Dimitrios // @match https://*.grepolis.com/game/* @@ -294,6 +294,35 @@ } } + // ---------------------------------------------------------------- + // AJAX Interceptor for Zero-Delay Push + // ---------------------------------------------------------------- + let pushTimeout = null; + function debouncedPushState() { + if (paused) return; + if (pushTimeout) clearTimeout(pushTimeout); + pushTimeout = setTimeout(() => { + log('⚡ State change detected (AJAX). Syncing to Remote...'); + pushState(); + }, 1200); // Wait 1.2s for memory models to update after AJAX finishes + } + + if (uw.$) { + uw.$(document).ajaxComplete(function (e, xhr, opt) { + if (!opt || !opt.url) return; + + // Ignore requests to our own bot server or map data + if (opt.url.includes(BASE_URL)) return; + if (opt.url.includes('map_tiles')) return; + + // Most game actions use "action=" parameter + // Switching towns uses "switch_town" + if (opt.url.includes('action=') || opt.url.includes('switch_town')) { + debouncedPushState(); + } + }); + } + // ---------------------------------------------------------------- // Report command result back to relay // ---------------------------------------------------------------- @@ -527,9 +556,10 @@ // Start captcha watcher immediately detectCaptcha(); - // Push state once after load, then every 45–90 seconds (randomized) + // Push state once after load, then heartbeat every 1-2 minutes + // The AJAX interceptor handles the real-time syncing! setTimeout(pushState, 5000); - jitterLoop(pushState, 45000, 90000); + jitterLoop(pushState, 60000, 120000); // Poll for commands every 8–18 seconds (randomized jitter) jitterLoop(pollAndExecute, 8000, 18000);