Files
lara-schach-live/js/app.js

69 lines
1.7 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* Lara Kiesewetter Live Schachturnier
* Event listeners and initialization
*/
/* global $, Chess, Chessboard */
document.getElementById('refresh-btn').addEventListener('click', () => {
pollId++;
startAutoRefresh();
});
document.querySelectorAll('.copy-pgn-btn').forEach(btn => {
btn.addEventListener('click', async () => {
const panel = btn.closest('[class*="pgn-panel"]');
const text = panel.querySelector('.pgn-text').textContent;
if (!text) return;
try {
await navigator.clipboard.writeText(text);
btn.textContent = '✅';
setTimeout(() => { btn.textContent = '📋'; }, 1500);
} catch {
const ta = document.createElement('textarea');
ta.value = text;
document.body.appendChild(ta);
ta.select();
document.execCommand('copy');
document.body.removeChild(ta);
}
});
});
document.addEventListener('keydown', (e) => {
if (!currentGame) return;
if (e.key === 'ArrowLeft') {
e.preventDefault();
goToMove(currentMoveIndex - 1);
} else if (e.key === 'ArrowRight') {
e.preventDefault();
goToMove(currentMoveIndex + 1);
}
});
window.addEventListener('resize', () => {
if (board) board.resize();
});
if (window.ResizeObserver) {
const ro = new ResizeObserver(() => {
if (board) board.resize();
});
ro.observe(document.getElementById('board'));
}
document.addEventListener('visibilitychange', () => {
if (document.hidden) {
clearInterval(pollInterval);
clearInterval(updateTimer);
} else {
startAutoRefresh();
}
});
loadPGN();
startAutoRefresh();
chess = new Chess();
updateEvaluation();