-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
81 lines (73 loc) · 3.15 KB
/
script.js
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
document.addEventListener('DOMContentLoaded', () => {
const startPauseBtn = document.getElementById('start-pause');
const resetBtn = document.getElementById('reset');
const timerDisplay = document.getElementById('time');
const statusDisplay = document.getElementById('status');
const timerEndSound = document.getElementById('timer-end-sound');
const settingsIcon = document.getElementById('settings-icon');
const settingsMenu = document.getElementById('settings-menu');
const applySettingsBtn = document.getElementById('apply-settings');
const pomodoroDurationInput = document.getElementById('pomodoro-duration');
const breakDurationInput = document.getElementById('break-duration');
const backgroundUrlInput = document.getElementById('background-url');
const buttonColorInput = document.getElementById('button-color');
let timer;
let isRunning = false;
let timeLeft = 25 * 60;
let isPomodoro = true;
const updateDisplay = () => {
const minutes = Math.floor(timeLeft / 60);
const seconds = timeLeft % 60;
timerDisplay.textContent = `${minutes.toString().padStart(2, '0')}:${seconds.toString().padStart(2, '0')}`;
};
const startTimer = () => {
timer = setInterval(() => {
if (timeLeft > 0) {
timeLeft--;
updateDisplay();
} else {
clearInterval(timer);
timerEndSound.play();
isPomodoro = !isPomodoro;
timeLeft = isPomodoro ? pomodoroDurationInput.value * 60 : breakDurationInput.value * 60;
statusDisplay.textContent = isPomodoro ? 'Pomodoro' : 'Break';
statusDisplay.classList.add('animate');
setTimeout(() => {
statusDisplay.classList.remove('animate');
}, 500);
startTimer();
}
}, 1000);
};
startPauseBtn.addEventListener('click', () => {
if (isRunning) {
clearInterval(timer);
startPauseBtn.textContent = 'Start';
} else {
startTimer();
startPauseBtn.textContent = 'Pause';
}
isRunning = !isRunning;
});
resetBtn.addEventListener('click', () => {
clearInterval(timer);
isRunning = false;
timeLeft = pomodoroDurationInput.value * 60;
isPomodoro = true;
statusDisplay.textContent = 'Pomodoro';
updateDisplay();
startPauseBtn.textContent = 'Start';
});
settingsIcon.addEventListener('click', () => {
settingsMenu.style.display = settingsMenu.style.display === 'none' ? 'flex' : 'none';
});
applySettingsBtn.addEventListener('click', () => {
timeLeft = pomodoroDurationInput.value * 60;
document.body.style.backgroundImage = `url('${backgroundUrlInput.value}')`;
startPauseBtn.style.backgroundColor = buttonColorInput.value;
resetBtn.style.backgroundColor = buttonColorInput.value;
updateDisplay();
settingsMenu.style.display = 'none';
});
updateDisplay();
});