-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathscript.js
459 lines (397 loc) · 14.3 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
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
function updateClock() {
const timezoneSelect = document.getElementById("timezone-select");
if (!timezoneSelect) return; // If the timezone select element doesn't exist, exit the function
const timezone = timezoneSelect.value;
const now = new Date();
// Date options for the selected timezone
const optionsDate = {
timeZone: timezone,
day: "2-digit",
month: "short",
year: "numeric",
};
// Time options for the selected timezone
const optionsTime = {
timeZone: timezone,
hour12: true,
hour: "2-digit",
minute: "2-digit",
second: "2-digit",
};
try {
// Format date and time based on the selected timezone
const datePart = now.toLocaleDateString("en-US", optionsDate);
const timePart = now.toLocaleTimeString("en-US", optionsTime);
// Display the formatted date and time in the element
document.getElementById("current-time").textContent = `${datePart} - ${timePart}`;
} catch (error) {
// Handle any errors related to invalid timezone
console.error("Error formatting date/time for timezone:", timezone, error);
document.getElementById("current-time").textContent = "Invalid Timezone";
}
}
setInterval(updateClock, 1000);
document.getElementById("timezone-select").addEventListener("change", updateClock);
updateClock();
// Checklist functionality
const taskInput = document.getElementById("new-task");
const categoryInput = document.getElementById("task-category");
const addTaskButton = document.getElementById("add-task");
const taskList = document.getElementById("task-list");
const categoryDropdown = document.getElementById("category-dropdown");
const mapAllButton = document.getElementById("map-all");
const customMapButton = document.getElementById("custom-map");
const taskCategories = new Set();
let tasks = [];
addTaskButton.addEventListener("click", addTask);
mapAllButton.addEventListener("click", mapAllTasks);
customMapButton.addEventListener("click", customMapTasks);
function addTask() {
const taskText = taskInput.value.trim();
const category = categoryInput.value.trim() || categoryDropdown.value;
if (taskText) {
const task = { text: taskText, category, completed: false };
tasks.push(task);
renderTask(task);
if (category) {
taskCategories.add(category.toLowerCase());
updateCategoryDropdown();
}
taskInput.value = "";
categoryInput.value = "";
updateProductivityScore();
}
}
function renderTask(task) {
const li = document.createElement("li");
li.innerHTML = `
<span class="task-text">${task.text}</span>
<span class="task-category">${task.category}</span>
<div class="task-control">
<button class="complete-task">✓</button>
<button class="edit-task">Edit</button>
<button class="delete-task">Delete</button>
<button class="toggle-category">👁️</button>
</div>
`;
taskList.appendChild(li);
li.querySelector(".complete-task").addEventListener("click", () =>
toggleTaskCompletion(task, li)
);
li.querySelector(".edit-task").addEventListener("click", () =>
editTask(task, li)
);
li.querySelector(".delete-task").addEventListener("click", () => {
showAlertBox(task, li);
});
li.querySelector(".toggle-category").addEventListener("click", () =>
toggleCategory(li)
);
}
function showAlertBox(task, li) {
const modal = document.getElementById("deleteModal");
modal.style.display = "flex";
const confirmDelete = document.getElementById("confirmDelete");
const cancelDelete = document.getElementById("cancelDelete");
confirmDelete.onclick = function () {
deleteTask(task, li);
modal.style.display = "none";
};
cancelDelete.onclick = function () {
modal.style.display = "none";
};
window.onclick = function (event) {
if (event.target == modal) {
modal.style.display = "none";
}
};
}
function toggleTaskCompletion(task, li) {
task.completed = !task.completed;
li.classList.toggle("completed");
updateProductivityScore();
}
function editTask(task, li) {
const newText = prompt("Edit task:", task.text);
if (newText !== null) {
task.text = newText.trim();
li.querySelector(".task-text").textContent = task.text;
}
}
function deleteTask(task, li) {
const index = tasks.indexOf(task);
if (index > -1) {
tasks.splice(index, 1);
li.remove();
updateProductivityScore();
}
}
function toggleCategory(li) {
const categorySpan = li.querySelector(".task-category");
categorySpan.style.display =
categorySpan.style.display === "none" ? "inline" : "none";
}
function updateCategoryDropdown() {
categoryDropdown.innerHTML = '<option value="">Select a category</option>';
taskCategories.forEach((category) => {
const option = document.createElement("option");
option.value = category;
option.textContent = category;
categoryDropdown.appendChild(option);
});
}
function mapAllTasks() {
mapTasksToTimer(tasks);
mapTasksToLog(tasks);
}
function customMapTasks() {
const selectedTasks = Array.from(taskList.querySelectorAll("li")).filter(
(li) => li.querySelector(".complete-task").disabled
);
mapTasksToTimer(
selectedTasks.map((li) =>
tasks.find((t) => t.text === li.querySelector(".task-text").textContent)
)
);
mapTasksToLog(
selectedTasks.map((li) =>
tasks.find((t) => t.text === li.querySelector(".task-text").textContent)
)
);
}
function mapTasksToTimer(tasks) {
const timerTaskSelect = document.getElementById("timer-task-select");
timerTaskSelect.innerHTML = "";
tasks.forEach((task) => {
const option = document.createElement("option");
option.value = task.text;
option.textContent = task.text;
timerTaskSelect.appendChild(option);
});
}
function mapTasksToLog(tasks) {
// Implement the function to map tasks to log (timeline)
}
function updateProductivityScore() {
const totalTasks = tasks.length;
const completedTasks = tasks.filter((task) => task.completed).length;
const score = totalTasks ? (completedTasks / totalTasks) * 100 : 0;
document.getElementById("score").textContent = Math.round(score);
document.querySelector(".progress").style.width = `${Math.round(score)}%`;
}
// Timer functionality
let timerInterval;
let timerStartTime;
let timerTasks = [];
function formatTime(seconds) {
const hours = String(Math.floor(seconds / 3600)).padStart(2, "0");
const minutes = String(Math.floor((seconds % 3600) / 60)).padStart(2, "0");
const secs = String(seconds % 60).padStart(2, "0");
return `${hours}:${minutes}:${secs}`;
}
function updateTimerTaskSelect() {
const timerTaskSelect = document.getElementById("timer-task-select");
timerTaskSelect.innerHTML = "";
timerTasks.forEach((task) => {
const option = document.createElement("option");
option.value = task;
option.textContent = task;
timerTaskSelect.appendChild(option);
});
}
document.getElementById("add-timer-task").addEventListener("click", () => {
const newTimerTask = document.getElementById("new-timer-task").value.trim();
if (newTimerTask) {
timerTasks.push(newTimerTask);
updateTimerTaskSelect();
document.getElementById("new-timer-task").value = "";
}
});
document.getElementById("start-timer").addEventListener("click", () => {
const timerTask = document.getElementById("timer-task-select").value;
if (timerTask) {
timerStartTime = Date.now();
clearInterval(timerInterval);
timerInterval = setInterval(updateTimer, 1000);
document.getElementById("timer-display").classList.add("active");
}
});
document.getElementById("pause-timer").addEventListener("click", () => {
clearInterval(timerInterval);
document.getElementById("timer-display").classList.remove("active");
});
document.getElementById("stop-timer").addEventListener("click", () => {
clearInterval(timerInterval);
document.getElementById("timer-display").textContent = "00:00:00";
document.getElementById("timer-display").classList.remove("active");
});
function updateTimer() {
const elapsedSeconds = Math.floor((Date.now() - timerStartTime) / 1000);
document.getElementById("timer-display").textContent =
formatTime(elapsedSeconds);
}
function mapTasksToTimer(tasks) {
timerTasks = [...new Set([...timerTasks, ...tasks.map((task) => task.text)])];
updateTimerTaskSelect();
}
// Pomodoro Timer functionality
let pomodoroInterval;
let pomodoroTime = 25 * 60;
function updatePomodoroDisplay() {
document.getElementById("pomodoro-display").textContent =
formatTime(pomodoroTime);
}
document.getElementById("start-pomodoro").addEventListener("click", () => {
pomodoroInterval = setInterval(() => {
if (pomodoroTime > 0) {
pomodoroTime--;
updatePomodoroDisplay();
} else {
clearInterval(pomodoroInterval);
}
}, 1000);
});
document.getElementById("reset-pomodoro").addEventListener("click", () => {
clearInterval(pomodoroInterval);
pomodoroTime = 25 * 60;
updatePomodoroDisplay();
});
// Daily Log functionality
document.getElementById("add-log-task").addEventListener("click", () => {
const logTask = document.getElementById("new-log-task").value.trim();
const startTime = document.getElementById("log-start-time").value;
const endTime = document.getElementById("log-end-time").value;
if (logTask && startTime && endTime) {
const timelineItem = document.createElement("div");
timelineItem.className = "timeline-item";
timelineItem.innerHTML = `<span class="timeline-time">${startTime} - ${endTime}</span> ${logTask}`;
document.getElementById("daily-log-timeline").appendChild(timelineItem);
}
});
// Links functionality
document.getElementById("add-link").addEventListener("click", () => {
const linkInputs = document.getElementById("link-inputs");
const linkInput = document.createElement("input");
linkInput.type = "url";
linkInput.placeholder = "Enter a link";
linkInputs.appendChild(linkInput);
linkInputs.appendChild(document.createElement("br"));
});
document.getElementById("add-more-link").addEventListener("click", () => {
const linkList = document.getElementById("link-list");
Array.from(document.querySelectorAll("#link-inputs input")).forEach(
(input) => {
if (input.value.trim()) {
const li = document.createElement("li");
li.innerHTML = `<a href="${input.value}" target="_blank">${input.value}</a>`;
linkList.appendChild(li);
input.value = "";
}
}
);
});
document.getElementById("copy-links-tomorrow").addEventListener("click", () => {
// Implement copy links to tomorrow functionality
});
document.getElementById("copy-links-week").addEventListener("click", () => {
// Implement copy links to week functionality
});
document
.getElementById("copy-links-next-week")
.addEventListener("click", () => {
// Implement copy links to next week functionality
});
// Daily Learnings functionality
document.getElementById("save-learning").addEventListener("click", () => {
const learningInput = document.getElementById("learning-input").value.trim();
if (learningInput) {
alert("Learning saved!");
document.getElementById("learning-input").value = "";
}
});
document.getElementById("view-learnings").addEventListener("click", () => {
// Implement view learnings functionality
});
// Toggle Dark Theme functionality
document.getElementById("toggle-theme").addEventListener("click", () => {
document.body.classList.toggle("dark-theme");
if (document.body.classList.contains("dark-theme")) {
localStorage.setItem("theme", "dark");
document.getElementById("toggle-theme").innerText = "Toggle Light Theme";
} else {
localStorage.setItem("theme", "light");
document.getElementById("toggle-theme").innerText = "Toggle Dark Theme";
}
});
//getting user prefernce of theme
if (localStorage.getItem("theme") === "dark") {
document.body.classList.add("dark-theme");
document.getElementById("toggle-theme").innerText = `Toggle Light Theme`;
} else {
document.getElementById("toggle-theme").innerText = `Toggle Dark Theme`;
}
// Task Reports functionality
const taskCompletionChart = document.getElementById("task-completion-chart");
const timeSpentChart = document.getElementById("time-spent-chart");
// Define colors directly or use CSS variables correctly
const colorGreen = "#4caf50"; // Example color for completed tasks
const colorRed = "#f44336"; // Example color for pending tasks
const colorBlue = "#2196f3"; // Example color for time spent on tasks
const colorLightGray = "#e0e0e0"; // Example color for free time
// Task Completion Chart
new Chart(taskCompletionChart, {
type: "bar",
data: {
labels: ["Completed", "Pending"],
datasets: [
{
label: "Task Completion",
data: [
tasks.filter((task) => task.completed).length,
tasks.length - tasks.filter((task) => task.completed).length,
],
backgroundColor: [colorGreen, colorRed], // Use defined color values
},
],
},
options: {
responsive: true,
maintainAspectRatio: false,
},
});
// Time Spent Chart
new Chart(timeSpentChart, {
type: "pie",
data: {
labels: ["Time Spent on Tasks", "Free Time"],
datasets: [
{
label: "Time Spent",
data: [
tasks.length * 30, // Example time spent on tasks (e.g., 30 minutes per task)
1440 - tasks.length * 30, // Remaining time in a day
],
backgroundColor: [colorBlue, colorLightGray], // Use defined color values
},
],
},
options: {
responsive: true,
maintainAspectRatio: false,
},
});
window.onscroll = function () {
let backToTopButton = document.getElementById("back-to-top");
if (
document.body.scrollTop > 300 ||
document.documentElement.scrollTop > 300
) {
backToTopButton.style.display = "block";
} else {
backToTopButton.style.display = "none";
}
};
document.getElementById("back-to-top").addEventListener("click", function (e) {
e.preventDefault(); // Prevent default anchor click behavior
window.scrollTo({ top: 0, behavior: "smooth" });
});