This commit is contained in:
2026-10-17 14:13:24 +07:00
parent c03be07eab
commit 14ce58f303
3 changed files with 26 additions and 1 deletions
+23
View File
@@ -32,4 +32,27 @@ async function loadLatestBuild() {
}
}
async function loadServerStatus() {
const status = document.getElementById('server-status');
try {
const response = await fetch('/minecraft/api/status', {
cache: 'no-store',
signal: AbortSignal.timeout(10000),
});
if (!response.ok) throw new Error('Статус недоступен');
const data = await response.json();
if (data?.online === false) {
status.textContent = 'Сервер недоступен';
} else if (data?.online === true && Number.isSafeInteger(data.players?.online) && data.players.online >= 0) {
status.textContent = `Игроков онлайн: ${data.players.online}`;
} else {
throw new Error('Неизвестный формат статуса');
}
} catch {
status.textContent = 'Не удалось получить онлайн';
}
}
loadLatestBuild();
loadServerStatus();
setInterval(loadServerStatus, 5 * 60 * 1000);