78 lines
3.1 KiB
JavaScript
78 lines
3.1 KiB
JavaScript
// ==UserScript==
|
|
// @name Grepolis Remote Loader
|
|
// @namespace http://tampermonkey.net/
|
|
// @version 4.0.1
|
|
// @description Dynamically loads the Grepolis Remote Control bot from the server
|
|
// @author Dimitrios
|
|
// @match https://*.grepolis.com/game/*
|
|
// @grant unsafeWindow
|
|
// @grant GM_xmlhttpRequest
|
|
// @connect grepo.haunter-pets.top
|
|
// @updateURL https://git.haunter-pets.top/haunter/grepo-remote/raw/branch/main/GrepoRemoteLoader.user.js
|
|
// @downloadURL https://git.haunter-pets.top/haunter/grepo-remote/raw/branch/main/GrepoRemoteLoader.user.js
|
|
// ==/UserScript==
|
|
|
|
(function() {
|
|
'use strict';
|
|
|
|
const BASE_URL = 'https://grepo.haunter-pets.top';
|
|
const MAX_TRIES = 3;
|
|
const RETRY_BASE = 3000; // 3 s, then 6 s
|
|
|
|
// ----------------------------------------------------------------
|
|
// CLAN_KEY: Set this to your clan's unique key.
|
|
// Leave it empty ('') and the bot will refuse to run.
|
|
// ----------------------------------------------------------------
|
|
const CLAN_KEY = ''; // <-- paste your clan key here
|
|
|
|
if (!CLAN_KEY || CLAN_KEY.trim() === '') {
|
|
console.error('[Loader] ❌ CLAN_KEY is not set. Bot will not start. Contact your admin for the key.');
|
|
return; // stop everything
|
|
}
|
|
|
|
function loadBot(attempt) {
|
|
attempt = attempt || 1;
|
|
console.log(`[Loader] Fetching bot code (attempt ${attempt}/${MAX_TRIES})...`);
|
|
|
|
GM_xmlhttpRequest({
|
|
method: 'GET',
|
|
url: `${BASE_URL}/api/bot?t=${Date.now()}`,
|
|
headers: {
|
|
'X-Clan-Key': CLAN_KEY
|
|
},
|
|
onload: function(response) {
|
|
if (response.status === 200) {
|
|
console.log('[Loader] Bot code downloaded. Executing...');
|
|
try {
|
|
window.__GRC_CLAN_KEY = CLAN_KEY; // make key available inside the bot's scope
|
|
eval(response.responseText);
|
|
} catch (e) {
|
|
console.error('[Loader] Execution error:', e);
|
|
}
|
|
} else if (attempt < MAX_TRIES) {
|
|
const delay = RETRY_BASE * attempt;
|
|
console.warn(`[Loader] Server returned ${response.status}. Retrying in ${delay / 1000}s...`);
|
|
setTimeout(() => loadBot(attempt + 1), delay);
|
|
} else {
|
|
console.error(`[Loader] Failed after ${MAX_TRIES} attempts (status ${response.status}). Give up.`);
|
|
}
|
|
},
|
|
onerror: function() {
|
|
if (attempt < MAX_TRIES) {
|
|
const delay = RETRY_BASE * attempt;
|
|
console.warn(`[Loader] Connection error. Retrying in ${delay / 1000}s...`);
|
|
setTimeout(() => loadBot(attempt + 1), delay);
|
|
} else {
|
|
console.error(`[Loader] Failed after ${MAX_TRIES} attempts. Check your server.`);
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
if (document.readyState === 'loading') {
|
|
document.addEventListener('DOMContentLoaded', () => loadBot(1));
|
|
} else {
|
|
loadBot(1);
|
|
}
|
|
})();
|