From 7f7bd6f381d4eb419391f23fef4df8394fc76a77 Mon Sep 17 00:00:00 2001 From: mv Date: Sun, 11 Aug 2024 18:19:09 +0300 Subject: [PATCH] Fix Firefox creating new tbodys and being able to type higher numbers --- random.js | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/random.js b/random.js index 7f18593..2d3f76c 100644 --- a/random.js +++ b/random.js @@ -76,10 +76,10 @@ function getRandomWeapons(weaponset, howmany, perk) { var chosenweapons = []; var totalweight = 0; var totalprice = 0; + var containsFireAxe = false; var i = 0; - console.log(`isfirebug: ${isfirebug}`) do { - var containsFireAxe = false; + containsFireAxe = false; i = i + 1; chosenweapons = []; totalweight = 0; @@ -87,7 +87,6 @@ function getRandomWeapons(weaponset, howmany, perk) { chosenweapons.forEach(e => { totalweight += e.weight }); if (i < 75000) { if (isfirebug) containsFireAxe = chosenweapons.some(e=>e === vanillaWeapons[1]); - console.log(`containsFireAxe: ${containsFireAxe}`) totalling = !(areDistinct(chosenweapons) && totalweight < weightmax && !containsFireAxe); } else { totalling = false; @@ -132,7 +131,18 @@ selperk.addEventListener("change", changePerkAndOrSetFunction); selset.addEventListener("change", changePerkAndOrSetFunction); selsuplvl.addEventListener("change", () => { localStorage.setItem("supportlvl", selsuplvl.value); - changePerkAndOrSetFunction() + changePerkAndOrSetFunction(); +}); + +selnum.addEventListener("keyup", () => { + if (selnum.value != "") { + if (parseInt(selnum.value) < parseInt(selnum.min)) { + selnum.value = selnum.min; + } + if (parseInt(selnum.value) > parseInt(selnum.max)) { + selnum.value = selnum.max; + } + } }); document.getElementById("random").addEventListener("click", () => { @@ -141,8 +151,6 @@ document.getElementById("random").addEventListener("click", () => { if (selnum.value == 0) selnum.value = 2; var randomWeapon = getRandomWeapons(set, selnum.value, selperk.value) if (Object.keys(randomWeapon) != 0) { - document.getElementById("tbody").insertAdjacentHTML('afterend', - `Total price: ${randomWeapon.totalprice} | Total weight: ${randomWeapon.totalweight}`); randomWeapon.chosenweapons.forEach(e=>{ document.getElementById("tbody").insertAdjacentHTML('beforeend', ` ${e.name} @@ -151,7 +159,9 @@ document.getElementById("random").addEventListener("click", () => { ${e.category} `); }) - } else { alert("shit failed, hit the button again") } + document.getElementById("tbody").insertAdjacentHTML('beforeend', + `Total price: ${randomWeapon.totalprice} | Total weight: ${randomWeapon.totalweight}`); + } else { alert("shit failed, hit the button again or try lowering the number of weapons") } }) -}////////////////////////////////////////////////////////////////////// \ No newline at end of file +}//////////////////////////////////////////////////////////////////////