Repository navigation
Expand file tree
/
Copy pathpomodoro-timer.html
More file actions
600 lines (558 loc) Β· 34.4 KB
/
Copy pathpomodoro-timer.html
File metadata and controls
600 lines (558 loc) Β· 34.4 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
<!DOCTYPE html>
<html lang="en">
<head>
<include src="_partials/meta-base.html"></include>
<title>Pomodoro Timer β HTML Tools</title>
<meta name="description" content="A focus timer that cycles work and breaks with configurable durations, a sound alert, a tab-title countdown, and desktop notifications. Runs in your browser β no installs, no tracking.">
<link rel="canonical" href="https://tools.mazipan.space/pomodoro-timer">
<meta property="og:title" content="Pomodoro Timer β HTML Tools">
<meta property="og:description" content="A focus timer that cycles work and breaks with configurable durations, a sound alert, a tab-title countdown, and desktop notifications. Runs in your browser β no installs, no tracking.">
<meta property="og:url" content="https://tools.mazipan.space/pomodoro-timer">
<meta name="twitter:title" content="Pomodoro Timer β HTML Tools">
<meta name="twitter:description" content="A focus timer that cycles work and breaks with configurable durations, a sound alert, a tab-title countdown, and desktop notifications. Runs in your browser β no installs, no tracking.">
<include src="_partials/meta-social.html"></include>
<link rel="icon" type="image/png" sizes="32x32" href="favicon-pomodoro-timer.png">
<include src="_partials/head-fonts.html"></include>
<link rel="stylesheet" href="styles.css">
<style>
/* Phase accent β overridden per phase via [data-phase] on the timer card. */
.timer-card {
--phase-c: var(--accent);
border: 1px solid color-mix(in srgb, var(--phase-c) 35%, transparent);
background: color-mix(in srgb, var(--phase-c) 7%, #0d1117);
border-radius: 0.85rem;
padding: 2rem 1.5rem;
text-align: center;
transition: border-color 0.25s, background-color 0.25s;
}
.timer-card[data-phase="short"] { --phase-c: #10b981; }
.timer-card[data-phase="long"] { --phase-c: #38bdf8; }
/* Phase switch tabs sit at the top of the hero card */
.phase-tabs { display: flex; gap: 0.25rem; justify-content: center; margin-bottom: 1.25rem; }
.countdown {
font-family: 'IBM Plex Mono', ui-monospace, monospace;
font-weight: 700;
font-size: clamp(4rem, 18vw, 7rem);
line-height: 1;
letter-spacing: 0.02em;
color: #f9fafb;
font-variant-numeric: tabular-nums;
transition: opacity 0.2s;
}
.timer-card.is-paused .countdown { opacity: 0.45; }
html[data-theme="light"] .timer-card { background: color-mix(in srgb, var(--phase-c) 8%, #ffffff); }
html[data-theme="light"] .countdown { color: #111827; }
.phase-label {
font-size: 0.7rem;
text-transform: uppercase;
letter-spacing: 0.12em;
color: var(--phase-c);
font-weight: 600;
margin-bottom: 0.5rem;
}
.round-label { margin-top: 0.75rem; font-size: 0.8rem; color: #9ca3af; }
.timer-controls { display: flex; flex-wrap: wrap; gap: 0.5rem; justify-content: center; margin-top: 1.75rem; }
/* Settings rows */
.setting-row {
display: flex; align-items: center; justify-content: space-between;
gap: 1rem; padding: 0.5rem 0;
}
.setting-row > span { font-size: 0.85rem; color: #d1d5db; }
html[data-theme="light"] .setting-row > span { color: #374151; }
.setting-sep { border: none; border-top: 1px solid #1f2937; margin: 0.5rem 0; }
html[data-theme="light"] .setting-sep { border-top-color: #e5e7eb; }
.today-stat {
margin-top: 0.5rem; text-align: center;
font-size: 0.85rem; color: #9ca3af;
}
.today-stat b { color: var(--accent); font-size: 1.05rem; }
</style>
<include src="_partials/head-theme.html"></include>
<!-- BEGIN:json-ld generated by scripts/generate-sections.mjs β re-run after editing tools.json -->
<script type="application/ld+json">{"@context":"https://schema.org","@type":"WebApplication","name":"Pomodoro Timer","url":"https://tools.mazipan.space/pomodoro-timer","description":"A Pomodoro focus timer that cycles work sessions and breaks β set your own focus / short / long durations, get a sound chime and desktop notification when each phase ends, and watch the countdown live in the tab title. Settings persist in your browser. Runs in your browser β no installs, no servers, no tracking.","applicationCategory":"DeveloperApplication","operatingSystem":"Any","browserRequirements":"Requires JavaScript","offers":{"@type":"Offer","price":"0","priceCurrency":"USD"},"isPartOf":{"@type":"WebSite","name":"HTML Tools","url":"https://tools.mazipan.space/"}}</script>
<script type="application/ld+json">{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"HTML Tools","item":"https://tools.mazipan.space/"},{"@type":"ListItem","position":2,"name":"Pomodoro Timer","item":"https://tools.mazipan.space/pomodoro-timer"}]}</script>
<script type="application/ld+json">{"@context":"https://schema.org","@type":"FAQPage","mainEntity":[{"@type":"Question","name":"What is the Pomodoro Technique?","acceptedAnswer":{"@type":"Answer","text":"It's a time-management method: work in focused intervals (classically 25 minutes) separated by short 5-minute breaks, with a longer break after every 4 rounds. This timer automates that cycle so you just press Start and follow the rhythm."}},{"@type":"Question","name":"Does the timer keep accurate time in a background tab?","acceptedAnswer":{"@type":"Answer","text":"Yes. It anchors each phase to an absolute end time rather than counting interval ticks, so browser throttling on inactive tabs won't make it drift. The remaining time also shows in the tab title, so you can glance at it without switching back."}},{"@type":"Question","name":"Why didn't I get a desktop notification?","acceptedAnswer":{"@type":"Answer","text":"Desktop notifications need permission and a supported browser. Toggle them on and accept the prompt; if you previously blocked them you'll need to re-enable them in your browser's site settings. When notifications aren't available, the timer falls back to the sound chime and the tab-title countdown."}},{"@type":"Question","name":"Why is there no sound when a phase ends?","acceptedAnswer":{"@type":"Answer","text":"Browsers block audio until you interact with the page, so press Start at least once to let the timer initialise its audio. Also check that the π Sound toggle is on and your device isn't muted."}},{"@type":"Question","name":"Are my settings saved? Does anything leave my browser?","acceptedAnswer":{"@type":"Answer","text":"Your durations and toggles are stored in your browser's localStorage and restored when you come back. Nothing is uploaded β the page is a single static HTML file with no servers and no tracking."}}]}</script>
<!-- END:json-ld -->
</head>
<body class="bg-gray-950 text-gray-200 min-h-screen flex flex-col">
<header class="border-b border-gray-800 px-6 py-4">
<nav aria-label="Breadcrumb" class="max-w-[900px] mx-auto flex items-center gap-3">
<a href="index.html" class="no-underline text-white font-bold text-lg tracking-tight hover:text-blue-400 transition-colors">HTML Tools</a>
<span class="text-gray-700">/</span>
<span class="text-gray-400 text-sm flex items-center gap-1.5" aria-current="page">π
Pomodoro Timer</span>
</nav>
</header>
<main class="max-w-[900px] mx-auto w-full flex-1 py-8 px-6">
<header class="mb-7">
<h1 class="text-3xl font-bold text-white flex items-center gap-3">π
Pomodoro Timer</h1>
<p class="mt-1.5 text-sm text-gray-500">Work in focused intervals with automatic breaks β configurable durations, sound and desktop alerts, and a live countdown in the tab title.</p>
</header>
<div class="grid gap-6 md:grid-cols-[1.4fr_1fr] items-start">
<!-- ββ Timer hero ββββββββββββββββββββββββββββββββββββββββββββ -->
<section class="timer-card is-paused" id="timer-card" data-phase="focus" aria-label="Timer">
<div class="phase-tabs" role="tablist" aria-label="Phase">
<button class="tab-btn tab-btn-active" role="tab" data-phase="focus" onclick="selectPhase('focus')">Focus</button>
<button class="tab-btn" role="tab" data-phase="short" onclick="selectPhase('short')">Short break</button>
<button class="tab-btn" role="tab" data-phase="long" onclick="selectPhase('long')">Long break</button>
</div>
<div class="phase-label" id="phase-label">Focus</div>
<div class="countdown" id="countdown" role="timer" aria-live="off">25:00</div>
<div class="round-label" id="round-label">Round 1 of 4</div>
<div class="timer-controls">
<button class="btn btn-primary" id="btn-start" onclick="startTimer()">βΆοΈ Start</button>
<button class="btn btn-secondary hidden" id="btn-pause" onclick="pauseTimer()">βΈοΈ Pause</button>
<button class="btn btn-secondary" id="btn-reset" onclick="resetTimer()">β©οΈ Reset</button>
<button class="btn btn-secondary" id="btn-skip" onclick="skipPhase()">βοΈ Skip</button>
</div>
</section>
<!-- ββ Settings ββββββββββββββββββββββββββββββββββββββββββββββ -->
<section class="card p-5" aria-label="Settings">
<h2 class="text-xs font-semibold text-gray-500 uppercase tracking-wide mb-2">Durations</h2>
<div class="setting-row">
<span>Focus length</span>
<span class="flex items-center gap-1.5">
<input class="num-input" type="number" id="dur-focus" min="1" max="180" value="25" inputmode="numeric"> <span class="text-xs text-gray-500">min</span>
</span>
</div>
<div class="setting-row">
<span>Short break</span>
<span class="flex items-center gap-1.5">
<input class="num-input" type="number" id="dur-short" min="1" max="60" value="5" inputmode="numeric"> <span class="text-xs text-gray-500">min</span>
</span>
</div>
<div class="setting-row">
<span>Long break</span>
<span class="flex items-center gap-1.5">
<input class="num-input" type="number" id="dur-long" min="1" max="120" value="15" inputmode="numeric"> <span class="text-xs text-gray-500">min</span>
</span>
</div>
<div class="setting-row">
<span>Rounds before long break</span>
<input class="num-input" type="number" id="rounds" min="1" max="12" value="4" inputmode="numeric" style="width:6ch">
</div>
<hr class="setting-sep">
<h2 class="text-xs font-semibold text-gray-500 uppercase tracking-wide mb-2">Alerts</h2>
<div class="setting-row">
<label class="switch"><input type="checkbox" id="opt-sound" checked><span>π Sound</span></label>
</div>
<div class="setting-row">
<label class="switch"><input type="checkbox" id="opt-notify"><span>π₯οΈ Desktop notifications</span></label>
</div>
<div class="setting-row">
<label class="switch"><input type="checkbox" id="opt-autostart" checked><span>βΆοΈ Auto-start next phase</span></label>
</div>
<p id="notify-hint" class="text-[0.7rem] text-gray-600 leading-snug mt-1 hidden"></p>
<hr class="setting-sep">
<div class="today-stat">Pomodoros completed today: <b id="today-count">0</b></div>
</section>
</div>
</main>
<include src="_partials/footer-script.html"></include>
<!-- BEGIN:faq generated by scripts/generate-sections.mjs β re-run after editing tools.json -->
<section class="max-w-[900px] mx-auto w-full px-6 py-8 border-t border-gray-800">
<h2 class="text-xl font-bold text-white mb-6">FAQ</h2>
<div class="space-y-2">
<details class="disclosure">
<summary>What is the Pomodoro Technique?</summary>
<div class="disclosure-content"><div class="disclosure-body">It's a time-management method: work in focused intervals (classically 25 minutes) separated by short 5-minute breaks, with a longer break after every 4 rounds. This timer automates that cycle so you just press Start and follow the rhythm.</div></div>
</details>
<details class="disclosure">
<summary>Does the timer keep accurate time in a background tab?</summary>
<div class="disclosure-content"><div class="disclosure-body">Yes. It anchors each phase to an absolute end time rather than counting interval ticks, so browser throttling on inactive tabs won't make it drift. The remaining time also shows in the tab title, so you can glance at it without switching back.</div></div>
</details>
<details class="disclosure">
<summary>Why didn't I get a desktop notification?</summary>
<div class="disclosure-content"><div class="disclosure-body">Desktop notifications need permission and a supported browser. Toggle them on and accept the prompt; if you previously blocked them you'll need to re-enable them in your browser's site settings. When notifications aren't available, the timer falls back to the sound chime and the tab-title countdown.</div></div>
</details>
<details class="disclosure">
<summary>Why is there no sound when a phase ends?</summary>
<div class="disclosure-content"><div class="disclosure-body">Browsers block audio until you interact with the page, so press Start at least once to let the timer initialise its audio. Also check that the π Sound toggle is on and your device isn't muted.</div></div>
</details>
<details class="disclosure">
<summary>Are my settings saved? Does anything leave my browser?</summary>
<div class="disclosure-content"><div class="disclosure-body">Your durations and toggles are stored in your browser's localStorage and restored when you come back. Nothing is uploaded β the page is a single static HTML file with no servers and no tracking.</div></div>
</details>
</div>
</section>
<!-- END:faq -->
<!-- BEGIN:more-tools generated by scripts/generate-sections.mjs β re-run after editing tools.json -->
<section class="max-w-[900px] mx-auto w-full px-6 py-8 border-t border-gray-800">
<h2 class="text-xl font-bold text-white mb-6">More tools</h2>
<div class="space-y-4">
<div>
<h3 class="text-xs font-semibold uppercase tracking-wider text-gray-500 mb-2">JSON</h3>
<div class="flex flex-wrap gap-x-5 gap-y-2">
<a href="/json-formatter" class="text-sm text-gray-300 hover:text-blue-400 transition-colors no-underline">ποΈ JSON Formatter</a>
<a href="/json-to-ts" class="text-sm text-gray-300 hover:text-blue-400 transition-colors no-underline">π· JSON to TypeScript</a>
<a href="/json-diff" class="text-sm text-gray-300 hover:text-blue-400 transition-colors no-underline">π JSON Diff</a>
<a href="/json-sort" class="text-sm text-gray-300 hover:text-blue-400 transition-colors no-underline">π€ JSON Sort</a>
<a href="/csv-to-json" class="text-sm text-gray-300 hover:text-blue-400 transition-colors no-underline">π JSON β CSV</a>
<a href="/json-to-yaml" class="text-sm text-gray-300 hover:text-blue-400 transition-colors no-underline">π JSON β YAML</a>
<a href="/json-to-schema" class="text-sm text-gray-300 hover:text-blue-400 transition-colors no-underline">π‘οΈ JSON to Validator Schema</a>
</div>
</div>
<div>
<h3 class="text-xs font-semibold uppercase tracking-wider text-gray-500 mb-2">Code</h3>
<div class="flex flex-wrap gap-x-5 gap-y-2">
<a href="/regex-tester" class="text-sm text-gray-300 hover:text-blue-400 transition-colors no-underline">π§ͺ Regex Tester</a>
<a href="/svg-to-jsx" class="text-sm text-gray-300 hover:text-blue-400 transition-colors no-underline">βοΈ SVG to JSX</a>
<a href="/svg-rasterizer" class="text-sm text-gray-300 hover:text-blue-400 transition-colors no-underline">π· SVG to Raster</a>
<a href="/cron-decoder" class="text-sm text-gray-300 hover:text-blue-400 transition-colors no-underline">β±οΈ Cron Decoder</a>
<a href="/snippet-to-image" class="text-sm text-gray-300 hover:text-blue-400 transition-colors no-underline">πΈ Code Snippet to Image</a>
<a href="/text-diff" class="text-sm text-gray-300 hover:text-blue-400 transition-colors no-underline">π Text Diff</a>
<a href="/markdown-preview" class="text-sm text-gray-300 hover:text-blue-400 transition-colors no-underline">π Markdown Preview</a>
<a href="/semver-checker" class="text-sm text-gray-300 hover:text-blue-400 transition-colors no-underline">π·οΈ SemVer Checker</a>
<a href="/jwt-decoder" class="text-sm text-gray-300 hover:text-blue-400 transition-colors no-underline">π JWT Decoder</a>
</div>
</div>
<div>
<h3 class="text-xs font-semibold uppercase tracking-wider text-gray-500 mb-2">Ornaments</h3>
<div class="flex flex-wrap gap-x-5 gap-y-2">
<a href="/gradients" class="text-sm text-gray-300 hover:text-blue-400 transition-colors no-underline">π¨ Gradients</a>
<a href="/blob" class="text-sm text-gray-300 hover:text-blue-400 transition-colors no-underline">π«§ Blob Generator</a>
<a href="/waves" class="text-sm text-gray-300 hover:text-blue-400 transition-colors no-underline">γ°οΈ Wave Generator</a>
</div>
</div>
<div>
<h3 class="text-xs font-semibold uppercase tracking-wider text-gray-500 mb-2">Image</h3>
<div class="flex flex-wrap gap-x-5 gap-y-2">
<a href="/image-compressor" class="text-sm text-gray-300 hover:text-blue-400 transition-colors no-underline">ποΈ Image Compressor</a>
<a href="/image-resizer" class="text-sm text-gray-300 hover:text-blue-400 transition-colors no-underline">π Image Resizer</a>
<a href="/image-cropper" class="text-sm text-gray-300 hover:text-blue-400 transition-colors no-underline">βοΈ Image Cropper</a>
<a href="/image-converter" class="text-sm text-gray-300 hover:text-blue-400 transition-colors no-underline">πΌοΈ Image Format Converter</a>
<a href="/image-watermark" class="text-sm text-gray-300 hover:text-blue-400 transition-colors no-underline">π Image Watermark</a>
</div>
</div>
<div>
<h3 class="text-xs font-semibold uppercase tracking-wider text-gray-500 mb-2">Audio</h3>
<div class="flex flex-wrap gap-x-5 gap-y-2">
<a href="/mp3-tag-editor" class="text-sm text-gray-300 hover:text-blue-400 transition-colors no-underline">π΅ MP3 Tag Editor</a>
</div>
</div>
<div>
<h3 class="text-xs font-semibold uppercase tracking-wider text-gray-500 mb-2">Web / SEO</h3>
<div class="flex flex-wrap gap-x-5 gap-y-2">
<a href="/meta-tag-preview" class="text-sm text-gray-300 hover:text-blue-400 transition-colors no-underline">π Meta Tag Preview</a>
<a href="/user-agent-parser" class="text-sm text-gray-300 hover:text-blue-400 transition-colors no-underline">π΅οΈ User Agent Parser</a>
<a href="/og-image-builder" class="text-sm text-gray-300 hover:text-blue-400 transition-colors no-underline">πΌοΈ OG Image Builder</a>
</div>
</div>
<div>
<h3 class="text-xs font-semibold uppercase tracking-wider text-gray-500 mb-2">Generators</h3>
<div class="flex flex-wrap gap-x-5 gap-y-2">
<a href="/qr-code-generator" class="text-sm text-gray-300 hover:text-blue-400 transition-colors no-underline">π± QR Code Generator</a>
<a href="/lorem-ipsum" class="text-sm text-gray-300 hover:text-blue-400 transition-colors no-underline">π Lorem Ipsum Generator</a>
<a href="/avatar-generator" class="text-sm text-gray-300 hover:text-blue-400 transition-colors no-underline">π€ Avatar Generator</a>
<a href="/favicon-generator" class="text-sm text-gray-300 hover:text-blue-400 transition-colors no-underline">β Favicon Generator</a>
<a href="/uuid-generator" class="text-sm text-gray-300 hover:text-blue-400 transition-colors no-underline">πͺͺ UUID Generator</a>
<a href="/wheel-of-names" class="text-sm text-gray-300 hover:text-blue-400 transition-colors no-underline">π‘ Wheel of Names</a>
</div>
</div>
<div>
<h3 class="text-xs font-semibold uppercase tracking-wider text-gray-500 mb-2">PDF</h3>
<div class="flex flex-wrap gap-x-5 gap-y-2">
<a href="/pdf-merger" class="text-sm text-gray-300 hover:text-blue-400 transition-colors no-underline">π PDF Merger</a>
<a href="/image-to-pdf" class="text-sm text-gray-300 hover:text-blue-400 transition-colors no-underline">π Image to PDF</a>
<a href="/pdf-compressor" class="text-sm text-gray-300 hover:text-blue-400 transition-colors no-underline">π€ PDF Compressor</a>
<a href="/pdf-splitter" class="text-sm text-gray-300 hover:text-blue-400 transition-colors no-underline">βοΈ PDF Splitter</a>
<a href="/pdf-page-manager" class="text-sm text-gray-300 hover:text-blue-400 transition-colors no-underline">ποΈ PDF Page Manager</a>
<a href="/pdf-watermark" class="text-sm text-gray-300 hover:text-blue-400 transition-colors no-underline">π§ PDF Watermark</a>
<a href="/pdf-signature" class="text-sm text-gray-300 hover:text-blue-400 transition-colors no-underline">βοΈ PDF Signature</a>
<a href="/pdf-to-image" class="text-sm text-gray-300 hover:text-blue-400 transition-colors no-underline">πΌοΈ PDF to Image</a>
</div>
</div>
</div>
</section>
<!-- END:more-tools -->
<footer class="max-w-[900px] mx-auto w-full py-8 px-6 border-t border-gray-800 text-center text-sm text-gray-600">
<div>© <span id="year"></span> <a href="https://mazipan.space" rel="noreferrer noopener" target="_blank" class="text-blue-400 transition-colors">Irfan Maulana</a> & Claude</div>
<div><span id="deploy-time"></span></div>
<div><span id="commit-sha"></span><a href="https://github.com/mazipan/html-tools" rel="noreferrer noopener" target="_blank" class="text-blue-400 transition-colors">Source</a></div>
<div><a href="design-system.html" rel="nofollow" class="text-blue-400 transition-colors">Design system</a></div>
<div><a href="https://baca-quran.id" rel="noreferrer noopener" target="_blank" class="text-blue-400 transition-colors">Baca Quran</a> Β· <a href="https://games.mazipan.space" rel="noreferrer noopener" target="_blank" class="text-blue-400 transition-colors">Games</a></div>
</footer>
<script>
'use strict';
const SETTINGS_KEY = 'pomodoro-timer:settings';
const STATS_KEY = 'pomodoro-timer:stats';
const PHASE_NAMES = { focus: 'Focus', short: 'Short break', long: 'Long break' };
// ββ DOM ββββββββββββββββββββββββββββββββββββββββββββββββββββββ
const el = {
card: document.getElementById('timer-card'),
countdown: document.getElementById('countdown'),
phaseLabel: document.getElementById('phase-label'),
roundLabel: document.getElementById('round-label'),
start: document.getElementById('btn-start'),
pause: document.getElementById('btn-pause'),
durFocus: document.getElementById('dur-focus'),
durShort: document.getElementById('dur-short'),
durLong: document.getElementById('dur-long'),
rounds: document.getElementById('rounds'),
optSound: document.getElementById('opt-sound'),
optNotify: document.getElementById('opt-notify'),
optAutostart: document.getElementById('opt-autostart'),
notifyHint: document.getElementById('notify-hint'),
todayCount: document.getElementById('today-count'),
tabs: Array.from(document.querySelectorAll('.phase-tabs .tab-btn')),
};
const baseTitle = document.title;
// ββ State ββββββββββββββββββββββββββββββββββββββββββββββββββββ
let phase = 'focus'; // current phase
let remaining = 0; // ms left in current phase
let deadline = 0; // absolute end timestamp while running
let running = false;
let completedFocus = 0; // focus sessions finished in the current set (0..rounds)
let ticker = null;
let audioCtx = null;
// ββ Settings persistence βββββββββββββββββββββββββββββββββββββ
function clampInt(input, def) {
const min = Number(input.min), max = Number(input.max);
let v = parseInt(input.value, 10);
if (!Number.isFinite(v)) v = def;
v = Math.min(max, Math.max(min, v));
input.value = String(v);
return v;
}
function settings() {
return {
focus: clampInt(el.durFocus, 25),
short: clampInt(el.durShort, 5),
long: clampInt(el.durLong, 15),
rounds: clampInt(el.rounds, 4),
};
}
function phaseMinutes(p) {
const s = settings();
return p === 'focus' ? s.focus : p === 'short' ? s.short : s.long;
}
function saveSettings() {
const s = settings();
try {
localStorage.setItem(SETTINGS_KEY, JSON.stringify({
...s,
sound: el.optSound.checked,
notify: el.optNotify.checked,
autostart: el.optAutostart.checked,
}));
} catch {}
}
function loadSettings() {
let s;
try { s = JSON.parse(localStorage.getItem(SETTINGS_KEY) || 'null'); } catch {}
if (!s) return;
if (s.focus) el.durFocus.value = s.focus;
if (s.short) el.durShort.value = s.short;
if (s.long) el.durLong.value = s.long;
if (s.rounds) el.rounds.value = s.rounds;
if (typeof s.sound === 'boolean') el.optSound.checked = s.sound;
if (typeof s.notify === 'boolean') el.optNotify.checked = s.notify;
if (typeof s.autostart === 'boolean') el.optAutostart.checked = s.autostart;
}
// ββ Today counter (resets on date change) ββββββββββββββββββββ
function todayKey() { return new Date().toLocaleDateString('en-CA'); } // YYYY-MM-DD, local
function loadStats() {
let s;
try { s = JSON.parse(localStorage.getItem(STATS_KEY) || 'null'); } catch {}
if (s && s.date === todayKey()) return s.count || 0;
return 0;
}
function bumpToday() {
const count = loadStats() + 1;
try { localStorage.setItem(STATS_KEY, JSON.stringify({ date: todayKey(), count })); } catch {}
el.todayCount.textContent = String(count);
}
// ββ Rendering ββββββββββββββββββββββββββββββββββββββββββββββββ
function fmt(ms) {
const total = Math.max(0, Math.ceil(ms / 1000));
const m = Math.floor(total / 60), s = total % 60;
return String(m).padStart(2, '0') + ':' + String(s).padStart(2, '0');
}
function render() {
const text = fmt(remaining);
el.countdown.textContent = text;
el.card.dataset.phase = phase;
el.phaseLabel.textContent = PHASE_NAMES[phase];
el.card.classList.toggle('is-paused', !running);
el.start.classList.toggle('hidden', running);
el.pause.classList.toggle('hidden', !running);
el.start.textContent = remaining < phaseMinutes(phase) * 60000 ? 'βΆοΈ Resume' : 'βΆοΈ Start';
const total = settings().rounds;
if (phase === 'focus') {
el.roundLabel.textContent = `Round ${(completedFocus % total) + 1} of ${total}`;
} else if (phase === 'long') {
el.roundLabel.textContent = 'Long break β nice work';
} else {
el.roundLabel.textContent = `Break β ${total - (completedFocus % total || total)} round(s) to long break`;
}
document.title = running ? `${text} ${PHASE_NAMES[phase]} Β· π
` : baseTitle;
}
// ββ Timer controls βββββββββββββββββββββββββββββββββββββββββββ
function setPhase(p, autoStart) {
phase = p;
remaining = phaseMinutes(p) * 60000;
running = false;
el.tabs.forEach(t => t.classList.toggle('tab-btn-active', t.dataset.phase === p));
render();
if (autoStart) startTimer();
}
function selectPhase(p) {
stopTicker();
setPhase(p, false);
}
function startTimer() {
if (running) return;
if (remaining <= 0) remaining = phaseMinutes(phase) * 60000;
primeAudio();
deadline = Date.now() + remaining;
running = true;
stopTicker();
ticker = setInterval(tick, 250);
render();
}
function pauseTimer() {
if (!running) return;
remaining = Math.max(0, deadline - Date.now());
running = false;
stopTicker();
render();
}
function resetTimer() {
stopTicker();
running = false;
remaining = phaseMinutes(phase) * 60000;
render();
}
function skipPhase() {
stopTicker();
advance(false); // treat as skipped β don't count as a completed focus
}
function stopTicker() {
if (ticker) { clearInterval(ticker); ticker = null; }
}
function tick() {
remaining = Math.max(0, deadline - Date.now());
if (remaining <= 0) {
stopTicker();
running = false;
phaseComplete();
return;
}
render();
}
// ββ Phase transition βββββββββββββββββββββββββββββββββββββββββ
// Which phase follows, given how many focus sessions are done in the set.
function phaseAfterFocus(focusDone) {
return (focusDone % settings().rounds === 0) ? 'long' : 'short';
}
// The upcoming phase, projecting the focus that's currently ending (used by the notification).
function nextPhase() {
if (phase !== 'focus') return 'focus';
return phaseAfterFocus(completedFocus + 1);
}
function phaseComplete() {
alertPhaseEnd();
advance(true);
}
function advance(counted) {
const leavingFocus = phase === 'focus';
if (leavingFocus) {
// Advance the cycle position whether the focus completed or was skipped,
// so the workβbreak rhythm stays consistent. Only a real completion counts
// toward today's tally.
completedFocus += 1;
if (counted) bumpToday();
}
const next = leavingFocus ? phaseAfterFocus(completedFocus) : 'focus';
if (phase === 'long') completedFocus = 0; // start a fresh set after the long break
setPhase(next, el.optAutostart.checked);
}
// ββ Alerts βββββββββββββββββββββββββββββββββββββββββββββββββββ
function primeAudio() {
if (!el.optSound.checked) return;
try {
audioCtx = audioCtx || new (window.AudioContext || window.webkitAudioContext)();
if (audioCtx.state === 'suspended') audioCtx.resume();
} catch {}
}
function beep() {
if (!el.optSound.checked || !audioCtx) return;
try {
const now = audioCtx.currentTime;
[880, 660, 990].forEach((freq, i) => {
const osc = audioCtx.createOscillator();
const gain = audioCtx.createGain();
osc.type = 'sine';
osc.frequency.value = freq;
const t = now + i * 0.18;
gain.gain.setValueAtTime(0.0001, t);
gain.gain.exponentialRampToValueAtTime(0.25, t + 0.02);
gain.gain.exponentialRampToValueAtTime(0.0001, t + 0.16);
osc.connect(gain).connect(audioCtx.destination);
osc.start(t);
osc.stop(t + 0.17);
});
} catch {}
}
function notify() {
if (!el.optNotify.checked || !('Notification' in window) || Notification.permission !== 'granted') return;
const done = PHASE_NAMES[phase];
const next = PHASE_NAMES[nextPhase()];
try {
new Notification(`${done} complete π
`, {
body: `Time for ${next}.`,
icon: 'favicon-pomodoro-timer.png',
tag: 'pomodoro-timer',
});
} catch {}
}
function alertPhaseEnd() { beep(); notify(); }
// ββ Notification permission flow βββββββββββββββββββββββββββββ
function setNotifyHint(msg) {
el.notifyHint.textContent = msg || '';
el.notifyHint.classList.toggle('hidden', !msg);
}
function onNotifyToggle() {
if (!el.optNotify.checked) { setNotifyHint(''); saveSettings(); return; }
if (!('Notification' in window)) {
el.optNotify.checked = false;
setNotifyHint('This browser does not support desktop notifications.');
return;
}
if (Notification.permission === 'granted') { setNotifyHint(''); }
else if (Notification.permission === 'denied') {
el.optNotify.checked = false;
setNotifyHint('Notifications are blocked in your browser settings. Re-enable them for this site to use this.');
} else {
Notification.requestPermission().then(perm => {
if (perm !== 'granted') {
el.optNotify.checked = false;
setNotifyHint('Permission not granted β falling back to the sound alert.');
} else {
setNotifyHint('');
}
saveSettings();
});
return;
}
saveSettings();
}
// ββ Wiring βββββββββββββββββββββββββββββββββββββββββββββββββββ
[el.durFocus, el.durShort, el.durLong, el.rounds].forEach(input => {
input.addEventListener('change', () => {
saveSettings();
if (!running) { remaining = phaseMinutes(phase) * 60000; }
render();
});
});
el.optSound.addEventListener('change', () => { if (el.optSound.checked) primeAudio(); saveSettings(); });
el.optAutostart.addEventListener('change', saveSettings);
el.optNotify.addEventListener('change', onNotifyToggle);
// Keep the title fresh when returning to a backgrounded tab
document.addEventListener('visibilitychange', () => { if (!document.hidden && running) { tick(); } });
// ββ Init βββββββββββββββββββββββββββββββββββββββββββββββββββββ
loadSettings();
el.todayCount.textContent = String(loadStats());
setPhase('focus', false);
</script>
</body>
</html>