-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtimer_overlay_bar.html
More file actions
456 lines (411 loc) · 14.9 KB
/
timer_overlay_bar.html
File metadata and controls
456 lines (411 loc) · 14.9 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>SessionPulse — Bar Overlay</title>
<style>
:root {
/* Shared with ring overlay — user can set once for both */
--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;
/* Bar-specific */
--bar-height: var(--sp-bar-height, 48px);
--bar-bg: var(--sp-bar-bg, rgba(6, 10, 22, 0.82));
--bar-progress-h: var(--sp-bar-progress-height, 6px);
--text-primary: #f1f5f9;
--text-secondary: rgba(241, 245, 249, 0.85);
--text-muted: rgba(241, 245, 249, 0.7);
}
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
background: transparent;
font-family: 'Segoe UI Variable', 'Segoe UI', 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
overflow: hidden;
}
/* ── Bar container ── */
.bar-container {
position: fixed;
width: 100%;
height: var(--bar-height);
background: var(--bar-bg);
backdrop-filter: blur(var(--sp-bar-blur, 18px));
-webkit-backdrop-filter: blur(var(--sp-bar-blur, 18px));
display: flex;
align-items: center;
padding: 0 24px;
gap: 14px;
opacity: 0;
transform: translateY(-100%);
transition: opacity 0.4s ease, transform 0.4s cubic-bezier(0.16, 1, 0.3, 1),
border-color 0.6s ease, box-shadow 0.6s ease;
border-bottom: 2px solid transparent;
}
.bar-container.visible {
opacity: 1;
transform: translateY(0);
}
/* Position variants */
.bar-container.top { top: 0; }
.bar-container.bottom {
top: auto;
bottom: 0;
transform: translateY(100%);
border-bottom: none;
border-top: 2px solid transparent;
}
.bar-container.bottom.visible { transform: translateY(0); }
/* ── Session icon ── */
.session-icon {
font-size: 1rem;
width: 30px;
height: 30px;
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
flex-shrink: 0;
transition: background 0.4s ease, box-shadow 0.4s ease;
}
/* ── Session label ── */
.session-label {
font-size: var(--sp-bar-label-size, 0.88rem);
font-weight: 700;
text-transform: uppercase;
letter-spacing: 2px;
color: var(--text-secondary);
white-space: nowrap;
min-width: 50px;
text-shadow: 0 1px 6px rgba(0, 0, 0, 0.4);
transition: color 0.4s ease, text-shadow 0.4s ease;
}
/* Status takeover on label */
.session-label.status-active {
color: var(--sp-status-color, #f59e0b);
text-shadow: 0 0 10px rgba(245, 158, 11, 0.3);
text-transform: none;
letter-spacing: 0.8px;
animation: pulse-status 2.5s ease-in-out infinite;
}
@keyframes pulse-status {
0%, 100% { opacity: 1; }
50% { opacity: 0.6; }
}
/* ── Timer text ── */
.time-text {
font-size: var(--sp-bar-time-size, 1.25rem);
font-weight: 700;
color: var(--text-primary);
font-variant-numeric: tabular-nums;
letter-spacing: -0.5px;
white-space: nowrap;
text-shadow: 0 1px 8px rgba(0, 0, 0, 0.4);
-webkit-text-stroke: 0.3px rgba(255, 255, 255, 0.15);
transition: color 0.3s ease, text-shadow 0.3s ease;
}
.time-text.overtime {
color: var(--overtime-color);
text-shadow: 0 0 14px rgba(239, 68, 68, 0.5);
}
/* ── Progress bar ── */
.progress-track {
flex: 1;
height: var(--bar-progress-h);
background: rgba(255, 255, 255, 0.08);
border-radius: 99px;
overflow: hidden;
min-width: 60px;
}
.progress-fill {
height: 100%;
border-radius: 99px;
width: 0%;
transition: width 0.8s cubic-bezier(0.4, 0, 0.2, 1);
position: relative;
}
/* ── Session counter ── */
.session-counter {
font-size: var(--sp-bar-counter-size, 0.95rem);
font-weight: 700;
color: var(--text-primary);
white-space: nowrap;
letter-spacing: 0.3px;
text-shadow: 0 1px 6px rgba(0, 0, 0, 0.4);
}
/* ── Divider ── */
.bar-divider {
width: 1.5px;
height: 20px;
background: rgba(255, 255, 255, 0.3);
flex-shrink: 0;
border-radius: 1px;
}
/* ── Next-up info ── */
.next-info {
font-size: var(--sp-bar-next-size, 0.92rem);
font-weight: 600;
color: var(--text-secondary);
white-space: nowrap;
letter-spacing: 0.3px;
text-shadow: 0 1px 6px rgba(0, 0, 0, 0.4);
opacity: 0;
transition: opacity 0.4s ease;
}
.next-info.visible { opacity: 1; }
/* ── Paused state ── */
@keyframes pulse-pause {
0%, 100% { opacity: 1; }
50% { opacity: 0.25; }
}
.bar-container.paused .time-text {
animation: pulse-pause 2.2s ease-in-out infinite;
}
.bar-container.paused .session-label {
animation: pulse-pause 2.2s ease-in-out infinite;
}
.bar-container.paused .progress-fill {
opacity: 0.5;
}
/* ── Overtime state ── */
@keyframes pulse-overtime {
0%, 100% { opacity: 1; }
50% { opacity: 0.5; }
}
.bar-container.overtime .progress-track {
animation: pulse-overtime 1.5s ease-in-out infinite;
}
</style>
</head>
<body>
<div class="bar-container top" id="bar">
<div class="session-icon" id="sessionIcon">📚</div>
<div class="session-label" id="sessionLabel">READY</div>
<div class="time-text" id="timeText">--:--</div>
<div class="progress-track">
<div class="progress-fill" id="progressFill"></div>
</div>
<div class="session-counter" id="sessionCounter"></div>
<div class="bar-divider" id="barDivider" style="display:none"></div>
<div class="next-info" id="nextInfo"></div>
</div>
<script>
const POLL_INTERVAL = 750;
const params = new URLSearchParams(window.location.search);
const SHOW_NEXT = params.get('showNext') !== 'false';
const SHOW_STATUS = params.get('showStatus') !== 'false';
const bar = document.getElementById('bar');
const sessionIcon = document.getElementById('sessionIcon');
const sessionLabel = document.getElementById('sessionLabel');
const timeText = document.getElementById('timeText');
const progressFill = document.getElementById('progressFill');
const sessionCounter = document.getElementById('sessionCounter');
const barDivider = document.getElementById('barDivider');
const nextInfo = document.getElementById('nextInfo');
// Position: via CSS var or URL param
function applySPPosition() {
const cssPos = getComputedStyle(document.body).getPropertyValue('--sp-position').trim();
const pos = cssPos || params.get('position') || 'top';
bar.classList.remove('top', 'bottom');
bar.classList.add(pos);
return cssPos !== '';
}
applySPPosition();
(function waitForOBSCustomCSS() {
let attempts = 0;
const timer = setInterval(() => {
attempts++;
if (applySPPosition() || attempts >= 20) clearInterval(timer);
}, 50);
})();
const ICONS = {
'Focus': '📚', 'Short Break': '☕', 'Long Break': '🧘',
'Stopwatch': '⏱️', 'Countdown': '⏳',
};
// Color lookup — resolves CSS variables for inline styles
const COLOR_MAP = {
'Focus': { color: 'var(--focus-color)', glow: 'var(--focus-glow)', grad: 'var(--focus-gradient-end)', rawHex: '#22c55e', rawGlow: 'rgba(34,197,94,0.3)' },
'Short Break': { color: 'var(--short-break-color)', glow: 'var(--short-break-glow)', grad: 'var(--short-break-gradient-end)', rawHex: '#3b82f6', rawGlow: 'rgba(59,130,246,0.3)' },
'Long Break': { color: 'var(--long-break-color)', glow: 'var(--long-break-glow)', grad: 'var(--long-break-gradient-end)', rawHex: '#a855f7', rawGlow: 'rgba(168,85,247,0.3)' },
'Stopwatch': { color: 'var(--stopwatch-color)', glow: 'var(--stopwatch-glow)', grad: 'var(--stopwatch-gradient-end)', rawHex: '#f59e0b', rawGlow: 'rgba(245,158,11,0.3)' },
'Countdown': { color: 'var(--countdown-color)', glow: 'var(--countdown-glow)', grad: 'var(--countdown-gradient-end)', rawHex: '#f97316', rawGlow: 'rgba(249,115,22,0.3)' },
};
const OVERTIME_COLORS = { color: 'var(--overtime-color)', glow: 'var(--overtime-glow)', grad: 'var(--overtime-gradient-end)', rawHex: '#ef4444', rawGlow: 'rgba(239,68,68,0.4)' };
function formatTime(seconds) {
if (seconds == null || seconds < 0) return '--:--';
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) {
if (!seconds) return '';
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 update(state) {
if (!state || !state.is_running) {
bar.classList.remove('visible', 'paused', 'overtime');
return;
}
bar.classList.add('visible');
const { session_type, current_time, total_time, is_paused, timer_mode,
completed_focus_sessions, goal_sessions, total_focus_seconds,
custom_segment_name, custom_segment_index, custom_segment_count,
is_overtime, overtime_seconds, show_transition, transition_message,
next_session_type, ends_at, status_active, status_message } = state;
const mode = timer_mode || 'pomodoro';
const overtime = is_overtime || false;
// Container state classes
bar.classList.toggle('paused', !!is_paused);
bar.classList.toggle('overtime', overtime);
// Session identity
let label = session_type || 'Timer';
let iconText = ICONS[session_type] || '⏱️';
let colors = COLOR_MAP[session_type] || COLOR_MAP['Focus'];
if (mode === 'stopwatch') {
label = 'Stopwatch'; iconText = '⏱️'; colors = COLOR_MAP['Stopwatch'];
} else if (mode === 'countdown') {
label = 'Countdown'; iconText = '⏳'; colors = COLOR_MAP['Countdown'];
} else if (mode === 'custom' && custom_segment_name) {
label = custom_segment_name; iconText = '📋';
}
if (overtime) {
colors = OVERTIME_COLORS;
iconText = '🔥';
}
// Icon
sessionIcon.textContent = iconText;
sessionIcon.style.background = `${colors.rawGlow}`;
sessionIcon.style.boxShadow = `0 0 8px ${colors.rawGlow}`;
// Label — status takeover or session name
const statusActive = SHOW_STATUS && status_active && status_message;
if (statusActive) {
sessionLabel.textContent = status_message;
sessionLabel.classList.add('status-active');
} else {
sessionLabel.classList.remove('status-active');
let displayLabel = label;
if (overtime) displayLabel += ' · OT';
else if (is_paused) displayLabel += ' · Paused';
sessionLabel.textContent = displayLabel.toUpperCase();
sessionLabel.style.color = '';
sessionLabel.style.textShadow = '';
}
// Timer
if (overtime) {
timeText.textContent = '+' + formatTime(overtime_seconds || 0);
timeText.classList.add('overtime');
} else {
timeText.textContent = formatTime(current_time);
timeText.classList.remove('overtime');
}
// Progress
let progress = 0;
if (overtime) { progress = 100; }
else if (mode === 'stopwatch') { progress = ((current_time % 3600) / 3600) * 100; }
else if (total_time > 0) { progress = ((total_time - current_time) / total_time) * 100; }
progressFill.style.width = progress + '%';
// Progress gradient + glow
progressFill.style.background = `linear-gradient(90deg, ${colors.color}, ${colors.grad})`;
progressFill.style.boxShadow = `0 0 8px ${colors.rawGlow}, 0 0 3px ${colors.rawGlow}`;
// Session-colored border accent
const pos = bar.classList.contains('bottom') ? 'borderTop' : 'borderBottom';
const otherPos = pos === 'borderTop' ? 'borderBottom' : 'borderTop';
bar.style[pos] = `2px solid ${colors.rawHex}`;
bar.style[otherPos] = 'none';
bar.style.boxShadow = `0 ${pos === 'borderBottom' ? '2' : '-2'}px 12px ${colors.rawGlow}`;
// Session counter
if (mode === 'pomodoro' && goal_sessions > 0) {
let counter = `${completed_focus_sessions || 0}/${goal_sessions}`;
if (total_focus_seconds > 0) counter += ` · ${formatDuration(total_focus_seconds)}`;
sessionCounter.textContent = counter;
} else if (mode === 'custom' && custom_segment_count > 0) {
sessionCounter.textContent = `${custom_segment_index || 1}/${custom_segment_count}`;
} else if (mode === 'stopwatch' && total_focus_seconds > 0) {
sessionCounter.textContent = formatDuration(total_focus_seconds);
} else {
sessionCounter.textContent = '';
}
// Next-up / transition (right side)
if (show_transition && transition_message) {
nextInfo.textContent = transition_message;
nextInfo.style.color = 'var(--text-primary)';
nextInfo.style.fontWeight = '600';
nextInfo.classList.add('visible');
} else if (SHOW_NEXT && !overtime) {
let nextText = '';
if (next_session_type) nextText = `Next: ${next_session_type}`;
if (ends_at) nextText += nextText ? ` · ${ends_at}` : `Ends ${ends_at}`;
if (nextText) {
nextInfo.textContent = nextText;
nextInfo.style.color = '';
nextInfo.style.fontWeight = '';
nextInfo.classList.add('visible');
} else {
nextInfo.classList.remove('visible');
}
} else {
nextInfo.classList.remove('visible');
}
// Divider: show only when both counter and next-info have content
const hasCounter = sessionCounter.textContent !== '';
const hasNext = nextInfo.classList.contains('visible');
barDivider.style.display = (hasCounter && hasNext) ? 'block' : 'none';
}
let lastState = null;
let consecutiveFetchFailures = 0;
let pollInFlight = false;
let pollTimer = null;
let pollStopped = false;
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) {
consecutiveFetchFailures = 0;
lastState = await resp.json();
update(lastState);
} 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);
}
}
window.addEventListener('beforeunload', () => {
pollStopped = true;
if (pollTimer) clearTimeout(pollTimer);
});
poll();
</script>
</body>
</html>