This commit is contained in:
ny 2025-06-10 11:38:38 +08:00
parent 7c3ebad987
commit ef8c81ee9e

View File

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