From 0f530dce2a703f7195c482b21c38d897d38a8d20 Mon Sep 17 00:00:00 2001 From: ZXMushroom63 Date: Sun, 16 Mar 2025 16:17:45 +0800 Subject: [PATCH] v2.7.3: add config meta entry --- injector.js | 2 +- modgui.js | 24 ++++++++++++++++++------ postinit.js | 16 ++++++++++++++++ 3 files changed, 35 insertions(+), 7 deletions(-) diff --git a/injector.js b/injector.js index f705d87..0852b16 100644 --- a/injector.js +++ b/injector.js @@ -1,4 +1,4 @@ -globalThis.ModAPIVersion = "v2.7.2"; +globalThis.ModAPIVersion = "v2.7.3"; globalThis.doEaglerforge = true; document.querySelector("title").innerText = `EaglerForge Injector ${ModAPIVersion}`; document.querySelector("h1").innerText = `EaglerForge Injector ${ModAPIVersion}`; diff --git a/modgui.js b/modgui.js index a0c0d7a..3bba2cc 100644 --- a/modgui.js +++ b/modgui.js @@ -248,15 +248,27 @@ globalThis.modapi_guikit = "(" + (() => { spacer.classList.add("nothing"); var controls = document.createElement("td"); - var button = document.createElement("button"); - button.innerText = "Delete"; - button.style.height = "3rem"; - button.addEventListener("click", async () => { + var deleteBtn = document.createElement("button"); + deleteBtn.innerText = "Delete"; + deleteBtn.style.height = "3rem"; + deleteBtn.addEventListener("click", async () => { await removeMod(i); window.modapi_displayModGui(); }); - button.classList.add("button"); - controls.appendChild(button); + deleteBtn.classList.add("button"); + controls.appendChild(deleteBtn); + + if (typeof ModAPI.meta._configMap[hash] === "function") { + var configBtn = document.createElement("button"); + configBtn.innerText = "Delete"; + configBtn.style.height = "3rem"; + configBtn.addEventListener("click", async () => { + ModAPI.meta._configMap[hash](); + }); + configBtn.classList.add("button"); + controls.appendChild(configBtn); + } + tr.appendChild(mod); tr.appendChild(spacer); tr.appendChild(controls); diff --git a/postinit.js b/postinit.js index 0ae13ec..f75e2df 100644 --- a/postinit.js +++ b/postinit.js @@ -22,6 +22,7 @@ globalThis.modapi_postinit = "(" + (() => { ModAPI.meta = {}; ModAPI.meta._titleMap = {}; ModAPI.meta._descriptionMap = {}; + ModAPI.meta._configMap = {}; ModAPI.meta._developerMap = {}; ModAPI.meta._iconMap = {}; ModAPI.meta._versionMap = {}; @@ -78,6 +79,9 @@ globalThis.modapi_postinit = "(" + (() => { " - Made the mod gui open before the client starts"); function limitSize(x, n) { + if (!x) { + return ""; + } if (x.length > n) { return x.substring(0, n) + "…"; } else { @@ -161,6 +165,18 @@ globalThis.modapi_postinit = "(" + (() => { } ModAPI.meta._descriptionMap[document.currentScript.getAttribute("data-hash")] = limitSize(desc, 160); } + ModAPI.meta.config = function (conf) { + if (typeof conf !== "function") { + return console.log("[ModAPIMeta] Config value was not a function"); + } + if (!document.currentScript || document.currentScript.getAttribute("data-isMod") !== "true") { + return console.log("[ModAPIMeta] Cannot set meta for non-mod script."); + } + if (!document.currentScript.hasAttribute("data-hash")) { + return console.log("[ModAPIMeta] Script does not have a hashcode."); + } + ModAPI.meta._configMap[document.currentScript.getAttribute("data-hash")] = conf; + } ModAPI.meta.version = function (ver) { if (!document.currentScript || document.currentScript.getAttribute("data-isMod") !== "true") { return console.log("[ModAPIMeta] Cannot set meta for non-mod script.");