-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrenderer.js
110 lines (97 loc) · 3.18 KB
/
renderer.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
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
// Timer logic
let timerInterval;
let timerRunning = false;
let timeRemaining = 1500; // 25 minutes in seconds by default
const timeDisplay = document.getElementById('time');
const startStopButton = document.getElementById('startStop');
const resetButton = document.getElementById('reset');
const setTimerButton = document.getElementById('set-timer');
const minutesInput = document.getElementById('minutes');
const secondsInput = document.getElementById('seconds');
// Start/Stop button functionality
startStopButton.addEventListener('click', () => {
if (timerRunning) {
clearInterval(timerInterval);
timerRunning = false;
startStopButton.textContent = 'Start';
} else {
timerRunning = true;
startStopButton.textContent = 'Stop';
timerInterval = setInterval(() => {
if (timeRemaining > 0) {
timeRemaining--;
updateTimeDisplay();
} else {
clearInterval(timerInterval);
alert('Time is up!');
}
}, 1000);
}
});
// Reset button functionality
resetButton.addEventListener('click', () => {
clearInterval(timerInterval);
timerRunning = false;
timeRemaining = 1500; // Default 25 minutes
updateTimeDisplay();
startStopButton.textContent = 'Start';
});
// Set custom timer functionality
setTimerButton.addEventListener('click', () => {
const minutes = parseInt(minutesInput.value) || 0;
const seconds = parseInt(secondsInput.value) || 0;
timeRemaining = minutes * 60 + seconds;
updateTimeDisplay();
});
// Update the timer display
function updateTimeDisplay() {
const minutes = Math.floor(timeRemaining / 60);
const seconds = timeRemaining % 60;
timeDisplay.textContent = `${minutes < 10 ? '0' : ''}${minutes}:${
seconds < 10 ? '0' : ''
}${seconds}`;
}
// Task List logic
const taskInput = document.getElementById('new-task');
const taskList = document.getElementById('task-list');
const addTaskButton = document.getElementById('add-task');
let tasks = [];
addTaskButton.addEventListener('click', () => {
const taskText = taskInput.value.trim();
if (taskText) {
const task = {
id: Date.now(),
text: taskText,
completed: false,
};
tasks.push(task);
renderTaskList();
taskInput.value = '';
}
});
function renderTaskList() {
taskList.innerHTML = '';
tasks.forEach((task) => {
const li = document.createElement('li');
li.dataset.id = task.id;
li.className = task.completed ? 'completed' : '';
const span = document.createElement('span');
span.textContent = task.text;
li.appendChild(span);
const completeButton = document.createElement('button');
completeButton.textContent = 'Complete';
completeButton.addEventListener('click', () => {
task.completed = !task.completed;
renderTaskList();
});
li.appendChild(completeButton);
const deleteButton = document.createElement('button');
deleteButton.textContent = 'Delete';
deleteButton.addEventListener('click', () => {
tasks = tasks.filter((t) => t.id !== task.id);
renderTaskList();
});
li.appendChild(deleteButton);
taskList.appendChild(li);
});
}