/** * Lara Kiesewetter – Live Schachturnier * Data fetching, PGN loading, standings, auto-refresh */ /* global parsePGN, filterLaraGames, getLiveGame, getTodaysGames, getLatestGame */ async function fetchRoundPGN(round) { const res = await fetch(`https://www.deutsche-schachjugend.de/2026/odjm-d/partien/${round}.pgn?t=${Date.now()}`); if (!res.ok) return null; const buf = await res.arrayBuffer(); let text = new TextDecoder('utf-8').decode(buf); if (text.includes('\uFFFD')) { text = new TextDecoder('iso-8859-1').decode(buf); } return text; } async function loadPGN(showOverlay = true) { const currentPollId = pollId; if (showOverlay) showLoading(true); hideError(); try { if (currentRound === 0) { if (showOverlay) showLoading(false); return; } const maxRound = currentRound + 1; const isFirstLoad = Object.keys(roundPgns).length === 0; const startRound = isFirstLoad ? 1 : currentRound; for (let r = startRound; r <= maxRound; r++) { const text = await fetchRoundPGN(r); if (currentPollId !== pollId) return; if (text !== null) roundPgns[r] = text; } const combinedPgn = Object.values(roundPgns).join('\n\n'); const allGames = parsePGN(combinedPgn); allLaraGames = filterLaraGames(allGames); if (allLaraGames.length === 0) { return; } if (!userSelectedGame) { const liveGame = getLiveGame(allLaraGames); const todaysGames = getTodaysGames(allLaraGames); currentGame = liveGame || (todaysGames.length > 0 ? getLatestGame(todaysGames) : getLatestGame(allLaraGames)); } else if (currentGame) { const updatedGame = allLaraGames.find(g => g.white === currentGame.white && g.black === currentGame.black && g.round === currentGame.round ); if (updatedGame) currentGame = updatedGame; } updateBoard(); updatePlayerInfo(); updateMovesList(); updateAllGamesList(); updatePGNDisplay(); updateTimestamp(); showLoading(false); } catch (error) { if (currentPollId !== pollId) return; console.error('Fehler beim Laden:', error); showLoading(false); } } async function updateStandings() { try { const res = await fetch(`https://www.deutsche-schachjugend.de/2026/odjm-d/tabelle/?t=${Date.now()}`); if (!res.ok) throw new Error('Fehler beim Laden'); const html = await res.text(); const roundMatch = html.match(/Tabellenstand\s+nach\s+der\s+(\d+)\.\s*Runde/); if (roundMatch) { currentRound = parseInt(roundMatch[1]); } const rows = html.matchAll(/