Fix Firefox creating new tbodys and being able to type higher numbers

This commit is contained in:
mv 2024-08-11 18:19:09 +03:00
parent 759cf9e929
commit 7f7bd6f381
1 changed files with 18 additions and 8 deletions

View File

@ -76,10 +76,10 @@ function getRandomWeapons(weaponset, howmany, perk) {
var chosenweapons = [];
var totalweight = 0;
var totalprice = 0;
var i = 0;
console.log(`isfirebug: ${isfirebug}`)
do {
var containsFireAxe = false;
var i = 0;
do {
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',
`<tr class="row"><th colspan="4">Total price: ${randomWeapon.totalprice} | Total weight: ${randomWeapon.totalweight}</td></tr>`);
randomWeapon.chosenweapons.forEach(e=>{
document.getElementById("tbody").insertAdjacentHTML('beforeend', `<tr class="row">
<td>${e.name}</td>
@ -151,7 +159,9 @@ document.getElementById("random").addEventListener("click", () => {
<td>${e.category}</td>
</tr>`);
})
} else { alert("shit failed, hit the button again") }
document.getElementById("tbody").insertAdjacentHTML('beforeend',
`<tr class="row"><th colspan="4">Total price: ${randomWeapon.totalprice} | Total weight: <b>${randomWeapon.totalweight}</th></tr>`);
} else { alert("shit failed, hit the button again or try lowering the number of weapons") }
})
}//////////////////////////////////////////////////////////////////////