diff --git a/bot_modules/05_main.js b/bot_modules/05_main.js index a2d3206..d5af506 100644 --- a/bot_modules/05_main.js +++ b/bot_modules/05_main.js @@ -124,14 +124,22 @@ async function pollAndExecute() { } // ---------------------------------------------------------------- -// Boot +// Boot — works whether page is already loaded or not. +// When eval()'d dynamically the 'load' event has already fired, +// so we check readyState and boot immediately in that case. // ---------------------------------------------------------------- -window.addEventListener('load', () => { +function boot() { log('Grepolis Remote Control v4.0.0 (remote) loaded'); - detectCaptcha(); - setTimeout(pushState, 5000); jitterLoop(pushState, 60000, 120000); jitterLoop(pollAndExecute, 8000, 18000); -}); +} + +if (document.readyState === 'complete') { + // Page already loaded (normal case when eval()'d dynamically) + boot(); +} else { + // Fallback: wait for load event (shouldn't happen but safe to keep) + window.addEventListener('load', boot); +}