Uhrzeit des letzten PGN-Updates und Countdown bis zum nächsten Update

This commit is contained in:
2026-05-24 14:33:08 +02:00
parent 6d588a4d5c
commit 414732cb7e
3 changed files with 42 additions and 9 deletions

24
app.js
View File

@@ -13,6 +13,7 @@ let currentGame = null;
let allLaraGames = [];
let refreshTimer = null;
let countdown = 0;
let serverLastFetch = null;
/**
* Lädt die PGN-Datei und aktualisiert die Anzeige
@@ -22,12 +23,19 @@ async function loadPGN() {
hideError();
try {
// Lokaler Proxy-Server (python server.py)
const response = await fetch('http://localhost:8111/pgn');
const [pgnResponse, statusResponse] = await Promise.all([
fetch('http://localhost:8111/pgn'),
fetch('http://localhost:8111/status').catch(() => null)
]);
if (!response.ok) throw new Error(`HTTP ${response.status}`);
if (!pgnResponse.ok) throw new Error(`HTTP ${pgnResponse.status}`);
const pgnText = await response.text();
if (statusResponse && statusResponse.ok) {
const status = await statusResponse.json();
serverLastFetch = status.last_fetch ? status.last_fetch * 1000 : null;
}
const pgnText = await pgnResponse.text();
const allGames = parsePGN(pgnText);
allLaraGames = filterLaraGames(allGames);
@@ -278,9 +286,9 @@ function formatClock(clockStr) {
* Update timestamp
*/
function updateTimestamp() {
const now = new Date();
const time = serverLastFetch ? new Date(serverLastFetch) : new Date();
document.getElementById('last-update').textContent =
`Letztes Update: ${now.toLocaleTimeString('de-DE')}`;
`Letztes Update: ${time.toLocaleTimeString('de-DE')}`;
}
/**
@@ -293,8 +301,10 @@ function startAutoRefresh() {
refreshTimer = setInterval(() => {
countdown--;
const mins = Math.floor(countdown / 60);
const secs = countdown % 60;
document.getElementById('refresh-timer').textContent =
`Nächste Aktualisierung: ${countdown}s`;
`Nächstes Update in: ${String(mins).padStart(2, '0')}:${String(secs).padStart(2, '0')}`;
if (countdown <= 0) {
countdown = REFRESH_INTERVAL / 1000;