const modapi_guikit = "(" + (() => {
// ModAPI GUI made by TheIdiotPlays
// https://github.com/TheIdiotPlays
var splashes = [
"Now with A.I.D.S (automatically injected dedicated server)",
"Only causes death 90% of the time!",
"HTML is better.",
"https://github.com/EaglerForge",
"hey you should check out https://github.com/ZXMushroom63/scratch-gui",
"99% of people stop gambling before they win big.",
"Now with free estradiol!",
"Now with H.I.V (Hyper Injected Virtual-debugger)",
"asdasd",
"Star us on GitHub to support us! https://github.com/EaglerForge/EaglerForgeInjector"
];
var gui = `
EaglerForge Mod Manager
{splash_msg}
Warning: installing malicious mods can delete your worlds, ip-grab you, or even download more serious malware onto your computer. The EaglerForge developers are not liable for any damage caused by the use of EaglerForge and its related tools.
Mod
Controls
(reload to apply changes)
`;
async function fileToText(file) {
return new Promise((res, rej) => {
var fr = new FileReader();
fr.addEventListener("error", (e) => { rej(e); });
fr.addEventListener("load", (e) => { res(fr.result); });
fr.readAsText(file);
});
}
window.modapi_displayModGui = async function (cb) {
if (!getMods) {
return;
}
if (document.querySelector("#modapi_gui_container")) {
cb ||= document.querySelector("#modapi_gui_container")._cb;
document.querySelector("#modapi_gui_container").remove();
}
var element = document.createElement("div");
element.innerHTML = gui.replace("{splash_msg}", splashes[Math.floor(Math.random() * splashes.length)]);
document.body.appendChild(element);
document.querySelector("#modapi_gui_container")._cb = cb;
var modsList = await getMods();
var tbody = document.querySelector("#modapi_gui_container #modapi_gui_modTable tbody");
tbody.innerHTML = "";
modsList.forEach((modtxt, i) => {
if (!modtxt) { return }
var hash = ModAPI.util.hashCode(modtxt);
var tr = document.createElement("tr");
var mod = document.createElement("td");
if (ModAPI.meta._titleMap[hash]) {
//Mod has metadata
if (ModAPI.meta._iconMap[hash]) {
var img = document.createElement("img");
img.style.width = "48px";
img.style.height = "48px";
img.style.imageRendering = "pixelated";
img.src = ModAPI.meta._iconMap[hash];
mod.appendChild(img);
}
var h4 = document.createElement("h4");
h4.style.margin = 0;
h4.style.padding = 0;
h4.innerText = ModAPI.meta._titleMap[hash] + (ModAPI.meta._versionMap[hash] ? " " + ModAPI.meta._versionMap[hash] : "");
mod.appendChild(h4);
if (ModAPI.meta._developerMap[hash]) {
var h6 = document.createElement("h6");
h6.style.margin = 0;
h6.style.padding = 0;
h6.innerText = ModAPI.meta._developerMap[hash];
mod.appendChild(h6);
}
if (ModAPI.meta._descriptionMap[hash]) {
var span = document.createElement("span");
span.style.fontSize = "0.65rem";
span.innerText = ModAPI.meta._descriptionMap[hash];
mod.appendChild(span);
}
} else {
//Mod does not have metadata
if (modtxt.length > 125) {
try {
mod.innerText = modtxt.match(/data:text\/\S+?;fs=\S+;/m)[0]
} catch (error) {
mod.innerText = "Unknown Mod.";
}
} else { mod.innerText = modtxt; }
}
var spacer = document.createElement("td");
spacer.classList.add("nothing");
var controls = document.createElement("td");
var deleteBtn = document.createElement("button");
deleteBtn.innerText = "Delete";
deleteBtn.style.height = "3rem";
deleteBtn.addEventListener("click", async () => {
await removeMod(i);
window.modapi_displayModGui();
});
deleteBtn.classList.add("button");
controls.appendChild(deleteBtn);
if (typeof ModAPI.meta._configMap[hash] === "function") {
var configBtn = document.createElement("button");
configBtn.innerText = "Config";
configBtn.style.height = "3rem";
configBtn.style.marginLeft = "1rem";
configBtn.addEventListener("click", async () => {
ModAPI.meta._configMap[hash]();
});
configBtn.classList.add("button");
controls.appendChild(configBtn);
}
tr.appendChild(mod);
tr.appendChild(spacer);
tr.appendChild(controls);
tbody.appendChild(tr);
});
var once = false;
if (cb) {
document.querySelector("#modapi_gui_container ._doneButton").addEventListener("mousedown", ()=>{
if (once) {
return;
}
once = true;
cb();
document.querySelector("#modapi_gui_container").remove();
})
}
}
window.modapi_clearmods = async () => {
await resetMods();
window.modapi_displayModGui();
}
window.modapi_addmod = async () => {
var mod = window.prompt("Paste in the URL of the mod you wish to add: ");
if (!mod || mod.length === 0) {
return;
}
await addMod(mod);
window.modapi_displayModGui();
}
window.modapi_uploadmod = async () => {
var f = document.createElement("input");
f.type = "file";
f.accept = "text/javascript";
f.multiple = true;
f.addEventListener("input", async () => {
if (f.files.length < 1) {
return;
}
for (let i = 0; i < f.files.length; i++) {
await addFileMod(f.files[i].name, (await fileToText(f.files[i])));
}
window.modapi_displayModGui();
});
f.click();
}
}).toString() + ")();";
if (globalThis.process) {
module.exports = {
modapi_guikit: modapi_guikit
}
}