18 lines
738 B
JavaScript
18 lines
738 B
JavaScript
// client.js (in your existing <script>)
|
|
let remaining = 12;
|
|
async function refreshRemaining() {
|
|
try {
|
|
const r = await fetch('/api/inventory'); const j = await r.json();
|
|
remaining = j.remaining;
|
|
document.querySelectorAll('[data-remaining] .remN').forEach(s => s.textContent = remaining);
|
|
// Disable all three server buttons if none left:
|
|
if (remaining <= 0) {
|
|
document.querySelectorAll('[data-add="server1"],[data-add="server2"],[data-add="server3"]').forEach(btn => {
|
|
btn.disabled = true; btn.textContent = 'Sold out';
|
|
});
|
|
}
|
|
} catch { }
|
|
}
|
|
refreshRemaining();
|
|
setInterval(refreshRemaining, 30_000); // stay “24/7” up-to-date
|