-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
528 lines (455 loc) · 25.1 KB
/
Copy pathindex.html
File metadata and controls
528 lines (455 loc) · 25.1 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Japandi Timer</title>
<script src="https://cdn.tailwindcss.com"></script>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;700&display=swap" rel="stylesheet">
<style>
:root {
/* Japandi Color Palette */
--bg-color: #F5F5F3; /* Off-white, rice paper */
--primary-text: #343434; /* Dark charcoal, almost black */
--secondary-text: #6B7280; /* Muted grey - Adjusted for better visibility */
--accent-color: #B9A28C; /* Warm, sandy beige */
--accent-color-dark: #9A8370;
--container-bg: #FFFFFF;
--border-color: #E5E5E3;
--timer-bg: #EAEAEA;
--timer-fill: #343434;
}
body {
font-family: 'Inter', sans-serif;
background-color: var(--bg-color);
color: var(--primary-text);
}
/* Utility classes to correctly apply CSS variables */
.bg-main { background-color: var(--bg-color); }
.bg-container { background-color: var(--container-bg); }
.bg-accent { background-color: var(--accent-color); }
.bg-primary-text { background-color: var(--primary-text); }
.bg-secondary-text { background-color: var(--secondary-text); }
.hover-bg-accent-dark:hover { background-color: var(--accent-color-dark); }
.text-primary { color: var(--primary-text); }
.text-secondary { color: var(--secondary-text); }
.border-main { border-color: var(--border-color); }
.focus-ring-accent:focus {
outline: 2px solid transparent;
outline-offset: 2px;
border-color: var(--accent-color);
--tw-ring-color: var(--accent-color);
--tw-ring-offset-shadow: var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color);
--tw-ring-shadow: var(--tw-ring-inset) 0 0 0 calc(2px + var(--tw-ring-offset-width)) var(--tw-ring-color);
box-shadow: var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow, 0 0 #0000);
}
.timer-circle {
transition: stroke-dashoffset 0.3s linear;
transform: rotate(-90deg);
transform-origin: 50% 50%;
}
/* Custom scrollbar for a more minimal look */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: var(--bg-color); }
::-webkit-scrollbar-thumb { background: var(--border-color); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--secondary-text); }
</style>
</head>
<body class="antialiased">
<div id="app" class="min-h-screen flex flex-col items-center justify-center p-4 transition-all duration-500">
<div class="w-full max-w-lg mx-auto bg-container rounded-2xl shadow-lg p-6 space-y-6">
<div class="text-center">
<h1 class="text-3xl font-bold text-primary">Japandi Timer</h1>
<p class="text-secondary mt-1">Focus, one task at a time.</p>
</div>
<div class="relative">
<input id="taskInput" type="text" placeholder='e.g., Meditate (10), Read book (25)' class="w-full bg-main border-2 border-main rounded-lg py-3 px-4 focus-ring-accent transition-colors" />
<button id="addTaskBtn" class="absolute right-2 top-1/2 -translate-y-1/2 bg-accent text-white font-semibold px-4 py-2 rounded-md hover-bg-accent-dark transition-colors">
Add
</button>
</div>
<div id="taskList" class="space-y-3 max-h-60 overflow-y-auto pr-2">
</div>
<div class="flex items-center justify-center pt-4 border-t border-main">
<button id="startPlaylistBtn" class="bg-primary-text text-white font-bold py-3 px-8 rounded-lg hover:bg-gray-700 transition-transform transform hover:scale-105 disabled:opacity-50 disabled:cursor-not-allowed disabled:transform-none">
Start Playlist
</button>
</div>
</div>
<div id="timerModal" class="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center hidden z-50 p-4">
<div class="bg-container rounded-2xl shadow-2xl p-8 w-full max-w-md text-center space-y-6 relative">
<button id="miniWindowBtn" class="absolute top-4 right-4 text-secondary hover:text-primary transition-colors" title="Open mini timer">
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"></path><polyline points="15 3 21 3 21 9"></polyline><line x1="10" y1="14" x2="21" y2="3"></line></svg>
</button>
<h2 id="timerTaskName" class="text-2xl sm:text-3xl font-bold text-primary"></h2>
<div class="relative w-64 h-64 mx-auto">
<svg class="w-full h-full" viewBox="0 0 100 100">
<circle stroke="var(--timer-bg)" stroke-width="12" fill="var(--container-bg)" r="44" cx="50" cy="50" />
<g id="timerDialMarks"></g>
<circle id="timerProgress" class="timer-circle" stroke-width="8" stroke-linecap="round" stroke="var(--timer-fill)" fill="transparent" r="44" cx="50" cy="50" />
</svg>
<div id="timerDisplay" class="absolute inset-0 flex items-center justify-center text-5xl font-bold text-primary">
00:00
</div>
</div>
<div id="endPrompt" class="hidden space-y-4 pt-4">
<p class="text-lg text-secondary">Task finished. What's next?</p>
<div class="grid grid-cols-1 gap-4">
<button id="nextTaskBtn" class="w-full bg-primary-text text-white font-semibold py-3 px-5 rounded-lg hover:bg-gray-700 transition-colors">
Next Task
</button>
<button id="closeModalBtn" class="w-full bg-secondary-text text-white font-semibold py-3 px-5 rounded-lg hover:bg-gray-500 transition-colors">
Finish Session
</button>
</div>
<div class="flex items-center justify-center pt-4">
<p class="text-sm text-secondary mr-4">Or add more time:</p>
<button class="add-time-btn bg-accent text-white rounded-full h-10 w-10 font-bold hover-bg-accent-dark transition-colors" data-time="1">1</button>
<button class="add-time-btn bg-accent text-white rounded-full h-10 w-10 font-bold ml-2 hover-bg-accent-dark transition-colors" data-time="5">5</button>
<button class="add-time-btn bg-accent text-white rounded-full h-10 w-10 font-bold ml-2 hover-bg-accent-dark transition-colors" data-time="10">10</button>
</div>
</div>
</div>
</div>
</div>
<audio id="ringtone" src="ringtone.ogg" preload="auto"></audio>
<script>
document.addEventListener('DOMContentLoaded', () => {
// DOM Elements
const taskInput = document.getElementById('taskInput');
const addTaskBtn = document.getElementById('addTaskBtn');
const taskList = document.getElementById('taskList');
const startPlaylistBtn = document.getElementById('startPlaylistBtn');
const timerModal = document.getElementById('timerModal');
const timerTaskName = document.getElementById('timerTaskName');
const timerDisplay = document.getElementById('timerDisplay');
const timerProgress = document.getElementById('timerProgress');
const timerDialMarks = document.getElementById('timerDialMarks');
const endPrompt = document.getElementById('endPrompt');
const nextTaskBtn = document.getElementById('nextTaskBtn');
const closeModalBtn = document.getElementById('closeModalBtn');
const ringtone = document.getElementById('ringtone');
const miniWindowBtn = document.getElementById('miniWindowBtn');
// App State
let tasks = [];
let currentTaskIndex = -1;
let timerInterval;
let totalSeconds = 0;
let secondsRemaining = 0;
let miniWindow = null;
const progressCircleRadius = timerProgress.r.baseVal.value;
const progressCircleCircumference = 2 * Math.PI * progressCircleRadius;
timerProgress.style.strokeDasharray = `${progressCircleCircumference} ${progressCircleCircumference}`;
// SVG Namespace
const svgNS = "http://www.w3.org/2000/svg";
// --- Timer Dial Generation ---
function renderDialMarks() {
timerDialMarks.innerHTML = '';
const center = 50;
const majorRadius = 38;
const minorRadius = 40;
const textRadius = 32;
for (let i = 0; i < 60; i++) {
const angle = (i / 60) * 360 - 90;
const angleRad = (angle * Math.PI) / 180;
const isMajorTick = i % 5 === 0;
const isNumberedTick = i % 10 === 0;
const tickStartRadius = isMajorTick ? majorRadius : minorRadius;
const tickEndRadius = 42;
const x1 = center + Math.cos(angleRad) * tickStartRadius;
const y1 = center + Math.sin(angleRad) * tickStartRadius;
const x2 = center + Math.cos(angleRad) * tickEndRadius;
const y2 = center + Math.sin(angleRad) * tickEndRadius;
const line = document.createElementNS(svgNS, 'line');
line.setAttribute('x1', x1);
line.setAttribute('y1', y1);
line.setAttribute('x2', x2);
line.setAttribute('y2', y2);
line.setAttribute('stroke', 'var(--secondary-text)');
line.setAttribute('stroke-width', isMajorTick ? '0.75' : '0.5');
timerDialMarks.appendChild(line);
if (isNumberedTick) {
const textX = center + Math.cos(angleRad) * textRadius;
const textY = center + Math.sin(angleRad) * textRadius;
const text = document.createElementNS(svgNS, 'text');
text.setAttribute('x', textX);
text.setAttribute('y', textY);
text.setAttribute('font-size', '5');
text.setAttribute('font-weight', '500');
text.setAttribute('text-anchor', 'middle');
text.setAttribute('dominant-baseline', 'middle');
text.setAttribute('fill', 'var(--primary-text)');
text.textContent = i === 0 ? '60' : i;
timerDialMarks.appendChild(text);
}
}
}
// --- Task Management ---
function parseAndAddTasks() {
const inputText = taskInput.value.trim();
if (!inputText) return;
const taskStrings = inputText.split(',');
taskStrings.forEach(str => {
const match = str.trim().match(/^(.*?)\s*\((\d+)\)$/);
if (match) {
const name = match[1].trim();
const duration = parseInt(match[2], 10);
if (name && !isNaN(duration) && duration > 0) {
tasks.push({ name, duration });
}
}
});
taskInput.value = '';
renderTasks();
updatePlaylistButton();
}
function renderTasks() {
taskList.innerHTML = '';
if (tasks.length === 0) {
taskList.innerHTML = `<p class="text-center text-secondary">Your task list is empty.</p>`;
} else {
tasks.forEach((task, index) => {
const taskElement = document.createElement('div');
taskElement.className = 'flex items-center justify-between bg-main p-3 rounded-lg border border-main';
taskElement.innerHTML = `
<div>
<p class="font-medium text-primary">${task.name}</p>
<p class="text-sm text-secondary">${task.duration} minute${task.duration > 1 ? 's' : ''}</p>
</div>
<button class="remove-task-btn text-red-400 hover:text-red-600 font-bold text-xl" data-index="${index}">×</button>
`;
taskList.appendChild(taskElement);
});
}
}
function removeTask(index) {
tasks.splice(index, 1);
renderTasks();
updatePlaylistButton();
}
function updatePlaylistButton() {
startPlaylistBtn.disabled = tasks.length === 0;
}
// --- Playlist and Timer Logic ---
function stopRingtone() {
ringtone.pause();
ringtone.currentTime = 0;
}
function startPlaylist() {
if (tasks.length === 0) return;
currentTaskIndex = 0;
startTask(currentTaskIndex);
}
function startTask(index) {
if (index >= tasks.length) {
endPlaylist();
return;
}
const task = tasks[index];
totalSeconds = task.duration * 60;
secondsRemaining = totalSeconds;
timerTaskName.textContent = task.name;
updateUIs();
showTimerModal();
hideEndPrompt();
stopRingtone();
clearInterval(timerInterval);
timerInterval = setInterval(() => {
secondsRemaining--;
updateUIs();
if (secondsRemaining <= 0) {
clearInterval(timerInterval);
handleTaskEnd();
}
}, 1000);
}
function handleTaskEnd() {
ringtone.play();
showEndPrompt();
if (miniWindow && !miniWindow.closed) {
miniWindow.showEndPrompt(currentTaskIndex < tasks.length - 1);
}
nextTaskBtn.style.display = (currentTaskIndex < tasks.length - 1) ? 'block' : 'none';
}
function startNextTask() {
stopRingtone();
currentTaskIndex++;
startTask(currentTaskIndex);
}
// **FIX**: Make function globally accessible AFTER it has been defined
window.startNextTask = startNextTask;
function addTime(minutes) {
stopRingtone();
hideEndPrompt();
if (miniWindow && !miniWindow.closed) {
miniWindow.hideEndPrompt();
}
if (secondsRemaining <= 0) {
totalSeconds = minutes * 60;
secondsRemaining = minutes * 60;
} else {
totalSeconds += minutes * 60;
secondsRemaining += minutes * 60;
}
clearInterval(timerInterval);
timerInterval = setInterval(() => {
secondsRemaining--;
updateUIs();
if (secondsRemaining <= 0) {
clearInterval(timerInterval);
handleTaskEnd();
}
}, 1000);
updateUIs();
}
// **FIX**: Make function globally accessible AFTER it has been defined
window.addTime = addTime;
function endPlaylist() {
hideTimerModal();
currentTaskIndex = -1;
}
// --- UI Updates ---
function updateUIs() {
const minutes = Math.floor(secondsRemaining / 60);
const seconds = secondsRemaining % 60;
const timeString = `${String(minutes).padStart(2, '0')}:${String(seconds).padStart(2, '0')}`;
let progress = 0;
if (totalSeconds > 0) {
progress = secondsRemaining / totalSeconds;
}
const dashoffset = progressCircleCircumference * (1 - progress);
// Update main modal
timerDisplay.textContent = timeString;
timerProgress.style.strokeDashoffset = Math.max(0, dashoffset);
// Update mini window if open
if (miniWindow && !miniWindow.closed) {
miniWindow.updateUI(tasks[currentTaskIndex].name, timeString, Math.max(0, dashoffset));
}
}
function showTimerModal() {
timerModal.classList.remove('hidden');
}
function hideTimerModal() {
stopRingtone();
timerModal.classList.add('hidden');
clearInterval(timerInterval);
if (miniWindow && !miniWindow.closed) {
miniWindow.close();
}
}
function showEndPrompt() {
endPrompt.classList.remove('hidden');
}
function hideEndPrompt() {
endPrompt.classList.add('hidden');
}
// --- Mini Window Logic ---
function openMiniWindow() {
if (miniWindow && !miniWindow.closed) {
miniWindow.focus();
return;
}
const miniHtml = `
<!DOCTYPE html>
<html>
<head>
<title>Japandi Timer</title>
<script src="https://cdn.tailwindcss.com"><\/script>
<style>
:root {
--bg-color: #F5F5F3; --primary-text: #343434; --secondary-text: #6B7280; --accent-color: #B9A28C;
--accent-color-dark: #9A8370; --container-bg: #FFFFFF; --border-color: #E5E5E3; --timer-bg: #EAEAEA; --timer-fill: #343434;
}
body { font-family: 'Inter', sans-serif; background-color: var(--bg-color); color: var(--primary-text); text-align: center; }
.timer-circle { transition: stroke-dashoffset 0.3s linear; transform: rotate(-90deg); transform-origin: 50% 50%; }
.hover-bg-accent-dark:hover { background-color: var(--accent-color-dark); }
<\/style>
</head>
<body class="antialiased p-6">
<h2 id="timerTaskName" class="text-xl font-bold truncate"></h2>
<div class="relative w-48 h-48 mx-auto my-4">
<svg class="w-full h-full" viewBox="0 0 100 100">
<circle stroke="var(--timer-bg)" stroke-width="12" fill="var(--container-bg)" r="44" cx="50" cy="50" />
<circle id="timerProgress" class="timer-circle" stroke-width="8" stroke-linecap="round" stroke="var(--timer-fill)" fill="transparent" r="44" cx="50" cy="50" style="stroke-dasharray: 276.46; stroke-dashoffset: 276.46;" />
</svg>
<div id="timerDisplay" class="absolute inset-0 flex items-center justify-center text-4xl font-bold">00:00</div>
</div>
<div id="endPrompt" class="hidden space-y-2">
<p class="text-md text-secondary">Task finished.</p>
<button id="nextTaskBtn" class="w-full bg-primary-text text-white font-semibold py-2 px-4 rounded-lg hover:bg-gray-700">Next Task</button>
<div class="flex items-center justify-center pt-2">
<button class="add-time-btn bg-accent text-white rounded-full h-8 w-8 font-bold hover-bg-accent-dark" data-time="1">1</button>
<button class="add-time-btn bg-accent text-white rounded-full h-8 w-8 font-bold ml-2 hover-bg-accent-dark" data-time="5">5</button>
<button class="add-time-btn bg-accent text-white rounded-full h-8 w-8 font-bold ml-2 hover-bg-accent-dark" data-time="10">10</button>
</div>
</div>
<script>
const taskNameEl = document.getElementById('timerTaskName');
const displayEl = document.getElementById('timerDisplay');
const progressEl = document.getElementById('timerProgress');
const endPromptEl = document.getElementById('endPrompt');
const nextTaskBtn = document.getElementById('nextTaskBtn');
function updateUI(taskName, timeString, dashoffset) {
taskNameEl.textContent = taskName;
taskNameEl.title = taskName;
displayEl.textContent = timeString;
progressEl.style.strokeDashoffset = dashoffset;
}
function showEndPrompt(hasNext) {
endPromptEl.classList.remove('hidden');
nextTaskBtn.style.display = hasNext ? 'block' : 'none';
}
function hideEndPrompt() {
endPromptEl.classList.add('hidden');
}
nextTaskBtn.addEventListener('click', () => window.opener.startNextTask());
document.querySelectorAll('.add-time-btn').forEach(btn => {
btn.addEventListener('click', (e) => {
window.opener.addTime(parseInt(e.target.dataset.time, 10));
});
});
window.addEventListener('beforeunload', () => {
window.opener.miniWindow = null;
});
<\/script>
</body>
</html>
`;
miniWindow = window.open('', 'JapandiTimerMini', 'width=300,height=380,resizable=yes,scrollbars=no');
miniWindow.document.write(miniHtml);
miniWindow.document.close();
}
// --- Event Listeners ---
addTaskBtn.addEventListener('click', parseAndAddTasks);
taskInput.addEventListener('keydown', (e) => { if (e.key === 'Enter') parseAndAddTasks(); });
taskList.addEventListener('click', (e) => {
if(e.target.classList.contains('remove-task-btn')) {
const index = parseInt(e.target.dataset.index, 10);
removeTask(index);
}
});
startPlaylistBtn.addEventListener('click', startPlaylist);
nextTaskBtn.addEventListener('click', startNextTask);
closeModalBtn.addEventListener('click', hideTimerModal);
miniWindowBtn.addEventListener('click', openMiniWindow);
document.querySelectorAll('.add-time-btn').forEach(button => {
button.addEventListener('click', (e) => {
const timeToAdd = parseInt(e.target.dataset.time, 10);
addTime(timeToAdd);
});
});
window.addEventListener('beforeunload', () => {
if (miniWindow && !miniWindow.closed) {
miniWindow.close();
}
});
// Initial Render
renderDialMarks();
renderTasks();
updatePlaylistButton();
});
</script>
</body>
</html>