From 9cb40f1d86b8371b2342a85c5c0d1fb1b1e6f352 Mon Sep 17 00:00:00 2001 From: Bluestonex64 Date: Thu, 12 Sep 2024 22:54:16 +0100 Subject: [PATCH] Fixed a bug with user defined variables --- script.js | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/script.js b/script.js index 6201fd5..ba964a0 100644 --- a/script.js +++ b/script.js @@ -175,14 +175,20 @@ let varc = (vari, lvls, cats, masterdiv) => { form.appendChild(document.createElement("br")) form.appendChild(inp) if (appvar["user-defined"]) { + if ((inp.nextElementSibling == null || inp.nextElementSibling.type != "text") && inp.value == 1) { + let definedvar = document.createElement("input") + definedvar.id = "definedvar" + definedvar.type = "text" + inp.insertAdjacentElement("afterend", definedvar) + } inp.addEventListener("change", () => { - if (masterdiv.querySelector("#definedvar") == null && inp.value == 1) { + if ((inp.nextElementSibling == null || inp.nextElementSibling.type != "text") && inp.value == 1) { let definedvar = document.createElement("input") definedvar.id = "definedvar" definedvar.type = "text" - form.appendChild(definedvar) - } else if (masterdiv.querySelector("#definedvar") != null && inp.value != 1) { - form.removeChild(masterdiv.querySelector("#definedvar")) + inp.insertAdjacentElement("afterend", definedvar) + } else if (inp.nextElementSibling.type == "text" && inp.value != 1) { + form.removeChild(inp.nextElementSibling) } }) } @@ -511,14 +517,20 @@ button.addEventListener("click", async function() { form.appendChild(document.createElement("br")) form.appendChild(inp) if (appvar["user-defined"]) { + if ((inp.nextElementSibling == null || inp.nextElementSibling.type != "text") && inp.value == 1) { + let definedvar = document.createElement("input") + definedvar.id = "defdefinedvar" + definedvar.type = "text" + inp.insertAdjacentElement("afterend", definedvar) + } inp.addEventListener("change", () => { - if (document.querySelector("#defdefinedvar") == null && inp.value == 1) { + if ((inp.nextElementSibling == null || inp.nextElementSibling.type != "text") && inp.value == 1) { let definedvar = document.createElement("input") definedvar.id = "defdefinedvar" definedvar.type = "text" - form.appendChild(definedvar) - } else if (document.querySelector("#defdefinedvar") != null && inp.value != 1) { - form.removeChild(document.querySelector("#defdefinedvar")) + inp.insertAdjacentElement("afterend", definedvar) + } else if (inp.nextElementSibling.type == "text" && inp.value != 1) { + form.removeChild(inp.nextElementSibling) } }) }