-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
195 lines (168 loc) · 5.65 KB
/
script.js
File metadata and controls
195 lines (168 loc) · 5.65 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
// ======= Todo List =======
const taskInput = document.getElementById("taskInput");
const addTaskBtn = document.getElementById("addTask");
const taskList = document.getElementById("taskList");
const clearAllBtn = document.getElementById("clearAll");
function saveTasks() {
const tasks = [];
document.querySelectorAll("#taskList li").forEach((li) => {
tasks.push({
text: li.firstChild.textContent,
completed: li.classList.contains("completed"),
});
});
localStorage.setItem("tasks", JSON.stringify(tasks));
}
function loadTasks() {
const tasks = JSON.parse(localStorage.getItem("tasks")) || [];
tasks.forEach((task) => addTaskToDOM(task.text, task.completed));
}
function addTaskToDOM(text, completed = false) {
const li = document.createElement("li");
li.textContent = text;
if (completed) li.classList.add("completed");
li.addEventListener("click", () => {
li.classList.toggle("completed");
saveTasks();
});
const deleteBtn = document.createElement("button");
deleteBtn.textContent = "❌";
deleteBtn.addEventListener("click", (e) => {
e.stopPropagation();
li.remove();
saveTasks();
});
li.appendChild(deleteBtn);
taskList.appendChild(li);
}
addTaskBtn.addEventListener("click", () => {
const text = taskInput.value.trim();
if (text) {
addTaskToDOM(text);
taskInput.value = "";
saveTasks();
}
});
clearAllBtn.addEventListener("click", () => {
taskList.innerHTML = "";
saveTasks();
});
loadTasks();
// ======= Pomodoro Timer =======
let timer = 25 * 60;
let interval = null;
let isBreak = false;
const timeDisplay = document.getElementById("timeDisplay");
const startStopBtn = document.getElementById("startStop");
const resetBtn = document.getElementById("reset");
const timerTitle = document.querySelector(".timer h2");
function updateTimerDisplay() {
const minutes = Math.floor(timer / 60)
.toString()
.padStart(2, "0");
const seconds = (timer % 60).toString().padStart(2, "0");
timeDisplay.textContent = `${minutes}:${seconds}`;
}
function switchMode() {
isBreak = !isBreak;
if (isBreak) {
timer = 5 * 60;
timerTitle.textContent = "Break Time! ☕";
timerTitle.style.color = "#28a745";
} else {
timer = 25 * 60;
timerTitle.textContent = "Pomodoro Timer 🍅";
timerTitle.style.color = "#000";
}
updateTimerDisplay();
}
function startTimer() {
if (interval) return;
interval = setInterval(() => {
if (timer > 0) {
timer--;
updateTimerDisplay();
} else {
clearInterval(interval);
interval = null;
alert(isBreak ? "Back to work!" : "Take a break!");
switchMode();
}
}, 1000);
startStopBtn.textContent = "Pause";
}
function stopTimer() {
clearInterval(interval);
interval = null;
startStopBtn.textContent = "Start";
}
startStopBtn.addEventListener("click", () => {
interval ? stopTimer() : startTimer();
});
resetBtn.addEventListener("click", () => {
stopTimer();
isBreak = false;
timer = 25 * 60;
updateTimerDisplay();
});
updateTimerDisplay();
// ======= Motivation =======
const tips = [
"Coding tip: Break large problems into smaller tasks.",
"Consistency beats intensity. Keep going!",
"Take a deep breath. Focus on one task at a time.",
"Done is better than perfect.",
"Coding tip: Always comment your code for your future self.",
"Chess tip: Control the center squares to dominate the board.",
"Music tip: Practice 20 minutes daily rather than 3 hours once a week.",
"Motivation tip: Take small steps every day; consistency beats intensity.",
"Life tip: Drink enough water daily and stay hydrated.",
"Coding tip: Don't memorize code, understand the logic behind it.",
"Chess tip: Don't bring your Queen out too early in the game.",
"Music tip: Record your practice sessions to hear your progress.",
"Motivation tip: Your only limit is your mind. Stay focused.",
"Life tip: Get at least 7-8 hours of sleep to keep your brain sharp.",
"Chess tip: Always look for your opponent's threat before making a move.",
"Motivation tip: Done is better than perfect. Just start!",
"Life tip: Practice gratitude; it changes your perspective on everything.",
"Coding tip: Google is your best friend, don't be afraid to use it.",
];
const motivationText = document.getElementById("motivationText");
const newMotivationBtn = document.getElementById("newMotivation");
function showMotivation() {
const index = Math.floor(Math.random() * tips.length);
motivationText.textContent = tips[index];
}
newMotivationBtn.addEventListener("click", showMotivation);
showMotivation();
// ======= Music Player =======
const musicUpload = document.getElementById("musicUpload");
const customUploadBtn = document.getElementById("customUploadBtn");
const audioPlayer = document.getElementById("audioPlayer");
const playPauseBtn = document.getElementById("playPauseMusic");
const trackName = document.getElementById("trackName");
const volumeControl = document.getElementById("volumeControl");
audioPlayer.volume = volumeControl.value;
volumeControl.addEventListener("input", (e) => {
audioPlayer.volume = e.target.value;
});
customUploadBtn.addEventListener("click", () => musicUpload.click());
musicUpload.addEventListener("change", function () {
const file = this.files[0];
if (file) {
const url = URL.createObjectURL(file);
audioPlayer.src = url;
trackName.textContent = "Track: " + file.name;
audioPlayer.play();
playPauseBtn.textContent = "Pause Music";
}
});
playPauseBtn.addEventListener("click", () => {
if (audioPlayer.paused) {
audioPlayer.play();
playPauseBtn.textContent = "Pause Music";
} else {
audioPlayer.pause();
playPauseBtn.textContent = "Play Music";
}
});