Repository navigation
Expand file tree
/
Copy pathindex.html
More file actions
358 lines (357 loc) · 15.8 KB
/
Copy pathindex.html
File metadata and controls
358 lines (357 loc) · 15.8 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
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />
<title>Focus Timer</title>
<!-- Tabler CSS from CDN -->
<link href="https://cdn.jsdelivr.net/npm/@tabler/core@latest/dist/css/tabler.min.css" rel="stylesheet" />
<link href="https://fonts.googleapis.com/css2?family=Exo+2:ital,wght@0,100..900;1,100..900&display=swap" rel="stylesheet">
<style>
html, body {
height: 100%;
min-height: 100vh;
background: var(--tblr-bg-surface);
font-family: 'Exo 2', 'Inter', 'Segoe UI', Arial, sans-serif !important;
-webkit-tap-highlight-color: transparent;
}
.font-monospace, .card, .btn {
font-family: 'Exo 2', 'Inter', 'Segoe UI', Arial, sans-serif !important;
}
.quick-timers .btn {
font-size: 1rem;
padding: 0.4rem 1rem;
margin: 0.15rem;
min-width: 60px;
}
.quick-timers {
display: flex;
flex-wrap: wrap;
gap: 0.25rem;
justify-content: flex-start;
}
.card-body {
padding: 1.2rem 0.7rem;
}
.container-xl {
padding: 10px;
}
@media (max-width: 767.98px) {
.container-xl {
padding-left: 0.2rem;
padding-right: 0.2rem;
}
.row.mt-5 {
margin-top: 1.2rem !important;
}
.card-body {
padding: 1rem 0.3rem;
}
/* Only stack cards vertically for screens below 576px */
}
@media (max-width: 575.98px) {
.col-12.col-md-8, .col-12.col-md-4 {
max-width: 100%;
flex: 0 0 100%;
}
.card {
margin-bottom: 1.2rem;
}
#currentTime {
font-size: 2rem !important;
}
#timerDisplay {
font-size: 2.7rem !important;
}
}
@media (max-width: 400px) {
#currentTime {
font-size: 1.2rem !important;
}
#timerDisplay {
font-size: 1.7rem !important;
}
.quick-timers .btn {
font-size: 0.85rem;
min-width: 44px;
padding: 0.3rem 0.5rem;
}
}
</style>
</head>
<body>
<!-- Navbar -->
<header>
<nav id="mainNavbar" class="navbar navbar-expand-lg shadow-sm mb-3" style="padding: 0.7rem 1.2rem; transition: background 0.2s, color 0.2s;">
<div class="container-xl d-flex align-items-center gap-2">
<span class="navbar-brand d-flex align-items-center gap-2 mb-0 h1" style="font-size:1.5rem;font-weight:700;">
<span style="display:inline-flex;align-items:center;">
<svg xmlns="http://www.w3.org/2000/svg" width="28" height="28" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" class="icon icon-tabler icons-tabler-outline icon-tabler-stopwatch"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M5 13a7 7 0 1 0 14 0a7 7 0 0 0 -14 0" /><path d="M14.5 10.5l-2.5 2.5" /><path d="M17 8l1 -1" /><path d="M14 3h-4" /></svg>
</span>
Focus Timer
</span>
</div>
</nav>
</header>
<script>
function setNavbarTheme() {
const html = document.documentElement;
const isDark = html.getAttribute('data-bs-theme') === 'dark';
// Use Tabler's default dark background for all cards and navbar
const darkBg = getComputedStyle(document.body).getPropertyValue('--tblr-bg-surface') || '#23272f';
var navbar = document.getElementById('mainNavbar');
if (navbar) {
navbar.style.background = isDark ? darkBg : '#fff';
navbar.style.color = isDark ? '#f8fafc' : '#222';
}
document.documentElement.style.setProperty('--navbar-bg', isDark ? darkBg : '#fff');
document.documentElement.style.setProperty('--navbar-text', isDark ? '#f8fafc' : '#222');
document.documentElement.style.setProperty('--right-card-bg', isDark ? darkBg : '#f8fafc');
document.documentElement.style.setProperty('--right-card-text', isDark ? '#f8fafc' : '#23272f');
}
setNavbarTheme();
if (typeof setThemeIcons === 'function') {
const prevSetThemeIcons = setThemeIcons;
setThemeIcons = function() {
prevSetThemeIcons();
setNavbarTheme();
}
}
</script>
<!-- End Navbar -->
<div class="page" style="min-height:100vh;">
<div class="page-main">
<div class="container-xl">
<div class="row mt-5">
<!-- Left Card: 8 columns -->
<div class="col-12 col-md-8">
<div class="card h-100">
<div class="card-body d-flex flex-column align-items-center justify-content-center position-relative" style="min-height: 300px;">
<!-- Move clock to top-left of main widget -->
<div id="topLeftClock" style="position: absolute; top: 12px; left: 18px; z-index: 10; display: flex; flex-direction: column; align-items: flex-start; gap: 0.1rem;">
<span id="currentTime" class="font-monospace" style="font-size:1.25rem;font-weight:600;"></span>
<span id="currentDate" class="font-monospace text-muted" style="font-size:0.95rem;"></span>
</div>
<div>
<span id="timerDisplay" class="font-monospace" style="font-size:3.5rem;font-weight:700;"></span>
</div>
<div class="w-100 mt-4">
<div class="progress" style="height: 18px;">
<div id="timerProgress" class="progress-bar bg-primary" role="progressbar" style="width: 0%; transition: width 0.2s;" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100"></div>
</div>
<div class="d-flex justify-content-between mt-1">
<small id="progressStart" class="text-muted"></small>
<small id="progressEnd" class="text-muted"></small>
</div>
</div>
</div>
</div>
</div>
<!-- Right Card: 4 columns -->
<div class="col-12 col-md-4 mt-4 mt-md-0">
<div class="card h-100 shadow-sm" style="background: var(--right-card-bg, #f8fafc); color: var(--right-card-text, #222);">
<div class="card-body">
<div class="mb-3">
<label class="form-label d-flex align-items-center gap-2">
<svg width="20" height="20" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="icon icon-tabler icon-tabler-clock" viewBox="0 0 24 24"><circle cx="12" cy="12" r="9"/><polyline points="12 7 12 12 15 15"/></svg>
Quick Timers
</label>
<div class="quick-timers">
<button class="btn btn-outline-primary">10s</button>
<button class="btn btn-outline-primary">1m</button>
<button class="btn btn-outline-primary">5m</button>
<button class="btn btn-outline-primary">10m</button>
<button class="btn btn-outline-primary">15m</button>
<button class="btn btn-outline-primary">30m</button>
<button class="btn btn-outline-primary">1h</button>
</div>
</div>
<div class="mb-3">
<label class="form-label d-flex align-items-center gap-2">
<svg width="20" height="20" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="icon icon-tabler icon-tabler-edit" viewBox="0 0 24 24"><path d="M16 3l5 5l-13 13H3v-5L16 3z"/><path d="M16 3l5 5"/></svg>
Custom Timer
</label>
<form id="customTimerForm" class="d-flex gap-2 align-items-end">
<input id="customTimerInput" type="text" class="form-control form-control-sm" placeholder="HH:MM:SS:sss" style="max-width: 140px;" autocomplete="off" />
<button type="submit" class="btn btn-sm btn-primary d-flex align-items-center gap-1"><svg width="16" height="16" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="icon icon-tabler icon-tabler-play" viewBox="0 0 24 24"><polygon points="5 3 19 12 5 21 5 3"/></svg>Start</button>
</form>
<div class="form-text">Format: HH:MM:SS:sss (e.g. 01:05:30:000)</div>
</div>
<div class="mb-2">
<label class="form-label d-flex align-items-center gap-2">
<span id="themeIcon" style="display:inline-flex;align-items:center;">
<svg id="iconDay" width="20" height="20" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="icon icon-tabler icon-tabler-sun" viewBox="0 0 24 24"><circle cx="12" cy="12" r="4"/><path d="M3 12h1m16 0h1M12 3v1m0 16v1M5.6 5.6l.7.7m10.6 10.6l.7.7M18.4 5.6l-.7.7M5.6 18.4l.7-.7"/></svg>
<svg id="iconNight" width="20" height="20" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="icon icon-tabler icon-tabler-moon" viewBox="0 0 24 24" style="display:none;"><path d="M21 12.79A9 9 0 1111.21 3a7 7 0 109.79 9.79z"/></svg>
</span>
Theme
</label>
<div>
<button id="themeToggle" class="btn btn-sm btn-secondary d-flex align-items-center gap-1">
<span id="themeToggleText">Toggle Dark/Light</span>
</button>
</div>
</div>
<!-- More configuration can go here -->
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<script>
// Live clock and date
function pad(num, size = 2) {
let s = "000" + num;
return s.substr(s.length - size);
}
function formatTime(date) {
return (
pad(date.getHours()) +
":" + pad(date.getMinutes()) +
":" + pad(date.getSeconds()) +
":" + pad(date.getMilliseconds(), 3)
);
}
function formatDate(date) {
const days = ['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'];
const months = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'];
return days[date.getDay()] + ', ' + months[date.getMonth()] + ' ' + date.getDate() + ', ' + date.getFullYear();
}
const currentTimeEl = document.getElementById('currentTime');
const currentDateEl = document.getElementById('currentDate');
function updateClock() {
const now = new Date();
currentTimeEl.textContent = formatTime(now);
if (currentDateEl) currentDateEl.textContent = formatDate(now);
requestAnimationFrame(updateClock);
}
updateClock();
// Timer logic
const timerDisplay = document.getElementById('timerDisplay');
let timerInterval = null;
let timerEnd = null;
let timerDuration = 0;
const timerProgress = document.getElementById('timerProgress');
const progressStart = document.getElementById('progressStart');
const progressEnd = document.getElementById('progressEnd');
function formatTimer(ms) {
if (ms < 0) ms = 0;
const date = new Date(ms);
// Use UTC to avoid timezone offset
return (
pad(Math.floor(ms / 3600000)) +
":" + pad(date.getUTCMinutes()) +
":" + pad(date.getUTCSeconds()) +
":" + pad(date.getUTCMilliseconds(), 3)
);
}
function parseCustomTime(str) {
// Accepts HH:MM:SS:sss, all optional, missing parts = 0
const parts = str.split(":").map(x => x.trim());
let [h, m, s, ms] = [0, 0, 0, 0];
if (parts.length > 0) h = parseInt(parts[0] || 0);
if (parts.length > 1) m = parseInt(parts[1] || 0);
if (parts.length > 2) s = parseInt(parts[2] || 0);
if (parts.length > 3) ms = parseInt(parts[3] || 0);
if ([h, m, s, ms].some(isNaN)) return null;
return h * 3600000 + m * 60000 + s * 1000 + ms;
}
function startTimer(durationMs) {
if (timerInterval) clearInterval(timerInterval);
timerEnd = Date.now() + durationMs;
timerDuration = durationMs;
// Set progress bar start/end labels
const startDate = new Date();
const endDate = new Date(Date.now() + durationMs);
progressStart.textContent = formatTime(startDate);
progressEnd.textContent = formatTime(endDate);
updateProgressBar(0);
function tick() {
const now = Date.now();
const remaining = timerEnd - now;
timerDisplay.textContent = formatTimer(remaining);
let percent = 100 * (1 - Math.max(0, remaining) / timerDuration);
updateProgressBar(percent);
if (remaining <= 0) {
timerDisplay.textContent = "00:00:00:000";
clearInterval(timerInterval);
timerInterval = null;
updateProgressBar(100);
}
}
tick();
timerInterval = setInterval(tick, 33);
}
function updateProgressBar(percent) {
timerProgress.style.width = percent + '%';
timerProgress.setAttribute('aria-valuenow', percent);
}
// Attach to timer buttons
const timerButtons = document.querySelectorAll('.quick-timers .btn-outline-primary');
const timeMap = {
'10s': 10 * 1000,
'1m': 60 * 1000,
'5m': 5 * 60 * 1000,
'10m': 10 * 60 * 1000,
'15m': 15 * 60 * 1000,
'30m': 30 * 60 * 1000,
'1h': 60 * 60 * 1000
};
timerButtons.forEach(btn => {
btn.addEventListener('click', () => {
const label = btn.textContent.trim();
if (timeMap[label]) {
startTimer(timeMap[label]);
}
});
});
// Custom timer form
const customTimerForm = document.getElementById('customTimerForm');
const customTimerInput = document.getElementById('customTimerInput');
customTimerForm.addEventListener('submit', function(e) {
e.preventDefault();
const val = customTimerInput.value.trim();
const ms = parseCustomTime(val);
if (ms && ms > 0) {
startTimer(ms);
customTimerInput.value = '';
} else {
customTimerInput.classList.add('is-invalid');
setTimeout(() => customTimerInput.classList.remove('is-invalid'), 1200);
}
});
// Theme toggle
const themeToggle = document.getElementById('themeToggle');
const iconDay = document.getElementById('iconDay');
const iconNight = document.getElementById('iconNight');
const themeIcon = document.getElementById('themeIcon');
const themeToggleText = document.getElementById('themeToggleText');
function setThemeIcons() {
const html = document.documentElement;
const isDark = html.getAttribute('data-bs-theme') === 'dark';
if (isDark) {
iconDay.style.display = 'none';
iconNight.style.display = 'inline';
document.documentElement.style.setProperty('--right-card-bg', '#23272f');
document.documentElement.style.setProperty('--right-card-text', '#f8fafc');
themeToggleText.textContent = 'Day Mode'; // Fix: show what will happen on click
} else {
iconDay.style.display = 'inline';
iconNight.style.display = 'none';
document.documentElement.style.setProperty('--right-card-bg', '#f8fafc');
document.documentElement.style.setProperty('--right-card-text', '#23272f');
themeToggleText.textContent = 'Night Mode'; // Fix: show what will happen on click
}
}
themeToggle.addEventListener('click', () => {
const html = document.documentElement;
const isDark = html.getAttribute('data-bs-theme') === 'dark';
html.setAttribute('data-bs-theme', isDark ? 'light' : 'dark');
setThemeIcons();
setNavbarTheme(); // Ensure navbar updates immediately
});
setThemeIcons();
</script>
</body>
</html>