-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtimer_overlay.html
More file actions
710 lines (642 loc) · 25.5 KB
/
timer_overlay.html
File metadata and controls
710 lines (642 loc) · 25.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
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>SessionPulse — Timer Overlay</title>
<style>
:root {
--focus-color: #22c55e;
--focus-glow: rgba(34, 197, 94, 0.3);
--focus-gradient-end: #06b6d4;
--short-break-color: #3b82f6;
--short-break-glow: rgba(59, 130, 246, 0.3);
--short-break-gradient-end: #818cf8;
--long-break-color: #a855f7;
--long-break-glow: rgba(168, 85, 247, 0.3);
--long-break-gradient-end: #ec4899;
--stopwatch-color: #f59e0b;
--stopwatch-glow: rgba(245, 158, 11, 0.3);
--stopwatch-gradient-end: #f97316;
--countdown-color: #f97316;
--countdown-glow: rgba(249, 115, 22, 0.3);
--countdown-gradient-end: #ef4444;
--overtime-color: #ef4444;
--overtime-glow: rgba(239, 68, 68, 0.4);
--overtime-gradient-end: #f97316;
--idle-color: #475569;
--ring-bg: rgba(255, 255, 255, 0.04);
--text-primary: #f1f5f9;
--text-secondary: rgba(241, 245, 249, 0.65);
--text-muted: rgba(241, 245, 249, 0.4);
--size: 400px;
--stroke: 14;
}
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
background: transparent;
display: flex;
align-items: center;
justify-content: center;
width: var(--size);
height: var(--size);
font-family: 'Segoe UI Variable', 'Segoe UI', 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
overflow: hidden;
border-radius: 50%;
}
.timer-container {
position: relative;
width: var(--size);
height: var(--size);
display: flex;
align-items: center;
justify-content: center;
transition: transform 0.6s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.5s ease;
}
/* ── Frosted glass backdrop ── */
.backdrop {
position: absolute;
inset: 7%;
border-radius: 50%;
background: radial-gradient(
ellipse at 48% 42%,
var(--sp-backdrop-bg, rgba(12, 16, 28, 0.8)),
var(--sp-backdrop-bg-edge, rgba(4, 8, 18, 0.93))
);
backdrop-filter: blur(var(--sp-backdrop-blur, 24px));
-webkit-backdrop-filter: blur(var(--sp-backdrop-blur, 24px));
border: 1px solid var(--sp-backdrop-border, rgba(255, 255, 255, 0.06));
box-shadow:
inset 0 1px 0 rgba(255, 255, 255, 0.03),
inset 0 -2px 8px rgba(0, 0, 0, 0.15);
transition: border-color 1s ease, box-shadow 1s ease;
}
/* ── Glow ── */
.glow {
position: absolute;
width: 50%;
height: 50%;
border-radius: 50%;
filter: var(--sp-glow-filter, blur(40px));
opacity: 0;
transition: opacity 1.2s ease, background 0.8s ease;
}
.glow.active {
opacity: var(--sp-glow-opacity, 1);
animation: breathe 5s ease-in-out infinite;
}
@keyframes breathe {
0%, 100% { transform: scale(1); opacity: var(--sp-glow-opacity, 1); }
50% { transform: scale(1.15); opacity: calc(var(--sp-glow-opacity, 1) * 0.5); }
}
/* ── Ring SVG ── */
.ring-svg {
position: absolute;
width: 100%;
height: 100%;
transform: rotate(-90deg);
overflow: visible;
}
.ring-bg {
fill: none;
stroke: var(--ring-bg);
stroke-width: var(--sp-ring-stroke, var(--stroke));
}
.ring-progress {
fill: none;
stroke: url(#ringGradient);
stroke-width: var(--sp-ring-stroke, var(--stroke));
stroke-linecap: round;
transition: stroke-dashoffset 0.8s cubic-bezier(0.4, 0, 0.2, 1);
filter: var(--sp-ring-filter, drop-shadow(0 0 6px currentColor) drop-shadow(0 0 2px currentColor));
}
/* Glow cap — leads the ring progress */
.ring-cap {
filter: blur(3px);
opacity: 0;
transition: opacity 0.6s ease;
}
.ring-cap.active { opacity: 1; }
/* Session tracker segments */
.tracker-segment {
fill: none;
stroke-width: var(--sp-tracker-stroke, 4);
stroke-linecap: round;
transition: stroke 0.4s ease, opacity 0.4s ease;
}
/* Tick marks */
.tick {
stroke: rgba(255, 255, 255, 0.04);
stroke-width: 1.2;
stroke-linecap: round;
}
/* ── Center content ── */
.center {
position: relative;
z-index: 2;
text-align: center;
display: flex;
flex-direction: column;
align-items: center;
gap: 0;
}
.time {
font-size: var(--sp-time-size, 5.4rem);
font-weight: var(--sp-time-weight, 700);
color: var(--text-primary);
letter-spacing: -2px;
line-height: 1;
font-variant-numeric: tabular-nums;
text-shadow: 0 2px 20px rgba(0, 0, 0, 0.6);
-webkit-text-stroke: var(--sp-time-stroke, 0.5px) rgba(255, 255, 255, 0.1);
paint-order: stroke fill;
transition: color 0.4s ease, text-shadow 0.6s ease;
}
.time.overtime {
color: var(--overtime-color);
text-shadow: 0 0 30px rgba(239, 68, 68, 0.5), 0 2px 20px rgba(0, 0, 0, 0.5);
}
.session-label {
font-size: var(--sp-label-size, 1.45rem);
font-weight: 700;
text-transform: uppercase;
letter-spacing: 5px;
color: var(--text-secondary);
transition: color 0.6s ease, text-shadow 0.6s ease, letter-spacing 0.4s ease;
text-shadow: 0 1px 8px rgba(0, 0, 0, 0.5);
margin-top: 6px;
}
/* ── Status takeover — label becomes status message ── */
.session-label.status-active {
color: var(--sp-status-color, #f59e0b);
text-shadow: 0 0 16px rgba(245, 158, 11, 0.4), 0 1px 8px rgba(0, 0, 0, 0.5);
letter-spacing: 3px;
text-transform: none;
animation: pulse-status 2.5s ease-in-out infinite;
}
@keyframes pulse-status {
0%, 100% { opacity: 1; }
50% { opacity: 0.6; }
}
.stats {
font-size: var(--sp-stats-size, 1rem);
font-weight: 500;
color: var(--text-muted);
margin-top: 6px;
text-shadow: 0 1px 6px rgba(0, 0, 0, 0.4);
letter-spacing: 0.5px;
}
/* ── Next-up line (inside center content) ── */
.next-line {
font-size: var(--sp-next-size, 0.82rem);
font-weight: 500;
color: var(--text-muted);
margin-top: 5px;
text-shadow: 0 1px 6px rgba(0, 0, 0, 0.4);
letter-spacing: 0.4px;
white-space: nowrap;
opacity: 0;
transition: opacity 0.4s ease;
}
.next-line.visible { opacity: 1; }
.info-line {
max-width: 240px;
font-size: 0.82rem;
font-weight: 500;
color: var(--text-secondary);
opacity: 0;
margin-top: 4px;
text-align: center;
text-shadow: 0 1px 6px rgba(0, 0, 0, 0.4);
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
transition: opacity 0.3s ease;
}
.info-line.visible { opacity: 0.85; }
/* ── Bottom pill (transition messages) ── */
.bottom-pill {
display: var(--sp-transition-display, block);
position: absolute;
bottom: 14%;
left: 50%;
transform: translateX(-50%);
z-index: 4;
font-size: 0.82rem;
font-weight: 600;
color: var(--text-primary);
white-space: nowrap;
background: rgba(0, 0, 0, 0.55);
padding: 4px 16px;
border-radius: 14px;
border: 1px solid rgba(255, 255, 255, 0.06);
text-shadow: 0 1px 8px rgba(0, 0, 0, 0.5);
letter-spacing: 0.4px;
opacity: 0;
transition: opacity 0.4s ease;
}
.bottom-pill.visible { opacity: 1; }
/* ── States ── */
@keyframes pulse-pause {
0%, 100% { opacity: 1; }
50% { opacity: 0.2; }
}
.paused .time { animation: pulse-pause 2.2s ease-in-out infinite; }
.paused .session-label { animation: pulse-pause 2.2s ease-in-out infinite; }
.paused .glow { opacity: 0.1 !important; animation: none; }
.paused .ring-cap { opacity: 0.2 !important; }
@keyframes pulse-overtime {
0%, 100% { opacity: 1; transform: scale(1); }
50% { opacity: 0.45; transform: scale(0.98); }
}
.overtime .ring-svg { animation: pulse-overtime 1.5s ease-in-out infinite; }
.idle { opacity: 0.5; transform: scale(0.96); }
.idle .time { opacity: 0.4; }
.idle .session-label { opacity: 0.3; }
.idle .backdrop { opacity: 0.6; }
/* ── Glassmorphism ── */
.timer-container::before {
content: '';
display: var(--sp-glass-display, none);
position: absolute;
inset: 18%;
border-radius: 50%;
background: rgba(255, 255, 255, 0.03);
backdrop-filter: blur(8px);
border: 1px solid rgba(255, 255, 255, 0.05);
z-index: 1;
}
/* ── Theme presets ── */
body.theme-neon { --sp-ring-filter: drop-shadow(0 0 14px currentColor) drop-shadow(0 0 4px currentColor); --sp-glow-filter: blur(50px); --stroke: 12; }
body.theme-minimal { --sp-glow-opacity: 0; --sp-ring-stroke: 6; --sp-time-weight: 300; --sp-backdrop-bg: rgba(8, 12, 24, 0.55); --sp-backdrop-bg-edge: rgba(6, 10, 22, 0.7); --sp-ring-filter: none; --sp-tracker-stroke: 2; }
body.theme-glassmorphism { --sp-glass-display: block; }
</style>
</head>
<body>
<div class="timer-container idle" id="container">
<div class="backdrop" id="backdrop"></div>
<div class="glow" id="glow"></div>
<svg class="ring-svg" viewBox="0 0 220 220">
<defs>
<linearGradient id="ringGradient" x1="0%" y1="0%" x2="100%" y2="100%">
<stop offset="0%" id="gradStop1" stop-color="var(--focus-color)" />
<stop offset="100%" id="gradStop2" stop-color="var(--focus-gradient-end)" />
</linearGradient>
<radialGradient id="capGlow" cx="50%" cy="50%" r="50%">
<stop offset="0%" id="capGlowColor" stop-color="#22c55e" stop-opacity="1" />
<stop offset="100%" stop-color="transparent" stop-opacity="0" />
</radialGradient>
</defs>
<!-- 12 tick marks -->
<g class="ticks">
<line class="tick" x1="110" y1="14" x2="110" y2="19" />
<line class="tick" x1="110" y1="14" x2="110" y2="19" transform="rotate(30 110 110)" />
<line class="tick" x1="110" y1="14" x2="110" y2="19" transform="rotate(60 110 110)" />
<line class="tick" x1="110" y1="14" x2="110" y2="19" transform="rotate(90 110 110)" />
<line class="tick" x1="110" y1="14" x2="110" y2="19" transform="rotate(120 110 110)" />
<line class="tick" x1="110" y1="14" x2="110" y2="19" transform="rotate(150 110 110)" />
<line class="tick" x1="110" y1="14" x2="110" y2="19" transform="rotate(180 110 110)" />
<line class="tick" x1="110" y1="14" x2="110" y2="19" transform="rotate(210 110 110)" />
<line class="tick" x1="110" y1="14" x2="110" y2="19" transform="rotate(240 110 110)" />
<line class="tick" x1="110" y1="14" x2="110" y2="19" transform="rotate(270 110 110)" />
<line class="tick" x1="110" y1="14" x2="110" y2="19" transform="rotate(300 110 110)" />
<line class="tick" x1="110" y1="14" x2="110" y2="19" transform="rotate(330 110 110)" />
</g>
<!-- Session tracker (inner segmented ring) -->
<g id="trackerGroup"></g>
<circle class="ring-bg" cx="110" cy="110" r="100"></circle>
<circle class="ring-progress" id="ring" cx="110" cy="110" r="100"></circle>
<!-- Glow cap at leading edge — default at 3 o'clock SVG = 12 o'clock screen -->
<circle class="ring-cap" id="ringCap" cx="210" cy="110" r="12" fill="url(#capGlow)" />
</svg>
<div class="center">
<div class="time" id="time">--:--</div>
<div class="session-label" id="label">Ready</div>
<div class="stats" id="stats"></div>
<div class="next-line" id="nextLine"></div>
<div class="info-line" id="infoLine"></div>
</div>
<div class="bottom-pill" id="bottomPill"></div>
</div>
<script>
const params = new URLSearchParams(window.location.search);
const SHOW_STATS = params.get('showStats') !== 'false';
const SHOW_NEXT = params.get('showNext') !== 'false';
const SHOW_CHAT = params.get('showChat') === 'true';
const SHOW_STATUS = params.get('showStatus') !== 'false';
const CUSTOM_FONT = params.get('font');
let _spThemeApplied = false;
function applySPConfig() {
const style = getComputedStyle(document.body);
const cssTheme = style.getPropertyValue('--sp-theme').trim();
const cssSize = parseInt(style.getPropertyValue('--sp-size')) || 0;
const theme = cssTheme || params.get('theme') || 'default';
const size = cssSize || parseInt(params.get('size')) || 400;
if (theme !== 'default') { document.body.classList.add('theme-' + theme); _spThemeApplied = true; }
if (size !== 400) {
document.documentElement.style.setProperty('--size', size + 'px');
document.body.style.width = size + 'px';
document.body.style.height = size + 'px';
}
return cssTheme !== '';
}
applySPConfig();
(function waitForOBSCustomCSS() {
let attempts = 0;
const timer = setInterval(() => {
attempts++;
if (applySPConfig() || _spThemeApplied || attempts >= 20) clearInterval(timer);
}, 50);
})();
if (CUSTOM_FONT) document.body.style.fontFamily = `'${CUSTOM_FONT}', 'Segoe UI Variable', 'Segoe UI', 'Inter', sans-serif`;
['focus', 'short_break', 'long_break', 'stopwatch', 'countdown'].forEach(key => {
const color = params.get('color_' + key);
if (color) {
const hex = color.startsWith('#') ? color : '#' + color;
document.documentElement.style.setProperty('--' + key.replace('_', '-') + '-color', hex);
}
});
const POLL_INTERVAL = 750;
const CIRCUMFERENCE = 2 * Math.PI * 100;
const RING_RADIUS = 100;
const RING_CX = 110;
const RING_CY = 110;
const TRACKER_RADIUS = 83;
const SVG_NS = 'http://www.w3.org/2000/svg';
const ring = document.getElementById('ring');
const ringCap = document.getElementById('ringCap');
const backdrop = document.getElementById('backdrop');
const gradStop1 = document.getElementById('gradStop1');
const gradStop2 = document.getElementById('gradStop2');
const capGlowColor = document.getElementById('capGlowColor');
const trackerGroup = document.getElementById('trackerGroup');
const timeEl = document.getElementById('time');
const labelEl = document.getElementById('label');
const statsEl = document.getElementById('stats');
const nextLineEl = document.getElementById('nextLine');
const infoLineEl = document.getElementById('infoLine');
const bottomPill = document.getElementById('bottomPill');
const glowEl = document.getElementById('glow');
const container = document.getElementById('container');
ring.style.strokeDasharray = CIRCUMFERENCE;
ring.style.strokeDashoffset = CIRCUMFERENCE;
const RAW_COLORS = {
'Focus': { hex: '#22c55e', glow: 'rgba(34,197,94,0.3)', dim: 'rgba(34,197,94,0.25)' },
'Short Break': { hex: '#3b82f6', glow: 'rgba(59,130,246,0.3)', dim: 'rgba(59,130,246,0.25)' },
'Long Break': { hex: '#a855f7', glow: 'rgba(168,85,247,0.3)', dim: 'rgba(168,85,247,0.25)' },
'Stopwatch': { hex: '#f59e0b', glow: 'rgba(245,158,11,0.3)', dim: 'rgba(245,158,11,0.25)' },
'Countdown': { hex: '#f97316', glow: 'rgba(249,115,22,0.3)', dim: 'rgba(249,115,22,0.25)' },
};
const RAW_OVERTIME = { hex: '#ef4444', glow: 'rgba(239,68,68,0.4)', dim: 'rgba(239,68,68,0.25)' };
const COLORS = {
'Focus': { color: 'var(--focus-color)', glow: 'var(--focus-glow)', grad: ['var(--focus-color)', 'var(--focus-gradient-end)'] },
'Short Break': { color: 'var(--short-break-color)', glow: 'var(--short-break-glow)', grad: ['var(--short-break-color)', 'var(--short-break-gradient-end)'] },
'Long Break': { color: 'var(--long-break-color)', glow: 'var(--long-break-glow)', grad: ['var(--long-break-color)', 'var(--long-break-gradient-end)'] },
'Stopwatch': { color: 'var(--stopwatch-color)', glow: 'var(--stopwatch-glow)', grad: ['var(--stopwatch-color)', 'var(--stopwatch-gradient-end)'] },
'Countdown': { color: 'var(--countdown-color)', glow: 'var(--countdown-glow)', grad: ['var(--countdown-color)', 'var(--countdown-gradient-end)'] },
};
const OVERTIME_PALETTE = { color: 'var(--overtime-color)', glow: 'var(--overtime-glow)', grad: ['var(--overtime-color)', 'var(--overtime-gradient-end)'] };
let lastState = null;
let consecutiveFetchFailures = 0;
let lastTrackerKey = '';
function formatTime(seconds) {
if (seconds < 0) seconds = 0;
const h = Math.floor(seconds / 3600);
const m = Math.floor((seconds % 3600) / 60);
const s = seconds % 60;
if (h > 0) return `${h}:${String(m).padStart(2,'0')}:${String(s).padStart(2,'0')}`;
return `${String(m).padStart(2,'0')}:${String(s).padStart(2,'0')}`;
}
function formatDuration(seconds) {
const mins = Math.floor(seconds / 60);
if (mins < 60) return `${mins}m`;
const h = Math.floor(mins / 60);
const rm = mins % 60;
return rm === 0 ? `${h}h` : `${h}h ${rm}m`;
}
function buildTracker(completed, total, colorHex, dimColor) {
const key = `${completed}-${total}-${colorHex}`;
if (key === lastTrackerKey) return;
lastTrackerKey = key;
while (trackerGroup.firstChild) trackerGroup.removeChild(trackerGroup.firstChild);
if (total <= 0 || total > 30) return;
const circ = 2 * Math.PI * TRACKER_RADIUS;
const gapAngle = total <= 4 ? 8 : total <= 8 ? 5 : 3;
const gap = (gapAngle / 360) * circ;
const segLen = (circ - gap * total) / total;
if (segLen < 2) return;
for (let i = 0; i < total; i++) {
const seg = document.createElementNS(SVG_NS, 'circle');
seg.setAttribute('cx', RING_CX);
seg.setAttribute('cy', RING_CY);
seg.setAttribute('r', TRACKER_RADIUS);
seg.classList.add('tracker-segment');
seg.style.strokeDasharray = `${segLen} ${circ - segLen}`;
seg.style.strokeDashoffset = `${-(i * (segLen + gap))}`;
if (i < completed) {
seg.setAttribute('stroke', colorHex);
seg.style.opacity = '0.55';
seg.style.filter = `drop-shadow(0 0 2px ${dimColor})`;
} else {
seg.setAttribute('stroke', 'rgba(255,255,255,0.06)');
seg.style.opacity = '1';
}
trackerGroup.appendChild(seg);
}
}
// Cap position: calculated in SVG space (before CSS rotation).
// SVG stroke starts at 3 o'clock (0°), CSS rotates -90° to move it
// to 12 o'clock on screen. So we use raw angle without -PI/2 offset.
function updateRingCap(progress, isActive) {
if (!isActive || progress <= 0.008) {
ringCap.classList.remove('active');
return;
}
const angle = progress * 2 * Math.PI;
const cx = RING_CX + RING_RADIUS * Math.cos(angle);
const cy = RING_CY + RING_RADIUS * Math.sin(angle);
ringCap.setAttribute('cx', cx);
ringCap.setAttribute('cy', cy);
ringCap.classList.add('active');
}
function update(state) {
if (!state) {
container.className = 'timer-container idle';
timeEl.textContent = '--:--';
timeEl.classList.remove('overtime');
labelEl.textContent = 'Offline';
statsEl.textContent = '';
infoLineEl.textContent = '';
infoLineEl.classList.remove('visible');
nextLineEl.textContent = '';
nextLineEl.classList.remove('visible');
bottomPill.textContent = '';
bottomPill.classList.remove('visible');
ring.style.strokeDashoffset = CIRCUMFERENCE;
glowEl.classList.remove('active');
updateRingCap(0, false);
lastTrackerKey = '';
while (trackerGroup.firstChild) trackerGroup.removeChild(trackerGroup.firstChild);
backdrop.style.borderColor = 'rgba(255,255,255,0.06)';
backdrop.style.boxShadow = 'inset 0 1px 0 rgba(255,255,255,0.03), inset 0 -2px 8px rgba(0,0,0,0.15)';
timeEl.style.textShadow = '0 2px 20px rgba(0,0,0,0.6)';
return;
}
const { is_running, is_paused, session_type, current_time, total_time,
completed_focus_sessions, goal_sessions, total_focus_seconds,
show_transition, transition_message, timer_mode,
custom_segment_name, custom_segment_index, custom_segment_count,
is_overtime, overtime_seconds, next_session_type, next_session_in,
sessions_remaining, break_suggestion, stream_duration, ends_at,
chat_status_line, status_active, status_message } = state;
const mode = timer_mode || 'pomodoro';
const overtime = is_overtime || false;
let cls = 'timer-container';
if (!is_running) cls += ' idle';
else if (is_paused) cls += ' paused';
if (overtime) cls += ' overtime';
container.className = cls;
if (overtime) {
timeEl.textContent = '+' + formatTime(overtime_seconds || 0);
timeEl.classList.add('overtime');
} else {
timeEl.textContent = formatTime(current_time);
timeEl.classList.remove('overtime');
}
let label = session_type || 'Ready';
if (mode === 'custom' && custom_segment_name) label = custom_segment_name;
else if (mode === 'stopwatch') label = 'Stopwatch';
else if (mode === 'countdown') label = 'Countdown';
if (overtime) label += ' · OT';
else if (is_paused) label += ' · Paused';
if (!is_running) label = 'Ready';
labelEl.textContent = label;
let progress = 0;
if (overtime) { progress = 1; }
else if (mode === 'stopwatch') { progress = (current_time % 3600) / 3600; }
else if (total_time > 0) { progress = (total_time - current_time) / total_time; }
ring.style.strokeDashoffset = CIRCUMFERENCE * (1 - Math.max(0, Math.min(1, progress)));
let palette, raw;
if (overtime) { palette = OVERTIME_PALETTE; raw = RAW_OVERTIME; }
else if (mode === 'stopwatch') { palette = COLORS['Stopwatch']; raw = RAW_COLORS['Stopwatch']; }
else if (mode === 'countdown') { palette = COLORS['Countdown']; raw = RAW_COLORS['Countdown']; }
else { palette = COLORS[session_type] || COLORS['Focus']; raw = RAW_COLORS[session_type] || RAW_COLORS['Focus']; }
ring.style.stroke = is_running ? 'url(#ringGradient)' : 'var(--idle-color)';
gradStop1.setAttribute('stop-color', palette.grad[0]);
gradStop2.setAttribute('stop-color', palette.grad[1]);
capGlowColor.setAttribute('stop-color', raw.hex);
labelEl.style.color = is_running ? palette.color : 'var(--text-secondary)';
if (is_running) {
labelEl.style.textShadow = `0 0 18px ${raw.glow}, 0 1px 8px rgba(0,0,0,0.5)`;
} else {
labelEl.style.textShadow = '0 1px 8px rgba(0,0,0,0.5)';
}
if (is_running && !overtime) {
timeEl.style.textShadow = `0 0 35px ${raw.glow}, 0 2px 20px rgba(0,0,0,0.6)`;
} else if (!overtime) {
timeEl.style.textShadow = '0 2px 20px rgba(0,0,0,0.6)';
}
const r = parseInt(raw.hex.slice(1,3), 16);
const g = parseInt(raw.hex.slice(3,5), 16);
const b = parseInt(raw.hex.slice(5,7), 16);
if (is_running && !is_paused) {
backdrop.style.borderColor = `rgba(${r},${g},${b},0.15)`;
backdrop.style.boxShadow = `inset 0 1px 0 rgba(255,255,255,0.03), inset 0 -2px 8px rgba(0,0,0,0.15), 0 0 20px rgba(${r},${g},${b},0.05)`;
} else {
backdrop.style.borderColor = 'rgba(255,255,255,0.06)';
backdrop.style.boxShadow = 'inset 0 1px 0 rgba(255,255,255,0.03), inset 0 -2px 8px rgba(0,0,0,0.15)';
}
glowEl.style.background = palette.glow;
glowEl.classList.toggle('active', is_running && !is_paused);
updateRingCap(progress, is_running && !is_paused);
if (mode === 'pomodoro' && goal_sessions > 0) {
buildTracker(completed_focus_sessions || 0, goal_sessions, raw.hex, raw.dim);
} else if (mode === 'custom' && custom_segment_count > 0) {
buildTracker(custom_segment_index ? custom_segment_index - 1 : 0, custom_segment_count, raw.hex, raw.dim);
} else if (lastTrackerKey !== '') {
lastTrackerKey = '';
while (trackerGroup.firstChild) trackerGroup.removeChild(trackerGroup.firstChild);
}
// Status takeover: when status is active, replace the label only
const statusActive = SHOW_STATUS && status_active && status_message;
if (statusActive) {
labelEl.textContent = status_message;
labelEl.classList.add('status-active');
} else {
labelEl.classList.remove('status-active');
}
// Stats (always shown, even during status)
if (!SHOW_STATS) {
statsEl.textContent = '';
} else if (mode === 'pomodoro' && (is_running || completed_focus_sessions > 0)) {
let stat = `${completed_focus_sessions}/${goal_sessions}`;
if (total_focus_seconds > 0) stat += ` · ${formatDuration(total_focus_seconds)}`;
statsEl.textContent = stat;
} else if (mode === 'custom' && custom_segment_count > 0) {
statsEl.textContent = `${custom_segment_index || 1}/${custom_segment_count}`;
} else if (mode === 'stopwatch' && total_focus_seconds > 0) {
statsEl.textContent = formatDuration(total_focus_seconds);
} else {
statsEl.textContent = '';
}
// Next-up line (inside center, always shown during running)
if (SHOW_NEXT && is_running && !overtime) {
let nextText = '';
if (next_session_type) nextText = `Next: ${next_session_type}`;
if (ends_at) nextText += nextText ? ` · ${ends_at}` : `Ends ${ends_at}`;
if (nextText) {
nextLineEl.textContent = nextText;
nextLineEl.classList.add('visible');
} else {
nextLineEl.classList.remove('visible');
}
} else {
nextLineEl.classList.remove('visible');
}
// Chat status line
if (SHOW_CHAT && chat_status_line) {
infoLineEl.textContent = chat_status_line;
infoLineEl.classList.add('visible');
} else {
infoLineEl.classList.remove('visible');
}
// Transition messages → bottom pill (brief flash)
if (show_transition && transition_message) {
bottomPill.textContent = transition_message;
bottomPill.classList.add('visible');
} else {
bottomPill.classList.remove('visible');
}
}
async function poll() {
if (pollStopped || pollInFlight) return;
pollInFlight = true;
try {
const resp = await fetch('session_state.json?t=' + Date.now(), { cache: 'no-store' });
if (resp.ok) {
const state = await resp.json();
consecutiveFetchFailures = 0;
lastState = state;
update(state);
} else {
consecutiveFetchFailures += 1;
if (consecutiveFetchFailures >= 2) { lastState = null; update(null); }
else update(lastState);
}
} catch (e) {
consecutiveFetchFailures += 1;
if (consecutiveFetchFailures >= 2) { lastState = null; update(null); }
else update(lastState);
} finally {
pollInFlight = false;
if (!pollStopped) pollTimer = setTimeout(poll, POLL_INTERVAL);
}
}
let pollInFlight = false;
let pollTimer = null;
let pollStopped = false;
window.addEventListener('beforeunload', () => { pollStopped = true; if (pollTimer) clearTimeout(pollTimer); });
poll();
</script>
</body>
</html>