-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontroller.html
More file actions
368 lines (339 loc) · 15 KB
/
Copy pathcontroller.html
File metadata and controls
368 lines (339 loc) · 15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
<title>Tournament Timer Controller</title>
<style>
:root {
--navy: #080e1d; --navy2: #0f1a30; --navy3: #1a2a45;
--gold: #d4af37; --gold2: #f0cc5a; --white: #ffffff;
--gray: #7a90b0; --green: #2ecc71; --red: #e74c3c; --orange: #f39c12;
}
* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body {
background: var(--navy); color: var(--white);
font-family: system-ui, -apple-system, sans-serif;
min-height: 100vh; display: flex; flex-direction: column;
align-items: center; padding: 24px 20px 48px;
}
h1 { font-size: 20px; color: var(--gold); margin-bottom: 2px; text-align: center; font-weight: 700; }
.subtitle { font-size: 12px; color: var(--gray); margin-bottom: 28px; text-align: center; }
.timer-preview {
width: 100%; max-width: 380px; background: var(--navy2);
border: 1px solid rgba(212,175,55,0.3); border-radius: 20px;
padding: 20px 16px 16px; text-align: center; margin-bottom: 24px;
}
.timer-lbl { font-size: 10px; letter-spacing: 0.15em; color: var(--gray); margin-bottom: 4px; }
.timer-big {
font-size: 88px; font-weight: 800; letter-spacing: 0.04em;
line-height: 1; color: var(--gold2); font-variant-numeric: tabular-nums; transition: color 0.3s;
}
.timer-big.warning { color: var(--orange); }
.timer-big.urgent { color: var(--red); animation: pulse 1s infinite; }
.timer-big.paused { color: var(--gray); }
.timer-big.done { color: var(--red); }
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:0.5} }
.status-row { display: flex; align-items: center; justify-content: center; gap: 7px; margin-top: 10px; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--gray); flex-shrink: 0; transition: background 0.3s; }
.dot.running { background: var(--green); box-shadow: 0 0 7px var(--green); }
.dot.paused { background: var(--orange); }
.dot.done { background: var(--red); }
.status-txt { font-size: 13px; color: var(--gray); }
.section { width: 100%; max-width: 380px; margin-bottom: 20px; }
.section-lbl { font-size: 10px; letter-spacing: 0.12em; color: var(--gray); margin-bottom: 8px; }
.dur-row { display: flex; align-items: center; gap: 10px; }
.dur-input {
flex: 1; background: var(--navy2); border: 1px solid rgba(212,175,55,0.35);
border-radius: 12px; color: var(--gold2); font-size: 28px; font-weight: 700;
padding: 14px; text-align: center; outline: none; -moz-appearance: textfield;
}
.dur-input::-webkit-inner-spin-button, .dur-input::-webkit-outer-spin-button { -webkit-appearance: none; }
.dur-unit { font-size: 15px; color: var(--gray); }
.btn {
width: 100%; max-width: 380px; padding: 20px; border-radius: 16px; border: none;
font-size: 20px; font-weight: 700; cursor: pointer;
transition: transform 0.1s, opacity 0.1s; margin-bottom: 10px; letter-spacing: 0.01em;
}
.btn:active { transform: scale(0.97); opacity: 0.88; }
.btn-start { background: var(--green); color: #fff; }
.btn-pause { background: var(--orange); color: #fff; }
.btn-resume { background: var(--green); color: #fff; }
.btn-restart { background: var(--navy3); color: var(--gold2); border: 1px solid rgba(212,175,55,0.35); }
.btn-reset { background: transparent; color: var(--gray); border: 1px solid rgba(255,255,255,0.12); font-size: 16px; padding: 14px; }
.btn:disabled { opacity: 0.3; cursor: default; }
.status-section {
width: 100%; max-width: 380px;
background: var(--navy2);
border: 1px solid rgba(255,255,255,0.08);
border-radius: 16px;
padding: 16px;
margin-bottom: 20px;
}
.status-header {
display: flex; align-items: center; justify-content: space-between;
margin-bottom: 12px;
}
.status-title { font-size: 10px; letter-spacing: 0.14em; color: var(--gray); font-weight: 700; }
.status-refresh {
background: none; border: none; color: var(--gray);
font-size: 14px; cursor: pointer; padding: 2px 6px; border-radius: 4px;
transition: color 0.15s;
}
.status-refresh:hover { color: var(--gold); }
.round-rows { display: flex; flex-direction: column; gap: 6px; }
.round-row {
display: flex; align-items: center; gap: 10px;
padding: 8px 12px; border-radius: 10px;
background: rgba(255,255,255,0.03);
border: 1px solid rgba(255,255,255,0.06);
transition: all 0.3s;
}
.round-row.current {
background: rgba(212,175,55,0.1);
border-color: rgba(212,175,55,0.35);
}
.round-row.done {
background: rgba(46,204,113,0.07);
border-color: rgba(46,204,113,0.2);
}
.rr-label {
font-size: 13px; font-weight: 700; color: var(--gray); min-width: 56px;
}
.round-row.current .rr-label { color: var(--gold2); }
.round-row.done .rr-label { color: var(--green); }
.rr-bar-wrap {
flex: 1; height: 6px; background: rgba(255,255,255,0.08);
border-radius: 3px; overflow: hidden;
}
.rr-bar {
height: 100%; border-radius: 3px;
background: var(--gray);
transition: width 0.4s ease;
}
.round-row.current .rr-bar { background: var(--gold); }
.round-row.done .rr-bar { background: var(--green); }
.rr-count {
font-size: 13px; font-weight: 700; color: var(--gray);
min-width: 36px; text-align: right;
}
.round-row.current .rr-count { color: var(--gold2); }
.round-row.done .rr-count { color: var(--green); }
.rr-check { font-size: 14px; min-width: 18px; text-align: center; }
.status-loading { text-align: center; color: var(--gray); font-size: 13px; padding: 8px 0; }
.reveal-section {
width: 100%; max-width: 380px;
border-top: 1px solid rgba(212,175,55,0.2);
margin-top: 16px; padding-top: 20px;
}
.reveal-label { font-size: 10px; color: var(--gray); letter-spacing: 0.12em; margin-bottom: 10px; text-align: center; }
.btn-reveal {
width: 100%; padding: 22px; border-radius: 16px; border: none;
font-size: 20px; font-weight: 700; cursor: pointer;
transition: transform 0.1s, opacity 0.1s; letter-spacing: 0.02em;
background: linear-gradient(135deg, #d4af37, #f0cc5a);
color: #080e1d;
}
.btn-reveal:active { transform: scale(0.97); opacity: 0.88; }
.btn-reveal:disabled { opacity: 0.3; cursor: default; }
.feedback { font-size: 13px; color: var(--green); text-align: center; min-height: 18px; margin-bottom: 8px; }
.feedback.err { color: var(--red); }
</style>
</head>
<body>
<h1>⏱ Timer Controller</h1>
<p class="subtitle">Euchre — Momma's First Annual Tournament</p>
<div class="timer-preview">
<div class="timer-lbl">CURRENT TIMER</div>
<div class="timer-big" id="timerBig">--:--</div>
<div class="status-row">
<div class="dot" id="dot"></div>
<span class="status-txt" id="statusTxt">Loading…</span>
</div>
</div>
<div class="status-section">
<div class="status-header">
<div class="status-title">SCORE STATUS</div>
<button class="status-refresh" onclick="fetchRoundStatus()" title="Refresh">⟳</button>
</div>
<div id="roundStatusRows"><div class="status-loading">Loading…</div></div>
</div>
<div class="section">
<div class="section-lbl">ROUND DURATION</div>
<div class="dur-row">
<input class="dur-input" id="durInput" type="number" min="1" max="99" value="25" oninput="onDurInput(this.value)">
<span class="dur-unit">minutes</span>
</div>
</div>
<button class="btn btn-start" id="btnStart" onclick="cmdStart()">▶ Start Timer</button>
<button class="btn btn-pause" id="btnPause" onclick="cmdPause()" style="display:none">⏸ Pause</button>
<button class="btn btn-resume" id="btnResume" onclick="cmdResume()" style="display:none">▶ Resume</button>
<button class="btn btn-restart" id="btnRestart" onclick="cmdRestart()" style="display:none">↺ Restart (25 min)</button>
<button class="btn btn-reset" id="btnReset" onclick="cmdReset()" >↺ Reset to 25 min</button>
<div class="feedback" id="fb"></div>
<div class="reveal-section" id="revealSection">
<div class="reveal-label">FINAL REVEAL</div>
<button class="btn btn-reveal" id="btnReveal" onclick="cmdReveal()">🏆 Trigger Final Reveal</button>
<button class="btn btn-reset" id="btnResetReveal" onclick="cmdResetReveal()" style="margin-top:8px;font-size:15px;padding:12px">↺ Reset Reveal Flag</button>
</div>
<script>
const DEFAULT_URL = 'https://script.google.com/macros/s/AKfycbzRvPHxmhoHefHBRwAhAWaPck9E8AasZLr_u4c7CO9oA1jMDQViLpJkzqiHhlfgxvZqAA/exec';
let state = { startedAt: null, remaining: 1500, total: 1500, running: false };
let selectedMins = 25;
function getUrl() { return localStorage.getItem('scriptUrl') || DEFAULT_URL; }
window.addEventListener('load', () => {
fetchState();
setInterval(tick, 500);
setInterval(fetchState, 8000);
});
function onDurInput(v) {
const m = parseInt(v);
if (m > 0) {
selectedMins = m;
document.getElementById('btnRestart').textContent = `↺ Restart (${m} min)`;
}
}
function secsLeft() {
if (!state.startedAt) return state.remaining;
if (!state.running) return state.remaining;
const elapsed = (Date.now() - new Date(state.startedAt).getTime()) / 1000;
return Math.max(0, state.remaining - elapsed);
}
function tick() {
const secs = secsLeft();
const el = document.getElementById('timerBig');
el.textContent = fmt(secs);
if (!state.startedAt) el.className = 'timer-big';
else if (secs <= 0) el.className = 'timer-big done';
else if (!state.running) el.className = 'timer-big paused';
else if (secs <= 30) el.className = 'timer-big urgent';
else if (secs <= 120) el.className = 'timer-big warning';
else el.className = 'timer-big';
}
function updateButtons() {
const started = !!state.startedAt;
const running = state.running;
const done = secsLeft() <= 0 && started;
show('btnStart', !started);
show('btnReset', true); // always visible
show('btnPause', running && !done);
show('btnResume', !running && started && !done);
show('btnRestart', started);
const dot = document.getElementById('dot');
const txt = document.getElementById('statusTxt');
if (!started) { dot.className='dot'; txt.textContent='No timer set'; }
else if (done) { dot.className='dot done'; txt.textContent="Time's up!"; }
else if (running) { dot.className='dot running';txt.textContent='Running on leaderboard'; }
else { dot.className='dot paused'; txt.textContent='Paused'; }
}
function show(id, visible) {
document.getElementById(id).style.display = visible ? 'block' : 'none';
}
async function fetchState() {
try {
const res = await fetch(getUrl() + '?action=getTimer', { cache: 'no-store' });
state = await res.json();
updateButtons();
} catch(e) {}
}
async function api(params) {
fb('Sending…');
try {
const url = getUrl() + '?action=setTimer&' + new URLSearchParams(params);
const res = await fetch(url, { cache: 'no-store' });
state = await res.json();
updateButtons();
fb('✓ Done');
} catch(e) { fb('Connection error', true); }
}
async function cmdResetReveal() {
const btn = document.getElementById('btnResetReveal');
btn.disabled = true; btn.textContent = 'Resetting…';
try {
await fetch(getUrl() + '?action=resetReveal', { cache: 'no-store' });
btn.textContent = '✓ Reset';
setTimeout(() => { btn.textContent = '↺ Reset Reveal Flag'; btn.disabled = false; }, 2000);
} catch(e) { btn.textContent = '↺ Reset Reveal Flag'; btn.disabled = false; }
}
async function cmdReveal() {
const btn = document.getElementById('btnReveal');
btn.disabled = true;
btn.textContent = '🎉 Sending reveal…';
try {
const res = await fetch(getUrl() + '?action=triggerReveal', { cache: 'no-store' });
const data = await res.json();
btn.textContent = '✓ Reveal triggered!';
fb('🏆 Podium reveal sent to TV!');
setTimeout(() => { btn.textContent = '🏆 Trigger Final Reveal'; btn.disabled = false; }, 5000);
} catch(e) {
btn.textContent = '🏆 Trigger Final Reveal';
btn.disabled = false;
fb('Connection error', true);
}
}
function cmdStart() { api({ cmd: 'start', totalSecs: selectedMins * 60 }); }
async function cmdReset() {
// Write reset state to server (running=false) so sync doesn't pull old value back
fb('Resetting…');
try {
const secs = selectedMins * 60;
const url = getUrl() + '?action=setTimer&' + new URLSearchParams({ cmd: 'reset', totalSecs: secs });
const res = await fetch(url, { cache: 'no-store' });
state = await res.json();
updateButtons();
fb('Reset to ' + selectedMins + ' min — press Start when ready');
} catch(e) { fb('Connection error', true); }
}
function cmdRestart() { api({ cmd: 'restart', totalSecs: selectedMins * 60 }); }
function cmdPause() { api({ cmd: 'pause', secsLeft: Math.round(Math.max(0, secsLeft())) }); }
function cmdResume() { api({ cmd: 'resume' }); }
function fmt(s) {
const m = Math.floor(s / 60), sec = Math.floor(s % 60);
return String(m).padStart(2,'0') + ':' + String(sec).padStart(2,'0');
}
function fb(msg, err=false) {
const el = document.getElementById('fb');
el.textContent = msg; el.className = 'feedback' + (err ? ' err' : '');
setTimeout(() => { if (el.textContent === msg) el.textContent = ''; }, 2500);
}
// ── Round status ────────────────────────────────────────────────────────────
async function fetchRoundStatus() {
try {
const res = await fetch(getUrl() + '?action=roundStatus', { cache: 'no-store' });
const data = await res.json();
if (data.status === 'ok') renderRoundStatus(data.roundStatus);
} catch(e) {}
}
function renderRoundStatus(rounds) {
if (!rounds) return;
const container = document.getElementById('roundStatusRows');
// Find current round (first incomplete with any scores, or first round)
const firstIncomplete = rounds.find(r => !r.complete);
const allDone = rounds.every(r => r.complete);
container.innerHTML = rounds.map(r => {
const pct = (r.tablesSubmitted / 5) * 100;
const isDone = r.complete;
const isCurr = !isDone && firstIncomplete && r.round === firstIncomplete.round;
const cls = isDone ? 'done' : isCurr ? 'current' : '';
const check = isDone ? '✅' : isCurr ? '▶' : '';
return `<div class="round-row ${cls}">
<div class="rr-label">Rnd ${r.round}</div>
<div class="rr-bar-wrap"><div class="rr-bar" style="width:${pct}%"></div></div>
<div class="rr-count">${r.tablesSubmitted}/5</div>
<div class="rr-check">${check}</div>
</div>`;
}).join('');
// Show/hint reveal button only when all 6 rounds done
const revealSection = document.getElementById('revealSection');
if (revealSection) {
revealSection.style.opacity = allDone ? '1' : '0.4';
document.getElementById('btnReveal').disabled = !allDone;
document.getElementById('btnReveal').title = allDone ? '' : 'All 6 rounds must be complete first';
}
}
// Fetch on load and every 20s
fetchRoundStatus();
setInterval(fetchRoundStatus, 20000);
</script>
</body>
</html>