diff --git a/static/webui/script.js b/static/webui/script.js index c0550a4f..62abca5c 100644 --- a/static/webui/script.js +++ b/static/webui/script.js @@ -1012,10 +1012,9 @@ function updateInventory() { } document.getElementById("changeSyndicate").value = data.SupportedSyndicate ?? ""; - document.getElementById("Boosters-list").innerHTML = ""; const now = Math.floor(Date.now() / 1000); - data.Boosters.forEach(({ItemType, ExpiryDate}) => { + data.Boosters.forEach(({ ItemType, ExpiryDate }) => { if (ExpiryDate < now) { // Booster has expired, skip it return; @@ -1035,7 +1034,7 @@ function updateInventory() { const a = document.createElement("a"); a.href = "#"; - a.onclick = (event)=>{ + a.onclick = event => { event.preventDefault(); if (inlineForm.style.display === "none") { inlineForm.style.display = "inline"; @@ -1052,9 +1051,9 @@ function updateInventory() { a.title = loc("code_changeExpiry"); a.classList.add("text-decoration-none"); td.appendChild(a); - - const submit = ()=>{ - if (doChangeBoosterExpiry(ItemType, input.value)){ + + const submit = () => { + if (doChangeBoosterExpiry(ItemType, input.value)) { inlineForm.style.display = "none"; input.value = ""; a.style.display = "inline"; @@ -1074,15 +1073,15 @@ function updateInventory() { if (inlineForm.style.display === "inline") { submit(); } - } + }; inlineForm.appendChild(input); - + td.appendChild(inlineForm); - + tr.appendChild(td); } document.getElementById("Boosters-list").appendChild(tr); - }) + }); }); }); } @@ -2105,10 +2104,12 @@ function setBooster(ItemType, ExpiryDate) { $.post({ url: "/custom/setBooster?" + window.authz, contentType: "application/json", - data: JSON.stringify([{ - ItemType, - ExpiryDate - }]) + data: JSON.stringify([ + { + ItemType, + ExpiryDate + } + ]) }).done(function () { updateInventory(); }); @@ -2121,7 +2122,7 @@ function doAcquireBoosters() { $("#acquire-type-Boosters").addClass("is-invalid").focus(); return; } - const ExpiryDate = (Date.now() / 1000) + 3 * 24 * 60 * 60; // default 3 days + const ExpiryDate = Date.now() / 1000 + 3 * 24 * 60 * 60; // default 3 days setBooster(uniqueName, ExpiryDate); } @@ -2130,7 +2131,9 @@ function doChangeBoosterExpiry(ItemType, ExpiryDateInput) { // cast local datetime string to unix timestamp const ExpiryDate = new Date(ExpiryDateInput).getTime() / 1000; if (isNaN(ExpiryDate)) { - $("#expiry-date-" + ItemType).addClass("is-invalid").focus(); + $("#expiry-date-" + ItemType) + .addClass("is-invalid") + .focus(); return false; } setBooster(ItemType, ExpiryDate); @@ -2138,32 +2141,32 @@ function doChangeBoosterExpiry(ItemType, ExpiryDateInput) { } function formatDatetime(fmt, date) { - if (typeof date === 'number') date = new Date(date); + if (typeof date === "number") date = new Date(date); return fmt.replace(/(%[yY]|%m|%[Dd]|%H|%h|%M|%[Ss]|%[Pp])/g, match => { switch (match) { - case '%Y': + case "%Y": return date.getFullYear().toString(); - case '%y': + case "%y": return date.getFullYear().toString().slice(-2); - case '%m': - return (date.getMonth() + 1).toString().padStart(2, '0'); - case '%D': - case '%d': - return date.getDate().toString().padStart(2, '0'); - case '%H': - return date.getHours().toString().padStart(2, '0'); - case '%h': - return (date.getHours() % 12).toString().padStart(2, '0'); - case '%M': - return date.getMinutes().toString().padStart(2, '0'); - case '%S': - case '%s': - return date.getSeconds().toString().padStart(2, '0'); - case '%P': - case '%p': - return date.getHours() < 12 ? 'am' : 'pm'; + case "%m": + return (date.getMonth() + 1).toString().padStart(2, "0"); + case "%D": + case "%d": + return date.getDate().toString().padStart(2, "0"); + case "%H": + return date.getHours().toString().padStart(2, "0"); + case "%h": + return (date.getHours() % 12).toString().padStart(2, "0"); + case "%M": + return date.getMinutes().toString().padStart(2, "0"); + case "%S": + case "%s": + return date.getSeconds().toString().padStart(2, "0"); + case "%P": + case "%p": + return date.getHours() < 12 ? "am" : "pm"; default: return match; } - }) -} \ No newline at end of file + }); +}