-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
74 lines (62 loc) · 2 KB
/
script.js
File metadata and controls
74 lines (62 loc) · 2 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
// Zen Focus Timer - Logic Layer
const timerDisplay = document.getElementById('timer');
const startBtn = document.getElementById('start-btn');
const pauseBtn = document.getElementById('pause-btn');
const resetBtn = document.getElementById('reset-btn');
const focusInput = document.getElementById('focus-task');
let timeLeft = 25 * 60; // 25 minutes in seconds
let timerId = null;
let isRunning = false;
function updateDisplay() {
const minutes = Math.floor(timeLeft / 60);
const seconds = timeLeft % 60;
const displayTime = `${minutes.toString().padStart(2, '0')}:${seconds.toString().padStart(2, '0')}`;
timerDisplay.textContent = displayTime;
document.title = `${displayTime} - Zen Focus`;
}
function startTimer() {
if (isRunning) return;
isRunning = true;
startBtn.disabled = true;
startBtn.style.opacity = "0.5";
pauseBtn.disabled = false;
pauseBtn.style.opacity = "1";
timerId = setInterval(() => {
if (timeLeft > 0) {
timeLeft--;
updateDisplay();
} else {
clearInterval(timerId);
isRunning = false;
startBtn.disabled = false;
startBtn.style.opacity = "1";
alert("Focus session complete!");
}
}, 1000);
}
function pauseTimer() {
if (!isRunning) return;
clearInterval(timerId);
isRunning = false;
startBtn.disabled = false;
startBtn.style.opacity = "1";
pauseBtn.disabled = true;
pauseBtn.style.opacity = "0.5";
}
function resetTimer() {
clearInterval(timerId);
isRunning = false;
timeLeft = 25 * 60;
updateDisplay();
startBtn.disabled = false;
startBtn.style.opacity = "1";
pauseBtn.disabled = false; // Reset to enabled state
pauseBtn.style.opacity = "1";
}
// Event Listeners
startBtn.addEventListener('click', startTimer);
pauseBtn.addEventListener('click', pauseTimer);
resetBtn.addEventListener('click', resetTimer);
// Initialize
updateDisplay();
console.log("Zen Focus Timer Loaded & Ready");