// ==UserScript== // @name Gargonem - dodatki Priweejta // @namespace http://tampermonkey.net/ // @version 0.3 // @description Zestaw dodatków do nowego i starego interfejsu w grze Margonem // @author Priw8 // @match https://*.margonem.pl/ // @exclude https://www.margonem.pl/ // @icon https://www.google.com/s2/favicons?sz=64&domain=margonem.pl // @grant GM_setValue // @grant GM_getValue // @grant GM_deleteValue // @grant unsafeWindow // ==/UserScript== !function() { const window = unsafeWindow; const gargonemMainSrc = "https://priw8.com/margo/gargonem/dist/main.js"; /** @type {string[]} */ const scriptsToLoad = [gargonemMainSrc]; const gmPrivilegedScripts = [gargonemMainSrc]; const InterfaceKind = { NEW: 0, OLD: 1 }; /** @returns {number} */ function getInterfaceKind() { return typeof window.Engine == "undefined" ? InterfaceKind.OLD : InterfaceKind.NEW; } const interfaceKind = getInterfaceKind(); const cachedScriptMaxLifetime = 12 * 60 * 60; // 12 hours function getScriptVersion() { const lastUpdateCheck = Number(GM_getValue(`_loaderLastUpdateCheck`, "0")); const ts = Math.floor(new Date().getTime() / 1000); if (lastUpdateCheck + cachedScriptMaxLifetime < ts) { GM_setValue(`_loaderLastUpdateCheck`, ts.toString()); return ts; } else { return lastUpdateCheck; } } const scriptVersion = getScriptVersion(); /** @param src {string} */ function loadScript(src) { const $script = window.document.createElement("script"); if (gmPrivilegedScripts.includes(src)) { $script.GM_setValue = GM_setValue; $script.GM_getValue = GM_getValue; $script.GM_deleteValue = GM_deleteValue; $script.gargonem = true; $script.addScript = addScript; } $script.src = `${src}?v=${scriptVersion}`; return new Promise((resolve, reject) => { $script.addEventListener("load", resolve); $script.addEventListener("error", reject); window.document.head.appendChild($script); }); } /** @param src {string} */ function addScript(src) { scriptsToLoad.push(src); } let overwrittenFunction = null; let overwrittenFunctionThis = null; let overwrittenFunctionArgs = null; let wasOverwrittenFunctionCalled = false; function beginLoading() { // Block game loading until all scripts are loaded if (interfaceKind == InterfaceKind.OLD) { overwrittenFunction = window.startGame; window.startGame = function() { wasOverwrittenFunctionCalled = true; overwrittenFunctionThis = this; overwrittenFunctionArgs = arguments; } } else { overwrittenFunction = window.Engine.communication.startCallInitAfterRecivedAddons; window.Engine.communication.startCallInitAfterRecivedAddons = function() { wasOverwrittenFunctionCalled = true; overwrittenFunctionThis = this; overwrittenFunctionArgs = arguments; } } loadBatch(); } function endLoading() { if (interfaceKind == InterfaceKind.OLD) { ... (Pozostałe wiersze: 28)