-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocument.js
More file actions
1294 lines (1118 loc) · 59.9 KB
/
document.js
File metadata and controls
1294 lines (1118 loc) · 59.9 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
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
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
document.addEventListener('DOMContentLoaded', function() {
// Core functionality
const darkModeToggle = document.getElementById('dark-mode-toggle');
const darkModeIcon = darkModeToggle.querySelector('i');
const historySection = document.querySelector('.history-section');
const toggleHistoryBtn = document.getElementById('toggle-history');
const clearHistoryBtn = document.getElementById('clear-history');
const historyItems = document.getElementById('history-items');
const notification = document.getElementById('notification');
const notificationText = document.getElementById('notification-text');
const moodOptions = document.querySelectorAll('.mood-option');
const currentQuote = document.getElementById('current-quote');
const currentMoodElement = document.getElementById('current-mood');
const todoForm = document.getElementById('todo-form');
const todoInput = document.getElementById('todo-input');
const todoList = document.getElementById('todo-list');
const timerDisplay = document.getElementById('timer-display');
const startBtn = document.getElementById('start-timer');
const resetBtn = document.getElementById('reset-timer');
const progressBar = document.getElementById('progress-bar');
const timerModes = document.querySelectorAll('.timer-mode');
const focusSessionsElement = document.getElementById('focus-sessions');
// New features elements
const moodNote = document.getElementById('mood-note');
const saveNoteBtn = document.getElementById('save-note');
const deleteNoteBtn = document.getElementById('delete-note');
const vibeTitle = document.getElementById('vibe-title');
const vibeMessage = document.getElementById('vibe-message');
const reminderBtn = document.getElementById('reminder-btn');
const exportTxtBtn = document.getElementById('export-txt');
const exportJsonBtn = document.getElementById('export-json');
const todayFocusTimeElement = document.getElementById('today-focus-time');
const helpToggle = document.getElementById('help-toggle');
const helpModal = document.getElementById('help-modal');
const closeHelp = document.getElementById('close-help');
const feedbackBtn = document.getElementById('feedback-btn');
const feedbackModal = document.getElementById('feedback-modal');
const closeFeedback = document.getElementById('close-feedback');
const feedbackForm = document.getElementById('feedback-form');
const resetConfirmModal = document.getElementById('reset-confirm-modal');
const cancelResetBtn = document.getElementById('cancel-reset');
const confirmResetBtn = document.getElementById('confirm-reset');
// New task management elements
const prioritySelect = document.getElementById('priority-select');
const categorySelect = document.getElementById('category-select');
const dueDateInput = document.getElementById('due-date');
const taskSearch = document.getElementById('task-search');
const sortSelect = document.getElementById('sort-select');
// State variables
let isDarkMode = localStorage.getItem('darkMode') === 'enabled';
let moodStats = {
happy: 0,
calm: 0,
focused: 0,
stressed: 0,
creative: 0
};
let moodHistoryData = [];
let focusSessions = 0;
let todos = [];
let currentFilter = 'all';
let timer = null;
let timeLeft = 25 * 60;
let timerMode = 'focus';
const timerDurations = {
focus: 25 * 60,
'short-break': 5 * 60,
'long-break': 15 * 60
};
let focusTime = 0;
let isRunning = false;
let focusTimeData = {};
let currentNote = '';
let searchQuery = '';
let sortBy = 'priority';
// Set min date for due date input to today
const today = new Date().toISOString().split('T')[0];
dueDateInput.min = today;
// Notification system
function showNotification(message) {
notificationText.textContent = message;
notification.classList.add('show');
setTimeout(() => {
notification.classList.remove('show');
}, 3000);
}
// Dark mode functionality
function toggleDarkMode() {
isDarkMode = !isDarkMode;
document.body.classList.toggle('dark-mode', isDarkMode);
if (isDarkMode) {
darkModeIcon.classList.remove('fa-moon');
darkModeIcon.classList.add('fa-sun');
localStorage.setItem('darkMode', 'enabled');
} else {
darkModeIcon.classList.remove('fa-sun');
darkModeIcon.classList.add('fa-moon');
localStorage.setItem('darkMode', 'disabled');
}
initCharts();
showNotification(`Dark mode ${isDarkMode ? 'enabled' : 'disabled'}`);
}
if (isDarkMode) {
document.body.classList.add('dark-mode');
darkModeIcon.classList.remove('fa-moon');
darkModeIcon.classList.add('fa-sun');
}
darkModeToggle.addEventListener('click', toggleDarkMode);
// Mood history functionality
function toggleHistory() {
historyItems.classList.toggle('hidden-items');
const isHidden = historyItems.classList.contains('hidden-items');
if (isHidden) {
toggleHistoryBtn.innerHTML = '<i class="fas fa-eye"></i> Show History';
} else {
toggleHistoryBtn.innerHTML = '<i class="fas fa-eye-slash"></i> Hide History';
}
localStorage.setItem('historyHidden', isHidden);
}
function clearHistory() {
if (confirm("Are you sure you want to clear your mood history? This cannot be undone.")) {
moodHistoryData = [];
updateMoodHistory();
localStorage.setItem('moodHistory', JSON.stringify(moodHistoryData));
showNotification('History cleared!');
}
}
toggleHistoryBtn.addEventListener('click', toggleHistory);
clearHistoryBtn.addEventListener('click', clearHistory);
const isHistoryHidden = localStorage.getItem('historyHidden') === 'true';
if (isHistoryHidden) {
historyItems.classList.add('hidden-items');
toggleHistoryBtn.innerHTML = '<i class="fas fa-eye"></i> Show History';
}
// Mood tracker functionality
const quotes = {
happy: [
"Every day may not be good, but there's something good in every day.",
"Happiness is not by chance, but by choice.",
"The joy we feel has little to do with the circumstances of our lives and everything to do with the focus of our lives."
],
calm: [
"Peace is the result of retraining your mind to process life as it is, not as you think it should be.",
"Calm mind brings inner strength and self-confidence.",
"In the midst of movement and chaos, keep stillness inside of you."
],
focused: [
"Concentrate all your thoughts upon the work at hand. The sun's rays do not burn until brought to a focus.",
"The successful warrior is the average man, with laser-like focus.",
"Focus on being productive instead of busy."
],
stressed: [
"You don't have to control your thoughts. You just have to stop letting them control you.",
"It's not the load that breaks you down, it's the way you carry it.",
"Stress is caused by being 'here' but wanting to be 'there'."
],
creative: [
"Creativity is intelligence having fun.",
"The desire to create is one of the deepest yearnings of the human soul.",
"Creativity is piercing the mundane to find the marvelous."
]
};
const moodLabels = {
happy: 'Happy',
calm: 'Calm',
focused: 'Focused',
stressed: 'Stressed',
creative: 'Creative'
};
const moodEmojis = {
happy: '😊',
calm: '😌',
focused: '🧠',
stressed: '😫',
creative: '🎨'
};
const affirmations = [
"You are capable of amazing things.",
"Believe you can and you're halfway there.",
"Every day is a fresh start.",
"You have the power to create change.",
"Your potential is endless.",
"Progress, not perfection.",
"You are stronger than you think.",
"Small steps still move you forward.",
"Your focus determines your reality.",
"You've survived 100% of your bad days.",
"Challenges are opportunities for growth.",
"Your mind is a powerful tool.",
"You are in control of your thoughts.",
"Productivity starts with a positive mindset.",
"You have everything you need to succeed.",
"Every effort counts, no matter how small.",
"Your best work is ahead of you.",
"Focus on progress, not perfection.",
"You are building your future right now.",
"Clarity comes from action, not thought.",
"Your potential is limitless.",
"Success is the sum of small efforts.",
"You are the architect of your destiny.",
"Productivity is about consistency.",
"Every moment is a new beginning.",
"You are more resilient than you realize.",
"Focus creates possibilities.",
"Your efforts will pay off.",
"You have the strength to overcome.",
"Great things take time and patience."
];
function setMood(mood) {
// Add fade animation
document.body.classList.add('fade-out');
setTimeout(() => {
moodOptions.forEach(option => {
option.classList.remove('active');
if (option.dataset.mood === mood) {
option.classList.add('active');
}
});
const moodClasses = ['happy', 'calm', 'focused', 'stressed', 'creative'];
moodClasses.forEach(cls => {
document.body.classList.remove(cls);
});
document.body.classList.add(mood);
currentMoodElement.textContent = moodLabels[mood];
const moodQuotes = quotes[mood];
const randomQuote = moodQuotes[Math.floor(Math.random() * moodQuotes.length)];
currentQuote.textContent = randomQuote;
moodStats[mood]++;
const historyEntry = {
mood: mood,
label: moodLabels[mood],
emoji: moodEmojis[mood],
timestamp: new Date(),
dateString: new Date().toLocaleString(),
note: currentNote
};
moodHistoryData.unshift(historyEntry);
if (moodHistoryData.length > 12) {
moodHistoryData = moodHistoryData.slice(0, 12);
}
updateMoodHistory();
updateMoodChart();
updateStatsChart();
localStorage.setItem('currentMood', mood);
localStorage.setItem('moodStats', JSON.stringify(moodStats));
localStorage.setItem('moodHistory', JSON.stringify(moodHistoryData));
showNotification(`Mood set to ${moodLabels[mood]}!`);
updateVibeMeter();
// Remove fade animation
document.body.classList.remove('fade-out');
}, 150);
}
function updateMoodHistory() {
historyItems.innerHTML = '';
if (moodHistoryData.length === 0) {
historyItems.innerHTML = '<div class="no-history">No mood history recorded yet. Select moods to start tracking!</div>';
return;
}
moodHistoryData.forEach(entry => {
const item = document.createElement('div');
item.className = 'history-item';
item.style.position = 'relative';
item.innerHTML = `
<div class="history-mood">${entry.emoji}</div>
<div class="history-label">${entry.label}</div>
<div class="history-date">${new Date(entry.timestamp).toLocaleDateString()}</div>
<div class="history-date">${new Date(entry.timestamp).toLocaleTimeString([], {hour: '2-digit', minute:'2-digit'})}</div>
${entry.note ? '<div class="note-indicator">✏️</div>' : ''}
`;
if (entry.note) {
const notePopup = document.createElement('div');
notePopup.className = 'note-popup';
notePopup.textContent = entry.note;
item.appendChild(notePopup);
}
historyItems.appendChild(item);
});
if (localStorage.getItem('historyHidden') === 'true') {
historyItems.classList.add('hidden-items');
}
}
function loadMoodStats() {
const savedStats = localStorage.getItem('moodStats');
if (savedStats) {
Object.assign(moodStats, JSON.parse(savedStats));
}
const savedHistory = localStorage.getItem('moodHistory');
if (savedHistory) {
moodHistoryData = JSON.parse(savedHistory);
moodHistoryData.forEach(entry => {
entry.timestamp = new Date(entry.timestamp);
});
updateMoodHistory();
}
const savedMood = localStorage.getItem('currentMood');
if (savedMood) {
setMood(savedMood);
} else {
updateMoodChart();
}
}
moodOptions.forEach(option => {
option.addEventListener('click', () => {
setMood(option.dataset.mood);
});
});
// To-Do list functionality
function renderTodos() {
todoList.innerHTML = '';
let filteredTodos = currentFilter === 'all'
? [...todos]
: todos.filter(todo => todo.mood === currentFilter);
// Apply search filter
if (searchQuery) {
filteredTodos = filteredTodos.filter(todo =>
todo.text.toLowerCase().includes(searchQuery.toLowerCase())
);
}
// Apply sorting
switch(sortBy) {
case 'priority':
filteredTodos.sort((a, b) => {
const priorityOrder = { high: 1, medium: 2, low: 3 };
return priorityOrder[a.priority] - priorityOrder[b.priority];
});
break;
case 'dueDate':
filteredTodos.sort((a, b) => {
if (!a.dueDate && !b.dueDate) return 0;
if (!a.dueDate) return 1;
if (!b.dueDate) return -1;
return new Date(a.dueDate) - new Date(b.dueDate);
});
break;
case 'creation':
filteredTodos.sort((a, b) => new Date(b.createdAt) - new Date(a.createdAt));
break;
case 'alphabetical':
filteredTodos.sort((a, b) => a.text.localeCompare(b.text));
break;
}
if (filteredTodos.length === 0) {
const emptyMessage = document.createElement('li');
emptyMessage.className = 'empty-state';
emptyMessage.textContent = currentFilter === 'all'
? 'No tasks found. Try changing your search or filter.'
: `No ${currentFilter} tasks. Try changing the filter.`;
todoList.appendChild(emptyMessage);
return;
}
filteredTodos.forEach((todo, index) => {
const todoItem = document.createElement('li');
todoItem.className = `todo-item ${isTaskOverdue(todo) ? 'overdue' : ''}`;
// Priority indicator
const priorityIndicator = document.createElement('div');
priorityIndicator.className = `priority-indicator priority-${todo.priority}`;
const checkbox = document.createElement('input');
checkbox.type = 'checkbox';
checkbox.checked = todo.completed;
checkbox.className = 'complete-btn';
checkbox.addEventListener('change', () => toggleTodo(index));
const todoText = document.createElement('div');
todoText.className = `todo-text ${todo.completed ? 'completed' : ''}`;
const taskMain = document.createElement('div');
taskMain.className = 'task-main';
const taskText = document.createElement('span');
taskText.textContent = todo.text;
const moodEmoji = document.createElement('span');
moodEmoji.textContent = moodEmojis[todo.mood] || '';
taskMain.appendChild(taskText);
taskMain.appendChild(moodEmoji);
const taskMeta = document.createElement('div');
taskMeta.className = 'task-meta';
// Priority label
const priorityLabel = document.createElement('span');
priorityLabel.className = `priority-label priority-${todo.priority}-label`;
priorityLabel.textContent = todo.priority.charAt(0).toUpperCase() + todo.priority.slice(1);
// Category
const categorySpan = document.createElement('span');
categorySpan.className = 'task-category';
categorySpan.textContent = todo.category;
// Due date
const dueDateSpan = document.createElement('span');
dueDateSpan.className = `task-due ${isTaskOverdue(todo) ? 'overdue' : ''}`;
if (todo.dueDate) {
const dueIcon = document.createElement('i');
dueIcon.className = 'far fa-calendar-alt';
const dueText = document.createElement('span');
dueText.textContent = formatDate(todo.dueDate);
dueDateSpan.appendChild(dueIcon);
dueDateSpan.appendChild(dueText);
}
taskMeta.appendChild(priorityLabel);
taskMeta.appendChild(categorySpan);
taskMeta.appendChild(dueDateSpan);
todoText.appendChild(taskMain);
todoText.appendChild(taskMeta);
const deleteBtn = document.createElement('button');
deleteBtn.className = 'action-btn delete-btn';
deleteBtn.innerHTML = '<i class="fas fa-trash"></i>';
deleteBtn.addEventListener('click', () => removeTodo(index));
const todoActions = document.createElement('div');
todoActions.className = 'todo-actions';
todoActions.appendChild(deleteBtn);
todoItem.appendChild(priorityIndicator);
todoItem.appendChild(checkbox);
todoItem.appendChild(todoText);
todoItem.appendChild(todoActions);
todoList.appendChild(todoItem);
});
updateStats();
}
function isTaskOverdue(todo) {
if (!todo.dueDate) return false;
if (todo.completed) return false;
const today = new Date();
const dueDate = new Date(todo.dueDate);
dueDate.setHours(23, 59, 59, 999); // End of day
return dueDate < today;
}
function formatDate(dateString) {
const date = new Date(dateString);
return date.toLocaleDateString('en-US', {
month: 'short',
day: 'numeric',
year: date.getFullYear() !== new Date().getFullYear() ? 'numeric' : undefined
});
}
function addTodo(e) {
e.preventDefault();
const text = todoInput.value.trim();
if (text === '') return;
const bodyClasses = document.body.classList;
const currentMood = ['happy', 'calm', 'focused', 'stressed', 'creative']
.find(cls => bodyClasses.contains(cls)) || 'focused';
const today = new Date().toISOString();
const newTodo = {
text,
completed: false,
mood: currentMood,
priority: prioritySelect.value,
category: categorySelect.value,
dueDate: dueDateInput.value || null,
createdAt: today,
completedAt: null
};
todos.push(newTodo);
saveTodos();
todoInput.value = '';
dueDateInput.value = '';
prioritySelect.value = 'medium';
categorySelect.value = 'personal';
renderTodos();
updateStats();
showNotification('Task added!');
}
function toggleTodo(index) {
todos[index].completed = !todos[index].completed;
if (todos[index].completed) {
todos[index].completedAt = new Date().toISOString();
} else {
todos[index].completedAt = null;
}
saveTodos();
renderTodos();
updateStats();
}
function removeTodo(index) {
todos.splice(index, 1);
saveTodos();
renderTodos();
updateStats();
showNotification('Task removed!');
}
function saveTodos() {
localStorage.setItem('todos', JSON.stringify(todos));
}
function setupFilters() {
document.getElementById('filter-all').addEventListener('click', () => {
currentFilter = 'all';
renderTodos();
});
document.getElementById('filter-happy').addEventListener('click', () => {
currentFilter = 'happy';
renderTodos();
});
document.getElementById('filter-calm').addEventListener('click', () => {
currentFilter = 'calm';
renderTodos();
});
document.getElementById('filter-focused').addEventListener('click', () => {
currentFilter = 'focused';
renderTodos();
});
document.getElementById('filter-stressed').addEventListener('click', () => {
currentFilter = 'stressed';
renderTodos();
});
document.getElementById('filter-creative').addEventListener('click', () => {
currentFilter = 'creative';
renderTodos();
});
}
// Focus timer functionality
function updateTimerDisplay() {
const minutes = Math.floor(timeLeft / 60).toString().padStart(2, '0');
const seconds = (timeLeft % 60).toString().padStart(2, '0');
timerDisplay.textContent = `${minutes}:${seconds}`;
const total = timerDurations[timerMode];
progressBar.style.width = `${((total - timeLeft) / total) * 100}%`;
}
function startTimer() {
if (timer) return;
if (timerMode === 'focus' && !isRunning) {
focusSessions++;
focusSessionsElement.textContent = focusSessions;
}
isRunning = true;
timer = setInterval(() => {
timeLeft--;
if (timerMode === 'focus') {
focusTime++;
const today = new Date().toISOString().split('T')[0];
if (!focusTimeData[today]) {
focusTimeData[today] = 0;
}
focusTimeData[today]++;
localStorage.setItem('focusTimeData', JSON.stringify(focusTimeData));
}
updateTimerDisplay();
updateStats();
if (timeLeft <= 0) {
clearInterval(timer);
timer = null;
isRunning = false;
try {
const audio = new Audio('data:audio/mp3;base64,SUQzBAAAAAABEVRYWFgAAAAtAAADY29tbWVudABCaWdTb3VuZEJhbmsuY29tIC8gTGFTb25vdGhlcXVlLm9yZwBURU5DAAAAHQAAA1N3aXRjaCBQbHVzIMKpIE5DSCBTb2Z0d2FyZQBUSVQyAAAABgAAAzIyMzUAVFNTRQAAAA8AAANMYXZmNTcuODMuMTAwAAAAAAAAAAAAAAD/80DEAAAAA0gAAAAATEFNRTMuMTAwVVVVVVVVVVVVVUxBTUUzLjEwMFVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVf/zQsRbAAADSAAAAABVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVf/zQMSkAAADSAAAAABVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV');
audio.volume = 0.3;
audio.play();
} catch (e) {
console.log("Audio notification failed", e);
}
const message = timerMode === 'focus'
? 'Focus session completed! Time for a break.'
: 'Break time over! Ready for next focus session?';
showNotification(message);
if (timerMode === 'focus') {
document.querySelector('.timer-mode[data-mode="short-break"]').click();
}
}
}, 1000);
startBtn.innerHTML = '<i class="fas fa-pause"></i> Pause';
startBtn.onclick = pauseTimer;
showNotification('Timer started!');
}
function pauseTimer() {
clearInterval(timer);
timer = null;
isRunning = false;
startBtn.innerHTML = '<i class="fas fa-play"></i> Start';
startBtn.onclick = startTimer;
showNotification('Timer paused!');
}
function resetTimer() {
resetConfirmModal.classList.add('active');
}
function performReset() {
clearInterval(timer);
timer = null;
isRunning = false;
timeLeft = timerDurations[timerMode];
updateTimerDisplay();
startBtn.innerHTML = '<i class="fas fa-play"></i> Start';
startBtn.onclick = startTimer;
resetConfirmModal.classList.remove('active');
showNotification('Timer reset!');
}
timerModes.forEach(mode => {
mode.addEventListener('click', () => {
if (mode.classList.contains('active')) return;
timerModes.forEach(m => m.classList.remove('active'));
mode.classList.add('active');
const newMode = mode.dataset.mode;
const wasRunning = isRunning;
if (timer) {
clearInterval(timer);
timer = null;
}
timerMode = newMode;
timeLeft = timerDurations[newMode];
updateTimerDisplay();
if (wasRunning) {
startTimer();
}
});
});
startBtn.addEventListener('click', startTimer);
resetBtn.addEventListener('click', resetTimer);
// Charts functionality
let moodChart, statsChart;
function getLast7DaysLabels() {
const days = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
const labels = [];
const today = new Date();
for (let i = 6; i >= 0; i--) {
const date = new Date();
date.setDate(today.getDate() - i);
labels.push(days[date.getDay()]);
}
return labels;
}
function getMoodScoresForWeek() {
const scores = [0, 0, 0, 0, 0, 0, 0];
const today = new Date();
const labels = getLast7DaysLabels();
if (moodHistoryData.length === 0) return scores;
moodHistoryData.forEach(entry => {
const entryDate = new Date(entry.timestamp);
const diffTime = Math.abs(today - entryDate);
const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24));
if (diffDays <= 7) {
const dayIndex = 7 - diffDays;
if (dayIndex >= 0 && dayIndex < 7) {
switch(entry.mood) {
case 'happy': scores[dayIndex] += 5; break;
case 'calm': scores[dayIndex] += 4; break;
case 'focused': scores[dayIndex] += 5; break;
case 'stressed': scores[dayIndex] += 2; break;
case 'creative': scores[dayIndex] += 4; break;
default: scores[dayIndex] += 3;
}
}
}
});
for (let i = 0; i < scores.length; i++) {
if (scores[i] > 0) {
scores[i] = Math.min(100, Math.round(scores[i] * 3));
}
}
return scores;
}
function getTasksCompletedLast7Days() {
const tasksByDay = [0, 0, 0, 0, 0, 0, 0];
const today = new Date();
if (todos.length === 0) return tasksByDay;
todos.forEach(todo => {
if (todo.completed && todo.completedAt) {
const completedDate = new Date(todo.completedAt);
const diffTime = Math.abs(today - completedDate);
const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24));
if (diffDays <= 7) {
const dayIndex = 7 - diffDays;
if (dayIndex >= 0 && dayIndex < 7) {
tasksByDay[dayIndex]++;
}
}
}
});
return tasksByDay;
}
function getFocusTimeLast7Days() {
const minutesByDay = [0, 0, 0, 0, 0, 0, 0];
const today = new Date();
if (!focusTimeData || Object.keys(focusTimeData).length === 0)
return minutesByDay;
const dates = [];
for (let i = 0; i < 7; i++) {
const date = new Date();
date.setDate(today.getDate() - i);
dates.push(date.toISOString().split('T')[0]);
}
dates.forEach((date, index) => {
if (focusTimeData[date]) {
minutesByDay[6 - index] = Math.floor(focusTimeData[date] / 60);
}
});
return minutesByDay;
}
function initCharts() {
const moodScores = getMoodScoresForWeek();
const tasksCompleted = getTasksCompletedLast7Days();
const focusTimeData = getFocusTimeLast7Days();
const labels = getLast7DaysLabels();
const textColor = isDarkMode ? '#e2e8f0' : '#1e293b';
const gridColor = isDarkMode ? 'rgba(255, 255, 255, 0.1)' : 'rgba(0, 0, 0, 0.1)';
// Mood Chart
const moodCtx = document.getElementById('moodChart').getContext('2d');
if (moodChart) moodChart.destroy();
moodChart = new Chart(moodCtx, {
type: 'doughnut',
data: {
labels: ['Happy', 'Calm', 'Focused', 'Stressed', 'Creative'],
datasets: [{
label: 'Mood Count',
data: Object.values(moodStats),
backgroundColor: [
'#f59e0b',
'#14b8a6',
'#6366f1',
'#ef4444',
'#8b5cf6'
],
borderColor: isDarkMode ? '#1e293b' : '#ffffff',
borderWidth: 2
}]
},
options: {
responsive: true,
maintainAspectRatio: false,
plugins: {
legend: {
position: 'bottom',
labels: {
padding: 20,
usePointStyle: true,
pointStyle: 'circle',
font: {
size: 12
},
color: textColor
}
},
tooltip: {
callbacks: {
label: function(context) {
return `${context.label}: ${context.raw} times`;
}
}
}
}
}
});
// Stats Chart
const statsCtx = document.getElementById('statsChart').getContext('2d');
if (statsChart) statsChart.destroy();
statsChart = new Chart(statsCtx, {
type: 'line',
data: {
labels: labels,
datasets: [{
label: 'Mood Score',
data: moodScores,
borderColor: '#6366f1',
backgroundColor: 'rgba(99, 102, 241, 0.1)',
borderWidth: 3,
tension: 0.3,
fill: true,
pointBackgroundColor: '#6366f1',
pointRadius: 5,
pointHoverRadius: 8
}]
},
options: {
responsive: true,
maintainAspectRatio: false,
scales: {
y: {
beginAtZero: true,
max: 100,
grid: {
color: gridColor
},
ticks: {
color: textColor,
callback: function(value) {
return value + '%';
}
}
},
x: {
grid: {
color: gridColor
},
ticks: {
color: textColor
}
}
},
plugins: {
legend: {
labels: {
color: textColor
}
},
tooltip: {
callbacks: {
label: function(context) {
return `Mood Score: ${context.parsed.y}%`;
}
}
}
}
}
});
// Graph tabs functionality
const graphTabs = document.querySelectorAll('.graph-tab');
graphTabs.forEach(tab => {
tab.addEventListener('click', () => {
graphTabs.forEach(t => t.classList.remove('active'));
tab.classList.add('active');
updateStatsChart(tab.dataset.graph);
});
});
}
function updateMoodChart() {
if (moodChart) {
moodChart.data.datasets[0].data = Object.values(moodStats);
moodChart.update();
}
}
function updateStatsChart(type = 'mood') {
if (!statsChart) return;
const labels = getLast7DaysLabels();
const textColor = isDarkMode ? '#e2e8f0' : '#1e293b';
const gridColor = isDarkMode ? 'rgba(255, 255, 255, 0.1)' : 'rgba(0, 0, 0, 0.1)';
statsChart.data.labels = labels;
if (type === 'tasks') {
const tasksCompleted = getTasksCompletedLast7Days();
statsChart.data.datasets[0].label = 'Tasks Completed';
statsChart.data.datasets[0].data = tasksCompleted;
statsChart.data.datasets[0].borderColor = '#84cc16';
statsChart.data.datasets[0].backgroundColor = 'rgba(132, 204, 22, 0.1)';
statsChart.options.scales.y.max = Math.max(10, ...tasksCompleted) + 2;
statsChart.options.plugins.tooltip.callbacks.label = function(context) {
return `Tasks: ${context.parsed.y}`;
};
}
else if (type === 'mood') {
const moodScores = getMoodScoresForWeek();
statsChart.data.datasets[0].label = 'Mood Score';
statsChart.data.datasets[0].data = moodScores;
statsChart.data.datasets[0].borderColor = '#6366f1';
statsChart.data.datasets[0].backgroundColor = 'rgba(99, 102, 241, 0.1)';
statsChart.options.scales.y.max = 100;
statsChart.options.plugins.tooltip.callbacks.label = function(context) {
return `Mood Score: ${context.parsed.y}%`;
};
}
else if (type === 'time') {
const focusMinutes = getFocusTimeLast7Days();
statsChart.data.datasets[0].label = 'Focus Time (min)';
statsChart.data.datasets[0].data = focusMinutes;
statsChart.data.datasets[0].borderColor = '#ec4899';
statsChart.data.datasets[0].backgroundColor = 'rgba(236, 72, 153, 0.1)';
statsChart.options.scales.y.max = Math.max(60, ...focusMinutes) + 20;
statsChart.options.plugins.tooltip.callbacks.label = function(context) {
return `Focus Time: ${context.parsed.y} min`;
};
}
statsChart.options.scales.y.ticks.color = textColor;
statsChart.options.scales.x.ticks.color = textColor;
statsChart.options.scales.y.grid.color = gridColor;
statsChart.options.scales.x.grid.color = gridColor;
statsChart.options.plugins.legend.labels.color = textColor;
statsChart.update();
}
function updateStats() {
const completedTasks = todos.filter(todo => todo.completed).length;
document.getElementById('completed-tasks').textContent = completedTasks;
const today = new Date().toISOString().split('T')[0];