-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
543 lines (514 loc) · 24.5 KB
/
Copy pathindex.html
File metadata and controls
543 lines (514 loc) · 24.5 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
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Values Spotlight</title>
<style>
* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; background: #000; min-height: 100vh; color: #fff; display: flex; flex-direction: column; }
.topbar {
display: flex; align-items: center; justify-content: space-between;
padding: 1.2rem 2rem; border-bottom: 1px solid #1a1a1a;
}
.topbar-left { display: flex; align-items: center; gap: 12px; }
.topbar-title { font-size: 0.7rem; letter-spacing: 0.2em; text-transform: uppercase; color: #555; }
.sync-pill {
display: flex; align-items: center; gap: 6px;
background: rgba(77,255,145,0.08); border: 1px solid rgba(77,255,145,0.2);
border-radius: 20px; padding: 3px 10px;
font-size: 0.6rem; letter-spacing: 0.12em; text-transform: uppercase; color: #4dff91;
}
.sync-dot { width: 5px; height: 5px; border-radius: 50%; background: #4dff91; animation: pulse 2s infinite; }
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:0.3} }
.topbar-badge { background: #b347ff; color: #fff; font-size: 0.65rem; font-weight: 700; letter-spacing: 0.12em; text-transform: uppercase; padding: 4px 12px; border-radius: 2px; }
.stage {
flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
padding: 3rem 2rem; gap: 2rem; position: relative; overflow: hidden;
}
.bg-num {
position: absolute; font-size: 32vw; font-weight: 900; color: #0d0d0d;
top: 50%; left: 50%; transform: translate(-50%,-50%);
pointer-events: none; user-select: none; line-height: 1; z-index: 0; transition: color 0.3s;
}
.stage-inner { position: relative; z-index: 1; width: 100%; max-width: 560px; display: flex; flex-direction: column; align-items: center; gap: 1.5rem; }
.sub-strip {
width: 100%; display: flex; gap: 6px; overflow: hidden;
mask-image: linear-gradient(to right, transparent, black 15%, black 85%, transparent);
-webkit-mask-image: linear-gradient(to right, transparent, black 15%, black 85%, transparent);
}
.sub-strip-inner { display: flex; gap: 6px; animation: scrollstrip 18s linear infinite; }
.sub-chip {
flex-shrink: 0; display: flex; align-items: center; gap: 6px;
background: #0f0f0f; border: 1px solid #1c1c1c; border-radius: 20px;
padding: 5px 12px 5px 8px; white-space: nowrap;
}
.chip-av { width: 20px; height: 20px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 8px; font-weight: 700; flex-shrink: 0; }
.chip-name { font-size: 11px; color: #999; }
.chip-val { font-size: 10px; color: #444; margin-left: 2px; }
@keyframes scrollstrip { 0%{transform:translateX(0)} 100%{transform:translateX(-50%)} }
.drum-wrap { width: 100%; position: relative; }
.drum {
width: 100%; height: 120px; overflow: hidden;
border: 1px solid #1e1e1e; border-radius: 4px;
background: #050505; position: relative;
}
.drum-tape { position: absolute; width: 100%; }
.drum-item { height: 120px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 5px; }
.drum-name { font-size: 2.8rem; font-weight: 900; color: #fff; letter-spacing: -0.03em; line-height: 1; }
.drum-val { font-size: 0.65rem; letter-spacing: 0.22em; text-transform: uppercase; color: #444; }
.drum-top { position: absolute; top: 0; left: 0; right: 0; height: 36px; background: linear-gradient(to bottom, #050505, transparent); z-index: 2; pointer-events: none; }
.drum-bot { position: absolute; bottom: 0; left: 0; right: 0; height: 36px; background: linear-gradient(to top, #050505, transparent); z-index: 2; pointer-events: none; }
.drum-line { position: absolute; left: 0; right: 0; top: calc(50% - 61px); border-top: 1px solid #1c1c1c; z-index: 3; pointer-events: none; transition: border-color 0.3s; }
.drum-line2 { position: absolute; left: 0; right: 0; top: calc(50% + 59px); border-top: 1px solid #1c1c1c; z-index: 3; pointer-events: none; transition: border-color 0.3s; }
.drum-wrap.spinning .drum-line,
.drum-wrap.spinning .drum-line2 { border-color: #b347ff; }
.spin-btn {
width: 100%; padding: 24px;
background: #fff; border: none; border-radius: 4px;
color: #000; font-size: 1.1rem; font-weight: 900;
font-family: inherit; letter-spacing: 0.14em; text-transform: uppercase;
cursor: pointer; transition: background 0.15s, color 0.15s, transform 0.08s;
}
.spin-btn:hover:not(:disabled) { background: #e8e8e8; }
.spin-btn:active:not(:disabled) { transform: scale(0.99); }
.spin-btn:disabled { background: #111; color: #2a2a2a; cursor: not-allowed; }
.spin-btn.going { background: #b347ff; color: #fff; }
.winner-card {
display: none; width: 100%;
border: 1px solid #1e1e1e; border-radius: 4px;
padding: 2.5rem 2rem; text-align: center; background: #050505;
animation: popIn 0.4s cubic-bezier(0.175,0.885,0.32,1.275) forwards;
}
@keyframes popIn { from{opacity:0;transform:scale(0.88)} to{opacity:1;transform:scale(1)} }
.w-eyebrow { font-size: 0.6rem; letter-spacing: 0.22em; text-transform: uppercase; color: #444; margin-bottom: 1.2rem; }
.w-av { width: 72px; height: 72px; border-radius: 50%; margin: 0 auto 1rem; display: flex; align-items: center; justify-content: circle; font-size: 1.5rem; font-weight: 800; }
.w-name { font-size: 2.6rem; font-weight: 900; letter-spacing: -0.03em; color: #fff; margin-bottom: 0.5rem; }
.w-val { display: inline-block; padding: 4px 16px; border-radius: 2px; font-size: 0.62rem; font-weight: 700; letter-spacing: 0.18em; text-transform: uppercase; background: #b347ff; color: #fff; margin-bottom: 1.2rem; }
.w-note { font-size: 0.9rem; color: #555; line-height: 1.75; font-style: italic; max-width: 400px; margin: 0 auto 1.5rem; }
.w-prize { font-size: 0.65rem; letter-spacing: 0.2em; text-transform: uppercase; color: #444; }
.w-prize span { color: #4dff91; font-weight: 700; }
.excluded-note {
font-size: 0.58rem; letter-spacing: 0.14em; text-transform: uppercase;
color: #2a2a2a; text-align: center; padding: 4px 0 0;
}
.excluded-note span { color: #444; }
.mute-btn {
position: fixed; bottom: 1.4rem; right: 1.6rem;
background: #0f0f0f; border: 1px solid #1e1e1e; border-radius: 50%;
width: 38px; height: 38px; display: flex; align-items: center; justify-content: center;
cursor: pointer; font-size: 1rem; transition: border-color 0.15s, background 0.15s;
z-index: 100;
}
.mute-btn:hover { background: #1a1a1a; border-color: #333; }
.mute-btn.muted { opacity: 0.35; }
/* Loading overlay */
.loading-overlay {
position: fixed; inset: 0; background: #000;
display: flex; flex-direction: column; align-items: center; justify-content: center;
gap: 1rem; z-index: 500; transition: opacity 0.5s;
}
.loading-overlay.hidden { opacity: 0; pointer-events: none; }
.loading-spinner {
width: 32px; height: 32px; border-radius: 50%;
border: 2px solid #1a1a1a; border-top-color: #b347ff;
animation: lspin 0.7s linear infinite;
}
@keyframes lspin { to { transform: rotate(360deg); } }
.loading-label { font-size: 0.6rem; letter-spacing: 0.2em; text-transform: uppercase; color: #333; }
.load-error { font-size: 0.65rem; letter-spacing: 0.1em; color: #ff4d6d; text-align: center; max-width: 300px; line-height: 1.7; display: none; margin-top: 0.5rem; }
.load-error.show { display: block; }
.cf-wrap { position: fixed; top:0; left:0; width:100%; height:100%; pointer-events:none; z-index:999; overflow:hidden; }
.cp { position:absolute; top:-12px; animation: cfall linear forwards; }
@keyframes cfall { 0%{opacity:1;top:-12px} 100%{opacity:0;top:110vh} }
.av0{background:rgba(179,71,255,.25);color:#b347ff}
.av1{background:rgba(77,255,145,.18);color:#4dff91}
.av2{background:rgba(255,255,255,.08);color:#999}
.av3{background:rgba(179,71,255,.15);color:#d090ff}
.av4{background:rgba(77,255,145,.1);color:#80ffb8}
</style>
</head>
<body>
<div class="loading-overlay" id="loadingOverlay">
<div class="loading-spinner"></div>
<div class="loading-label" id="loadingLabel">Loading kudos from Motivosity...</div>
<div class="load-error" id="loadError"></div>
</div>
<div class="cf-wrap" id="cf"></div>
<button class="mute-btn" id="muteBtn" title="Toggle sound" onclick="toggleMute()">🔊</button>
<div class="topbar">
<div class="topbar-left">
<span class="topbar-title" id="topbarTitle">Values Spotlight</span>
<div class="sync-pill"><div class="sync-dot"></div>Live from Motivosity</div>
</div>
<span class="topbar-badge">$25 Award</span>
</div>
<div class="stage">
<div class="bg-num" id="bgNum">5</div>
<div class="stage-inner">
<div class="sub-strip">
<div class="sub-strip-inner" id="strip"></div>
</div>
<div class="drum-wrap" id="drumWrap">
<div class="drum">
<div class="drum-tape" id="tape"></div>
<div class="drum-top"></div>
<div class="drum-bot"></div>
<div class="drum-line"></div>
<div class="drum-line2"></div>
</div>
</div>
<button class="spin-btn" id="spinBtn" onclick="spin()">Spin</button>
<div class="excluded-note" id="excludedNote"></div>
<div class="winner-card" id="winnerCard">
<div class="w-eyebrow">This week's winner</div>
<div class="w-av" id="wAv"></div>
<div class="w-name" id="wName"></div>
<div class="w-val" id="wVal"></div>
<div class="w-note" id="wNote"></div>
<div class="w-prize">Recognition Award — <span>$25</span></div>
</div>
</div>
</div>
<script>
// Demo data shown while loading or if the API isn't connected yet
const DEMO_ENTRIES = [
{name:"Sarah Chen", value:"Teamwork", note:"Stayed late to help the team ship the product launch on time."},
{name:"Marcus Rivera", value:"Innovation", note:"Built an automation that saves 4 hours of manual work per week."},
{name:"Priya Patel", value:"Customer Focus", note:"Went above and beyond to resolve a tricky client escalation."},
{name:"Jordan Kim", value:"Integrity", note:"Flagged a billing error that could have overcharged a customer."},
{name:"Alex Thompson", value:"Growth", note:"Completed three certs and shared learnings with the team."},
];
let entries = [...DEMO_ENTRIES];
let spinning = false, winIdx = -1, muted = false;
// ── Audio ──────────────────────────────────────────────────────────────
let audioCtx = null;
function getCtx() {
if (!audioCtx) audioCtx = new (window.AudioContext || window.webkitAudioContext)();
return audioCtx;
}
function toggleMute() {
muted = !muted;
const btn = document.getElementById('muteBtn');
btn.textContent = muted ? '🔇' : '🔊';
btn.classList.toggle('muted', muted);
}
// Snare-like noise burst (for drum roll + cymbal crash)
function playNoise(ctx, t, dur, vol, highpass = 1000) {
const buf = ctx.createBuffer(1, ctx.sampleRate * dur, ctx.sampleRate);
const data = buf.getChannelData(0);
for (let i = 0; i < data.length; i++) data[i] = Math.random() * 2 - 1;
const src = ctx.createBufferSource();
src.buffer = buf;
const hp = ctx.createBiquadFilter();
hp.type = 'highpass'; hp.frequency.value = highpass;
const gain = ctx.createGain();
src.connect(hp); hp.connect(gain); gain.connect(ctx.destination);
gain.gain.setValueAtTime(vol, t);
gain.gain.exponentialRampToValueAtTime(0.001, t + dur);
src.start(t); src.stop(t + dur);
}
// Single click tick for spin
function playTick(time, ctx, freq = 900, vol = 0.2) {
const osc = ctx.createOscillator();
const gain = ctx.createGain();
osc.connect(gain); gain.connect(ctx.destination);
osc.type = 'square';
osc.frequency.setValueAtTime(freq, time);
osc.frequency.exponentialRampToValueAtTime(freq * 0.4, time + 0.035);
gain.gain.setValueAtTime(vol, time);
gain.gain.exponentialRampToValueAtTime(0.001, time + 0.055);
osc.start(time); osc.stop(time + 0.06);
}
function playSpinSound() {
if (muted) return;
const ctx = getCtx();
const spinDuration = 3.9;
const now = ctx.currentTime;
// Phase 1 (0–3.0s): slot machine ticks, slowing down
let t = now + 0.04;
const phase1End = now + 3.0;
while (t < phase1End) {
const progress = (t - now) / 3.0;
const eased = 1 - Math.pow(1 - progress, 2);
const interval = 0.04 + eased * 0.28;
const pitch = 880 - eased * 380;
playTick(t, ctx, pitch, 0.2);
t += interval;
}
// Phase 2 (3.0–3.9s): rapid snare drum roll building to a climax
let rt = now + 3.0;
let rollInterval = 0.09;
while (rt < now + spinDuration - 0.05) {
playNoise(ctx, rt, 0.07, 0.18, 2000);
rollInterval = Math.max(0.03, rollInterval * 0.88); // accelerate
rt += rollInterval;
}
// Final big snare hit right as it stops
playNoise(ctx, now + spinDuration - 0.04, 0.12, 0.35, 1500);
}
function playFanfare() {
if (muted) return;
const ctx = getCtx();
const now = ctx.currentTime;
// ── Kick drum: deep thud at t=0 ──
const kick = ctx.createOscillator();
const kickGain = ctx.createGain();
kick.connect(kickGain); kickGain.connect(ctx.destination);
kick.type = 'sine';
kick.frequency.setValueAtTime(160, now);
kick.frequency.exponentialRampToValueAtTime(40, now + 0.12);
kickGain.gain.setValueAtTime(1.0, now);
kickGain.gain.exponentialRampToValueAtTime(0.001, now + 0.25);
kick.start(now); kick.stop(now + 0.3);
// ── Crowd roar: bandpass-filtered noise swelling up and sustaining ──
const crowdBuf = ctx.createBuffer(1, ctx.sampleRate * 7, ctx.sampleRate);
const crowdData = crowdBuf.getChannelData(0);
for (let i = 0; i < crowdData.length; i++) crowdData[i] = Math.random() * 2 - 1;
const crowdSrc = ctx.createBufferSource();
crowdSrc.buffer = crowdBuf;
const bp = ctx.createBiquadFilter();
bp.type = 'bandpass'; bp.frequency.value = 1200; bp.Q.value = 0.8;
const crowdGain = ctx.createGain();
crowdSrc.connect(bp); bp.connect(crowdGain); crowdGain.connect(ctx.destination);
crowdGain.gain.setValueAtTime(0, now);
crowdGain.gain.linearRampToValueAtTime(0.55, now + 0.3); // fast swell
crowdGain.gain.linearRampToValueAtTime(0.45, now + 1.5); // settle
crowdGain.gain.linearRampToValueAtTime(0.38, now + 4.0); // long sustain
crowdGain.gain.exponentialRampToValueAtTime(0.001, now + 7.0); // slow fade
crowdSrc.start(now); crowdSrc.stop(now + 7.0);
// ── Second crowd layer: slightly different bandpass for texture ──
const crowd2Buf = ctx.createBuffer(1, ctx.sampleRate * 7, ctx.sampleRate);
const crowd2Data = crowd2Buf.getChannelData(0);
for (let i = 0; i < crowd2Data.length; i++) crowd2Data[i] = Math.random() * 2 - 1;
const crowd2Src = ctx.createBufferSource();
crowd2Src.buffer = crowd2Buf;
const bp2 = ctx.createBiquadFilter();
bp2.type = 'bandpass'; bp2.frequency.value = 700; bp2.Q.value = 0.6;
const crowd2Gain = ctx.createGain();
crowd2Src.connect(bp2); bp2.connect(crowd2Gain); crowd2Gain.connect(ctx.destination);
crowd2Gain.gain.setValueAtTime(0, now);
crowd2Gain.gain.linearRampToValueAtTime(0.25, now + 0.5);
crowd2Gain.gain.linearRampToValueAtTime(0.2, now + 4.0);
crowd2Gain.gain.exponentialRampToValueAtTime(0.001, now + 7.0);
crowd2Src.start(now); crowd2Src.stop(now + 7.0);
// ── Cymbal crash ──
playNoise(ctx, now, 2.5, 0.45, 7000);
// ── Brass fanfare: full sweep C4→C6 then held chord ──
const melody = [
{ freq: 261.63, t: 0.00, dur: 0.09 }, // C4
{ freq: 392.00, t: 0.09, dur: 0.09 }, // G4
{ freq: 523.25, t: 0.18, dur: 0.09 }, // C5
{ freq: 659.25, t: 0.27, dur: 0.09 }, // E5
{ freq: 783.99, t: 0.36, dur: 0.09 }, // G5
{ freq: 783.99, t: 0.47, dur: 0.07 }, // G5 bounce
{ freq: 1046.5, t: 0.56, dur: 1.60 }, // C6 — big held note (longer)
];
melody.forEach(({ freq, t, dur }) => {
[
{ type: 'sawtooth', vol: 0.22 },
{ type: 'square', vol: 0.10 },
].forEach(({ type, vol }) => {
const osc = ctx.createOscillator();
const gain = ctx.createGain();
if (type === 'sawtooth') osc.detune.value = 8;
osc.connect(gain); gain.connect(ctx.destination);
osc.type = type;
osc.frequency.setValueAtTime(freq, now + t);
gain.gain.setValueAtTime(0, now + t);
gain.gain.linearRampToValueAtTime(vol, now + t + 0.018);
gain.gain.setValueAtTime(vol, now + t + dur - 0.02);
gain.gain.exponentialRampToValueAtTime(0.001, now + t + dur + 0.35);
osc.start(now + t); osc.stop(now + t + dur + 0.5);
});
});
// ── Second melody phrase — echo of the run, starts after the held note ──
const melody2 = [
{ freq: 783.99, t: 2.4, dur: 0.10 }, // G5
{ freq: 880.00, t: 2.52, dur: 0.10 }, // A5
{ freq: 1046.5, t: 2.64, dur: 0.10 }, // C6
{ freq: 1318.5, t: 2.76, dur: 1.20 }, // E6 — soaring final note
];
melody2.forEach(({ freq, t, dur }) => {
const osc = ctx.createOscillator();
const gain = ctx.createGain();
osc.detune.value = 5;
osc.connect(gain); gain.connect(ctx.destination);
osc.type = 'sawtooth';
osc.frequency.setValueAtTime(freq, now + t);
gain.gain.setValueAtTime(0, now + t);
gain.gain.linearRampToValueAtTime(0.16, now + t + 0.02);
gain.gain.setValueAtTime(0.16, now + t + dur - 0.05);
gain.gain.exponentialRampToValueAtTime(0.001, now + t + dur + 0.6);
osc.start(now + t); osc.stop(now + t + dur + 0.8);
});
// ── Big held chord (enters with the high note, sustains long) ──
[130.81, 261.63, 329.63, 392.00, 523.25, 783.99].forEach(freq => {
const osc = ctx.createOscillator();
const gain = ctx.createGain();
osc.connect(gain); gain.connect(ctx.destination);
osc.type = 'sine';
osc.frequency.setValueAtTime(freq, now + 0.55);
gain.gain.setValueAtTime(0, now + 0.55);
gain.gain.linearRampToValueAtTime(freq < 200 ? 0.18 : 0.09, now + 0.7);
gain.gain.linearRampToValueAtTime(freq < 200 ? 0.14 : 0.07, now + 3.5); // sustain
gain.gain.exponentialRampToValueAtTime(0.001, now + 6.5);
osc.start(now + 0.55); osc.stop(now + 6.6);
});
// ── Shimmer cymbals: one on chord hit, one on second phrase ──
playNoise(ctx, now + 0.55, 2.0, 0.25, 9000);
playNoise(ctx, now + 2.76, 2.5, 0.18, 9500);
}
// ── End Audio ──────────────────────────────────────────────────────────
const STORAGE_KEY = 'vs_last_winner';
const initials = n => n.split(' ').map(p=>p[0]).join('').toUpperCase().slice(0,2);
const avCls = n => 'av'+(Math.abs(n.split('').reduce((a,c)=>a+c.charCodeAt(0),0))%5);
// Returns the eligible pool — everyone except last week's winner.
// If only one person is in entries, the rule is waived so we never have an empty pool.
function eligibleEntries() {
const last = localStorage.getItem(STORAGE_KEY);
if (!last || entries.length <= 1) return entries;
const filtered = entries.filter(e => e.name !== last);
return filtered.length > 0 ? filtered : entries; // fallback: waive rule if everyone was excluded
}
function showExcludedNote() {
const last = localStorage.getItem(STORAGE_KEY);
const note = document.getElementById('excludedNote');
if (last && entries.some(e => e.name === last) && entries.length > 1) {
note.innerHTML = `Not eligible this week: <span>${last}</span> (won last week)`;
} else {
note.innerHTML = '';
}
}
function buildStrip() {
const inner = document.getElementById('strip');
const doubled = [...entries,...entries];
inner.innerHTML = doubled.map(e=>`
<div class="sub-chip">
<div class="chip-av ${avCls(e.name)}">${initials(e.name)}</div>
<span class="chip-name">${e.name}</span>
<span class="chip-val">${e.value ? '· '+e.value : ''}</span>
</div>`).join('');
}
function buildDrum(pool) {
const tape = document.getElementById('tape');
const rep = [...pool,...pool,...pool];
tape.innerHTML = rep.map(e=>`
<div class="drum-item">
<div class="drum-name">${e.name}</div>
<div class="drum-val">${e.value||''}</div>
</div>`).join('');
tape.style.transform = 'translateY(0)';
}
function spin() {
if (spinning) return;
spinning = true;
const pool = eligibleEntries();
buildDrum(pool);
const btn = document.getElementById('spinBtn');
btn.disabled = true;
btn.classList.add('going');
btn.textContent = 'Spinning...';
document.getElementById('winnerCard').style.display = 'none';
document.getElementById('drumWrap').classList.add('spinning');
playSpinSound();
const tape = document.getElementById('tape');
const h = 120, n = pool.length;
winIdx = Math.floor(Math.random() * n);
tape.style.transition = 'none';
tape.style.transform = `translateY(-${n * h}px)`;
setTimeout(() => {
tape.style.transition = 'transform 4s cubic-bezier(0.16,1,0.3,1)';
tape.style.transform = `translateY(-${(n * 2 + winIdx) * h}px)`;
}, 50);
setTimeout(() => {
document.getElementById('drumWrap').classList.remove('spinning');
showWinner(pool);
playFanfare();
launchConfetti();
spinning = false;
btn.classList.remove('going');
btn.textContent = 'Spin again';
btn.disabled = false;
document.getElementById('bgNum').textContent = eligibleEntries().length;
}, 4300);
}
function showWinner(pool) {
const w = pool[winIdx];
// Persist this winner so they're excluded next week
localStorage.setItem(STORAGE_KEY, w.name);
showExcludedNote();
document.getElementById('wAv').className = `w-av ${avCls(w.name)}`;
document.getElementById('wAv').textContent = initials(w.name);
document.getElementById('wName').textContent = w.name;
document.getElementById('wVal').textContent = w.value || 'Recognition';
document.getElementById('wNote').textContent = w.note ? `"${w.note}"` : '';
const card = document.getElementById('winnerCard');
card.style.display = 'block';
card.style.animation = 'none'; card.offsetHeight;
card.style.animation = 'popIn 0.4s cubic-bezier(0.175,0.885,0.32,1.275) forwards';
}
function launchConfetti() {
const wrap = document.getElementById('cf');
wrap.innerHTML = '';
const cols = ['#b347ff','#4dff91','#fff','#d090ff','#80ffb8'];
for (let i = 0; i < 90; i++) {
const el = document.createElement('div');
el.className = 'cp';
const sz = 5 + Math.random() * 8;
el.style.cssText = `left:${Math.random()*100}%;width:${sz}px;height:${sz}px;background:${cols[Math.floor(Math.random()*cols.length)]};border-radius:${Math.random()>.5?'50%':'2px'};animation-duration:${2+Math.random()*2}s;animation-delay:${Math.random()*.6}s;transform:rotate(${Math.random()*360}deg)`;
wrap.appendChild(el);
}
setTimeout(() => wrap.innerHTML = '', 5000);
}
// ── Live data loading ─────────────────────────────────────────────────────────
// Calculates the current week label client-side (mirrors server logic)
function getWeekLabel() {
const now = new Date();
const ptDate = new Date(now.toLocaleString('en-US', { timeZone: 'America/Los_Angeles' }));
const dayPT = ptDate.getDay();
const hourPT = ptDate.getHours();
let daysBack = ((dayPT - 3) + 7) % 7;
if (daysBack === 0 && hourPT < 13) daysBack = 7;
const start = new Date(ptDate);
start.setDate(start.getDate() - daysBack);
const end = new Date(start);
end.setDate(end.getDate() + 7);
const fmt = d => d.toLocaleDateString('en-US', { month: 'short', day: 'numeric' });
return `Values Spotlight — ${fmt(start)} – ${fmt(end)}`;
}
async function loadKudos() {
const overlay = document.getElementById('loadingOverlay');
const label = document.getElementById('loadingLabel');
const errEl = document.getElementById('loadError');
// Set dynamic week label immediately
document.getElementById('topbarTitle').textContent = getWeekLabel();
try {
const res = await fetch('/api/kudos');
const data = await res.json();
if (data.error) throw new Error(data.error);
if (data.kudos && data.kudos.length > 0) {
entries = data.kudos;
} else {
// API connected but no kudos this week yet — keep demo data visible
label.textContent = 'No kudos found this week yet — showing demo data';
errEl.classList.add('show');
errEl.textContent = 'Once people post in #kudos this week, they\'ll appear here automatically.';
}
} catch (err) {
// API not connected (local dev / env vars not set) — silently use demo data
console.warn('Kudos API not available, using demo data:', err.message);
}
// Update background count number
document.getElementById('bgNum').textContent = eligibleEntries().length;
buildStrip();
buildDrum(eligibleEntries());
showExcludedNote();
// Fade out loading overlay
overlay.classList.add('hidden');
setTimeout(() => overlay.style.display = 'none', 500);
}
loadKudos();
</script>
</body>
</html>