325 lines
9.7 KiB
HTML
325 lines
9.7 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Charades Player Display</title>
|
|
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600&family=Roboto+Mono:wght@400;500&display=swap" rel="stylesheet">
|
|
<style>
|
|
* {
|
|
margin: 0;
|
|
padding: 0;
|
|
box-sizing: border-box;
|
|
}
|
|
|
|
body {
|
|
font-family: 'Inter', sans-serif;
|
|
background: #f5f5f5;
|
|
color: #2c3e50;
|
|
height: 100vh;
|
|
display: flex;
|
|
flex-direction: column;
|
|
justify-content: center;
|
|
align-items: center;
|
|
padding: 2rem;
|
|
}
|
|
|
|
.container {
|
|
width: 100%;
|
|
max-width: 1000px;
|
|
}
|
|
|
|
.status-bar {
|
|
background: white;
|
|
border: 2px solid #2c3e50;
|
|
border-radius: 4px;
|
|
padding: 1rem 2rem;
|
|
margin-bottom: 2rem;
|
|
text-align: center;
|
|
}
|
|
|
|
.status-text {
|
|
font-size: 1rem;
|
|
color: #7f8c8d;
|
|
font-weight: 500;
|
|
}
|
|
|
|
.connection-status {
|
|
position: fixed;
|
|
top: 1.5rem;
|
|
right: 1.5rem;
|
|
padding: 0.5rem 1rem;
|
|
border-radius: 3px;
|
|
font-size: 0.875rem;
|
|
font-weight: 500;
|
|
}
|
|
|
|
.connected {
|
|
background: #27ae60;
|
|
color: white;
|
|
}
|
|
|
|
.disconnected {
|
|
background: #e74c3c;
|
|
color: white;
|
|
}
|
|
|
|
.word-display {
|
|
background: white;
|
|
border: 3px solid #2c3e50;
|
|
border-radius: 4px;
|
|
padding: 4rem 2rem;
|
|
text-align: center;
|
|
min-height: 400px;
|
|
display: flex;
|
|
flex-direction: column;
|
|
justify-content: center;
|
|
align-items: center;
|
|
}
|
|
|
|
.current-word {
|
|
font-size: 5rem;
|
|
font-weight: 600;
|
|
color: #2c3e50;
|
|
line-height: 1.2;
|
|
word-wrap: break-word;
|
|
margin-bottom: 2rem;
|
|
}
|
|
|
|
.timer {
|
|
font-family: 'Roboto Mono', monospace;
|
|
font-size: 4rem;
|
|
color: #34495e;
|
|
font-weight: 500;
|
|
margin-top: 1rem;
|
|
}
|
|
|
|
.timer.warning {
|
|
color: #e67e22;
|
|
}
|
|
|
|
.timer.danger {
|
|
color: #e74c3c;
|
|
}
|
|
|
|
.waiting-message {
|
|
font-size: 1.5rem;
|
|
color: #95a5a6;
|
|
font-weight: 400;
|
|
}
|
|
|
|
.last-word-status {
|
|
position: fixed;
|
|
bottom: 2rem;
|
|
left: 50%;
|
|
transform: translateX(-50%);
|
|
padding: 1rem 2rem;
|
|
border-radius: 4px;
|
|
font-size: 1.25rem;
|
|
font-weight: 500;
|
|
}
|
|
|
|
.status-correct {
|
|
background: #27ae60;
|
|
color: white;
|
|
border: 2px solid #229954;
|
|
}
|
|
|
|
.status-incorrect {
|
|
background: #e74c3c;
|
|
color: white;
|
|
border: 2px solid #c0392b;
|
|
}
|
|
|
|
.status-hidden {
|
|
display: none;
|
|
}
|
|
|
|
@media (max-width: 768px) {
|
|
body {
|
|
padding: 1rem;
|
|
}
|
|
|
|
.current-word {
|
|
font-size: 3rem;
|
|
}
|
|
|
|
.timer {
|
|
font-size: 2.5rem;
|
|
}
|
|
|
|
.waiting-message {
|
|
font-size: 1.25rem;
|
|
}
|
|
|
|
.word-display {
|
|
padding: 3rem 1.5rem;
|
|
min-height: 300px;
|
|
}
|
|
|
|
.status-bar {
|
|
padding: 0.75rem 1rem;
|
|
}
|
|
|
|
.status-text {
|
|
font-size: 0.9rem;
|
|
}
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div class="connection-status connected" id="connection-status">
|
|
Connected
|
|
</div>
|
|
|
|
<div class="container">
|
|
<div class="status-bar">
|
|
<div id="player-info" class="status-text">Waiting for game to start...</div>
|
|
</div>
|
|
|
|
<div class="word-display">
|
|
<div id="current-word" class="current-word" style="display: none;"></div>
|
|
<div id="waiting-message" class="waiting-message">
|
|
Waiting for the next word...
|
|
</div>
|
|
<div id="timer" class="timer" style="display: none;"></div>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="last-word-status" class="last-word-status status-hidden"></div>
|
|
|
|
<script>
|
|
// Elements
|
|
const currentWordEl = document.getElementById('current-word');
|
|
const waitingMessageEl = document.getElementById('waiting-message');
|
|
const timerEl = document.getElementById('timer');
|
|
const lastWordStatusEl = document.getElementById('last-word-status');
|
|
const playerInfoEl = document.getElementById('player-info');
|
|
const connectionStatusEl = document.getElementById('connection-status');
|
|
|
|
let lastWordStatus = -1;
|
|
let pollInterval = null;
|
|
|
|
async function fetchCurrentWord() {
|
|
try {
|
|
const response = await fetch('/current-word');
|
|
if (!response.ok) {
|
|
throw new Error(`HTTP error! status: ${response.status}`);
|
|
}
|
|
|
|
const data = await response.json();
|
|
updateDisplay(data);
|
|
|
|
// Update connection status
|
|
connectionStatusEl.textContent = 'Connected';
|
|
connectionStatusEl.className = 'connection-status connected';
|
|
|
|
} catch (error) {
|
|
console.error('Error fetching current word:', error);
|
|
connectionStatusEl.textContent = 'Connection Error';
|
|
connectionStatusEl.className = 'connection-status disconnected';
|
|
}
|
|
}
|
|
|
|
function updateDisplay(data) {
|
|
// Show last word status only when it changes and is not -1 (no previous word)
|
|
if (data.lastWordStatus !== lastWordStatus && data.lastWordStatus !== -1) {
|
|
showLastWordStatus(data.lastWordStatus);
|
|
lastWordStatus = data.lastWordStatus;
|
|
}
|
|
|
|
if (data.isActive && data.word && data.word.trim() !== '') {
|
|
// Show active word with timer
|
|
currentWordEl.textContent = data.word;
|
|
currentWordEl.style.display = 'block';
|
|
waitingMessageEl.style.display = 'none';
|
|
timerEl.style.display = 'block';
|
|
|
|
updateTimer(data.timeRemaining);
|
|
playerInfoEl.textContent = `Current Word - Time Remaining: ${data.timeRemaining.toFixed(1)}s`;
|
|
|
|
} else if (!data.isActive && data.word && data.word.trim() !== '') {
|
|
// Show word without timer (time is up or no time set)
|
|
currentWordEl.textContent = data.word;
|
|
currentWordEl.style.display = 'block';
|
|
waitingMessageEl.style.display = 'none';
|
|
timerEl.style.display = 'none';
|
|
|
|
playerInfoEl.textContent = 'Current Word - No Time Limit';
|
|
|
|
} else {
|
|
// No word, show waiting message
|
|
currentWordEl.style.display = 'none';
|
|
waitingMessageEl.style.display = 'block';
|
|
timerEl.style.display = 'none';
|
|
|
|
playerInfoEl.textContent = 'Waiting for next word...';
|
|
}
|
|
}
|
|
|
|
function updateTimer(timeRemaining) {
|
|
const seconds = Math.max(0, timeRemaining);
|
|
timerEl.textContent = seconds.toFixed(1) + 's';
|
|
|
|
// Update timer color based on remaining time
|
|
timerEl.className = 'timer';
|
|
if (seconds <= 5) {
|
|
timerEl.classList.add('danger');
|
|
} else if (seconds <= 10) {
|
|
timerEl.classList.add('warning');
|
|
}
|
|
}
|
|
|
|
function showLastWordStatus(status) {
|
|
if (status === 1) {
|
|
lastWordStatusEl.textContent = 'Previous word: CORRECT';
|
|
lastWordStatusEl.className = 'last-word-status status-correct';
|
|
setTimeout(() => {
|
|
lastWordStatusEl.className = 'last-word-status status-hidden';
|
|
}, 3000);
|
|
} else if (status === 0) {
|
|
lastWordStatusEl.textContent = 'Previous word: Time Up';
|
|
lastWordStatusEl.className = 'last-word-status status-incorrect';
|
|
setTimeout(() => {
|
|
lastWordStatusEl.className = 'last-word-status status-hidden';
|
|
}, 3000);
|
|
}
|
|
}
|
|
|
|
function startPolling() {
|
|
// Initial fetch
|
|
fetchCurrentWord();
|
|
|
|
// Poll every 200ms for smooth timer updates
|
|
pollInterval = setInterval(fetchCurrentWord, 200);
|
|
}
|
|
|
|
function stopPolling() {
|
|
if (pollInterval) {
|
|
clearInterval(pollInterval);
|
|
pollInterval = null;
|
|
}
|
|
}
|
|
|
|
// Start polling when page loads
|
|
window.addEventListener('load', () => {
|
|
startPolling();
|
|
});
|
|
|
|
// Stop polling when page is about to unload
|
|
window.addEventListener('beforeunload', () => {
|
|
stopPolling();
|
|
});
|
|
|
|
// Handle page visibility changes (pause polling when tab is hidden)
|
|
document.addEventListener('visibilitychange', () => {
|
|
if (document.hidden) {
|
|
stopPolling();
|
|
} else {
|
|
startPolling();
|
|
}
|
|
});
|
|
</script>
|
|
</body>
|
|
</html>
|