-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
1479 lines (1363 loc) · 64.4 KB
/
Copy pathscript.js
File metadata and controls
1479 lines (1363 loc) · 64.4 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
// Message alternatives storage - comprehensive collection of motivational messages
const MESSAGE_ALTERNATIVES = {
general: {
default: [
["You're doing amazing! 🌟", "You're incredible! ✨", "You're fantastic! 💫", "You're outstanding! 🎯"],
["Keep up the great work! 💪", "You're crushing it! 🔥", "Amazing progress! 🚀", "Outstanding effort! ⚡"],
["Every day counts! 🎯", "Each moment matters! ⏰", "Progress adds up! 📈", "Small steps, big results! 🌱"],
["You've got this! 🚀", "You're unstoppable! 💥", "Nothing can stop you! 🌪️", "You're a force! ⚡"],
["Consistency is key! 🔑", "Steady wins the race! 🏃", "Persistence pays off! 💰", "Keep going strong! 💪"],
["Stay strong! 💎", "You're resilient! 🛡️", "Inner strength shines! ✨", "Tough and determined! 🔥"],
["You're unstoppable! ⚡", "Nothing holds you back! 🌊", "Unbreakable spirit! 💎", "Limitless potential! 🚀"],
["One day at a time! 🌈", "Focus on today! 🎯", "Present moment power! ⚡", "Step by step! 👣"],
["You're on fire! 🔥", "Blazing with determination! 🌟", "Ignited passion! 💥", "Burning bright! ✨"],
["Believe in yourself! ✨", "Self-confidence soars! 🚀", "Trust your journey! 🌟", "You are capable! 💪"],
["Progress over perfection! 🎨", "Growth mindset wins! 🌱", "Learning and improving! 📚", "Every attempt counts! 🎯"],
["You're a champion! 🏆", "Victory is yours! 🥇", "Triumphant spirit! 👑", "Winner mentality! 💫"]
],
milestones: {
0: [
"Great start! The first step is always the hardest! 🌱",
"Every journey begins with a single step! 🌟",
"The adventure starts now! Your story begins! 📖",
"First moments are the foundation of greatness! 🏗️",
"You've taken the leap! Courage in action! 💪"
],
1: [
"You made it one full day! Incredible! 🎉",
"24 hours of commitment! You're amazing! ⏰",
"One day down, countless more to go! 🌟",
"Your first milestone achieved! Celebration time! 🎊",
"Day one complete! The momentum builds! 🚀"
],
7: [
"One full week! You're building real habits! 🌟",
"Seven days of consistency! Habit forming! 📅",
"A week of dedication! You're committed! 💪",
"Seven days strong! The pattern emerges! 🔄",
"One week milestone! Your journey deepens! 🌈"
],
30: [
"30 days! You're a habit-building machine! 👑",
"A month of dedication! True commitment! 📆",
"Thirty days of progress! You're unstoppable! 🚀",
"One month milestone! Habits become lifestyle! 🌟",
"30 days strong! Your transformation shows! ✨"
],
100: [
"100 DAYS! You're absolutely legendary! 💯",
"A century of commitment! You're a champion! 🏆",
"100 days of excellence! Legendary status! 👑",
"Triple digits! Your perseverance inspires! 🌟",
"100 days milestone! You're a true warrior! ⚔️"
]
}
},
streak_badges: {
just_started: [
{ emoji: '🌱', text: 'Just Started!', class: 'new', messages: [
"Every journey begins with a single step! 🌟",
"First steps are the foundation of greatness! 🏗️",
"The adventure starts now! Your story begins! 📖",
"You've taken the leap! Courage in action! 💪",
"New beginnings hold infinite potential! ✨"
]},
{ emoji: '🌱', text: 'Just Started!', class: 'new', messages: [
"The spark of commitment ignites! 🔥",
"Your path unfolds before you! 🛤️",
"Every expert was once a beginner! 🌟",
"The seed of success is planted! 🌱",
"Your journey of a thousand miles begins! 👣"
]}
],
five_minutes: [
{ emoji: '🌿', text: '5+ Minutes!', class: 'new', messages: [
"Great momentum! Keep that energy flowing! 💫",
"Five minutes of focus! The flow begins! 🌊",
"Initial commitment showing results! 📈",
"First milestone achieved! You're moving! 🚀",
"Five minutes of dedication! Building steam! 💨"
]},
{ emoji: '🌿', text: '5+ Minutes!', class: 'new', messages: [
"The momentum is building! Your effort shows! 💪",
"Five minutes down, countless more ahead! ⏰",
"Early progress creates lasting habits! 🔄",
"Your dedication is already paying off! 💰",
"Five minutes of focus = infinite potential! ✨"
]}
],
fifteen_minutes: [
{ emoji: '🍀', text: '15+ Minutes!', class: 'new', messages: [
"You're building something amazing! 🌈",
"Quarter hour of commitment! Dedication shows! ⏱️",
"Fifteen minutes of focus! You're in the zone! 🎯",
"Your persistence is creating results! 📊",
"Fifteen minutes milestone! The habit forms! 🌟"
]},
{ emoji: '🍀', text: '15+ Minutes!', class: 'new', messages: [
"Building momentum with every minute! 💨",
"Fifteen minutes of excellence! Quality time! ⭐",
"Your commitment deepens! Stronger every day! 💪",
"Quarter hour achievement! Progress accelerates! 🚀",
"Fifteen minutes of pure determination! 🔥"
]}
],
thirty_minutes: [
{ emoji: '🌳', text: '30+ Minutes!', class: 'building', messages: [
"Half an hour of dedication! You're unstoppable! ⚡",
"Thirty minutes of focus! Deep work achieved! 🧠",
"Half hour milestone! Your commitment shines! ✨",
"Thirty minutes of progress! Building strength! 💪",
"Half an hour of excellence! You're crushing it! 🔥"
]},
{ emoji: '🌳', text: '30+ Minutes!', class: 'building', messages: [
"Thirty minutes of pure determination! ⏰",
"Half hour of commitment! The habit solidifies! 🏗️",
"Thirty minutes achievement! Momentum builds! 💨",
"Your dedication spans half an hour! Impressive! 👏",
"Thirty minutes of focused energy! ⚡"
]}
],
one_hour: [
{ emoji: '💪', text: '1+ Hour!', class: 'building', messages: [
"An hour of focus! Your determination shines! ✨",
"Sixty minutes of commitment! True dedication! ⏱️",
"One hour milestone! You're in deep focus! 🌊",
"An hour of progress! Building real momentum! 💨",
"Sixty minutes of excellence! You're amazing! ⭐"
]},
{ emoji: '💪', text: '1+ Hour!', class: 'building', messages: [
"One hour of pure determination! 🔥",
"Sixty minutes of focused energy! 💪",
"An hour achievement! The zone is yours! 🎯",
"One hour of commitment! Your strength shows! 🛡️",
"Sixty minutes milestone! Unstoppable force! ⚡"
]}
],
three_hours: [
{ emoji: '💫', text: '3+ Hours!', class: 'building', messages: [
"Three hours of commitment! You're a force! 🚀",
"Three hours of focus! Deep work mastery! 🧠",
"Three hours achievement! Incredible stamina! 💪",
"Three hours of dedication! Your power grows! ⚡",
"Three hours milestone! You're unstoppable! 🔥"
]},
{ emoji: '💫', text: '3+ Hours!', class: 'building', messages: [
"Three hours of pure determination! ⏰",
"Three hours of excellence! Quality focus! ⭐",
"Three hours achievement! Building empires! 🏗️",
"Your commitment spans three hours! Amazing! 👏",
"Three hours of focused energy! 💫"
]}
],
six_hours: [
{ emoji: '⭐', text: '6+ Hours!', class: 'building', messages: [
"Six hours of dedication! You're incredible! 🌟",
"Six hours of focus! Marathon commitment! 🏃",
"Six hours achievement! Your endurance shines! 💪",
"Six hours of progress! Building greatness! 🏗️",
"Six hours milestone! You're a champion! 🏆"
]},
{ emoji: '⭐', text: '6+ Hours!', class: 'building', messages: [
"Six hours of pure determination! 🔥",
"Six hours of excellence! Quality sustained! ⭐",
"Six hours achievement! Deep focus mastery! 🌊",
"Your commitment spans six hours! Incredible! ⏰",
"Six hours of focused energy! 💫"
]}
],
twelve_hours: [
{ emoji: '✨', text: '12+ Hours!', class: 'strong', messages: [
"Half a day of consistency! You're amazing! 🎯",
"Twelve hours of commitment! True dedication! ⏱️",
"Half day milestone! Your persistence pays! 💰",
"Twelve hours of progress! Building legacy! 🏛️",
"Half day achievement! You're unstoppable! ⚡"
]},
{ emoji: '✨', text: '12+ Hours!', class: 'strong', messages: [
"Twelve hours of pure determination! 🔥",
"Half day of excellence! Quality sustained! ⭐",
"Twelve hours achievement! Deep focus legend! 🌟",
"Your commitment spans half a day! Amazing! ⏰",
"Twelve hours of focused energy! ✨"
]}
],
one_day: [
{ emoji: '🎯', text: '1 Day!', class: 'strong', messages: [
"Your first full day! A beautiful beginning! 🌅",
"One day achievement! The journey deepens! 🌟",
"24 hours milestone! Your commitment shines! ✨",
"One day of dedication! Building real habits! 🏗️",
"First day complete! Your story unfolds! 📖"
]},
{ emoji: '🎯', text: '1 Day!', class: 'strong', messages: [
"One day of pure determination! 🔥",
"24 hours of excellence! Quality sustained! ⭐",
"One day achievement! Foundation solid! 🏛️",
"Your commitment spans a full day! Amazing! ⏰",
"One day of focused energy! 🎯"
]}
],
two_days: [
{ emoji: '🚀', text: '2 Days!', class: 'strong', messages: [
"Two days strong! Your momentum is building! 💪",
"Two days achievement! Consistency emerging! 📈",
"48 hours milestone! Your dedication grows! 🌱",
"Two days of progress! Building momentum! 💨",
"Two days commitment! You're getting stronger! 🛡️"
]},
{ emoji: '🚀', text: '2 Days!', class: 'strong', messages: [
"Two days of pure determination! 🔥",
"48 hours of excellence! Quality sustained! ⭐",
"Two days achievement! Pattern forming! 🔄",
"Your commitment spans two days! Impressive! ⏰",
"Two days of focused energy! 🚀"
]}
],
three_days: [
{ emoji: '⚡', text: '3 Days!', class: 'strong', messages: [
"Three days of dedication! You're on fire! 🔥",
"Three days achievement! Real progress shows! 📊",
"72 hours milestone! Your commitment shines! ✨",
"Three days of consistency! Building habits! 🏗️",
"Three days strong! Your determination grows! 💪"
]},
{ emoji: '⚡', text: '3 Days!', class: 'strong', messages: [
"Three days of pure determination! 🔥",
"72 hours of excellence! Quality sustained! ⭐",
"Three days achievement! Momentum building! 💨",
"Your commitment spans three days! Amazing! ⏰",
"Three days of focused energy! ⚡"
]}
],
week_days: [
{ emoji: '💎', text: '{{days}} Days!', class: 'strong', messages: [
"Day {{days}} and still going! You're a diamond! 💎",
"Day {{days}} achievement! Your persistence shines! ✨",
"Day {{days}} milestone! Building real strength! 💪",
"Day {{days}} of commitment! True dedication! ⏱️",
"Day {{days}} strong! Your journey continues! 🌟"
]},
{ emoji: '💎', text: '{{days}} Days!', class: 'strong', messages: [
"Day {{days}} of pure determination! 🔥",
"Day {{days}} of excellence! Quality sustained! ⭐",
"Day {{days}} achievement! Progress accelerates! 🚀",
"Your commitment reaches day {{days}}! Amazing! ⏰",
"Day {{days}} of focused energy! 💎"
]}
],
one_week: [
{ emoji: '🌟', text: '1 Week!', class: 'strong', messages: [
"One full week! You're building real habits! 🌟",
"Seven days achievement! Consistency emerges! 📅",
"One week milestone! Your dedication shows! 💪",
"Seven days of progress! Building momentum! 💨",
"One week commitment! You're committed! 🔥"
]},
{ emoji: '🌟', text: '1 Week!', class: 'strong', messages: [
"One week of pure determination! 🔥",
"Seven days of excellence! Quality sustained! ⭐",
"One week achievement! Pattern established! 🔄",
"Your commitment spans one week! Impressive! ⏰",
"One week of focused energy! 🌟"
]}
],
two_weeks: [
{ emoji: '⚡', text: '2 Weeks!', class: 'fire', messages: [
"Two weeks of consistency! You're electric! ⚡",
"Fourteen days achievement! Real habits form! 📅",
"Two weeks milestone! Your commitment shines! ✨",
"Fourteen days of progress! Building strength! 💪",
"Two weeks commitment! You're unstoppable! 🔥"
]},
{ emoji: '⚡', text: '2 Weeks!', class: 'fire', messages: [
"Two weeks of pure determination! 🔥",
"Fourteen days of excellence! Quality sustained! ⭐",
"Two weeks achievement! Deep focus mastery! 🌊",
"Your commitment spans two weeks! Amazing! ⏰",
"Two weeks of focused energy! ⚡"
]}
],
three_weeks: [
{ emoji: '🎆', text: '3 Weeks!', class: 'fire', messages: [
"Three weeks! You're a celebration of consistency! 🎆",
"Twenty-one days achievement! Habits solidified! 📅",
"Three weeks milestone! Your dedication glows! ✨",
"Twenty-one days of progress! Building legacy! 🏛️",
"Three weeks commitment! You're incredible! 🔥"
]},
{ emoji: '🎆', text: '3 Weeks!', class: 'fire', messages: [
"Three weeks of pure determination! 🔥",
"Twenty-one days of excellence! Quality sustained! ⭐",
"Three weeks achievement! Transformation complete! ✨",
"Your commitment spans three weeks! Legendary! ⏰",
"Three weeks of focused energy! 🎆"
]}
],
one_month: [
{ emoji: '👑', text: '1 Month!', class: 'fire', messages: [
"One month of dedication! You're royalty! 👑",
"Thirty days achievement! True transformation! 📅",
"One month milestone! Your commitment reigns! ✨",
"Thirty days of progress! Building empires! 🏗️",
"One month commitment! You're a champion! 🏆"
]},
{ emoji: '👑', text: '1 Month!', class: 'fire', messages: [
"One month of pure determination! 🔥",
"Thirty days of excellence! Quality sustained! ⭐",
"One month achievement! Legendary status! 👑",
"Your commitment spans one month! Incredible! ⏰",
"One month of focused energy! 👑"
]}
],
two_months: [
{ emoji: '🥈', text: '2 Months!', class: 'fire', messages: [
"Two months of excellence! Silver medal worthy! 🥈",
"Sixty days achievement! True mastery! 📅",
"Two months milestone! Your dedication shines! ✨",
"Sixty days of progress! Building greatness! 🏛️",
"Two months commitment! You're elite! 🏆"
]},
{ emoji: '🥈', text: '2 Months!', class: 'fire', messages: [
"Two months of pure determination! 🔥",
"Sixty days of excellence! Quality sustained! ⭐",
"Two months achievement! Champion level! 🥇",
"Your commitment spans two months! Amazing! ⏰",
"Two months of focused energy! 🥈"
]}
],
hundred_days: [
{ emoji: '💯', text: '100 Days!', class: 'fire', messages: [
"100 DAYS! You're absolutely legendary! 💯",
"One hundred days achievement! Century club! 📅",
"100 days milestone! Your dedication is eternal! ✨",
"One hundred days of progress! Building legends! 🏛️",
"100 days commitment! You're a true warrior! ⚔️"
]},
{ emoji: '💯', text: '100 Days!', class: 'fire', messages: [
"100 days of pure determination! 🔥",
"One hundred days of excellence! Quality sustained! ⭐",
"100 days achievement! Legendary status! 💯",
"Your commitment spans 100 days! Incredible! ⏰",
"100 days of focused energy! 💯"
]}
],
legend_days: [
{ emoji: '👑', text: '{{days}} Days LEGEND!', class: 'fire', messages: [
"Day {{days}} - you're a living legend! 👑",
"Day {{days}} achievement! Legendary status! 📅",
"Day {{days}} milestone! Your dedication is eternal! ✨",
"Day {{days}} of progress! Building eternal legacy! 🏛️",
"Day {{days}} commitment! You're immortal! 🔥"
]},
{ emoji: '👑', text: '{{days}} Days LEGEND!', class: 'fire', messages: [
"Day {{days}} of pure determination! 🔥",
"Day {{days}} of excellence! Quality sustained! ⭐",
"Day {{days}} achievement! God-like focus! 👑",
"Your commitment reaches day {{days}}! Legendary! ⏰",
"Day {{days}} of focused energy! 👑"
]}
],
champion_days: [
{ emoji: '🌟', text: '{{days}} Days CHAMPION!', class: 'fire', messages: [
"Day {{days}} - you're an eternal champion! 🌟",
"Day {{days}} achievement! Champion forever! 📅",
"Day {{days}} milestone! Your dedication is infinite! ✨",
"Day {{days}} of progress! Building eternal greatness! 🏛️",
"Day {{days}} commitment! You're timeless! 🔥"
]},
{ emoji: '🌟', text: '{{days}} Days CHAMPION!', class: 'fire', messages: [
"Day {{days}} of pure determination! 🔥",
"Day {{days}} of excellence! Quality eternal! ⭐",
"Day {{days}} achievement! Champion of champions! 🏆",
"Your commitment spans day {{days}}! Eternal! ⏰",
"Day {{days}} of focused energy! 🌟"
]}
]
}
};
// Goal Tracker Application
class GoalTracker {
constructor() {
this.goals = this.loadGoals();
this.selectedColor = 'gray';
this.soundEnabled = localStorage.getItem('soundEnabled') !== 'false';
this.darkMode = localStorage.getItem('darkMode') === 'true';
this.sortBy = 'newest';
this.openMenus = this.loadOpenMenus();
// Initialize AudioContext for sound generation (optimize by reusing)
try {
this.audioContext = new (window.AudioContext || window.webkitAudioContext)();
} catch (e) {
console.warn('Web Audio API not supported');
this.audioContext = null;
}
// Note: Message caching is now handled directly in goal objects for persistence
// The temporary messageCache and usedMessages are no longer needed
this.init();
this.startUpdateInterval();
}
init() {
this.goalInput = document.getElementById('goalInput');
this.addGoalBtn = document.getElementById('addGoalBtn');
this.goalsContainer = document.getElementById('goalsContainer');
this.emptyState = document.getElementById('emptyState');
this.statsOverview = document.getElementById('statsOverview');
this.sortSelect = document.getElementById('sortSelect');
this.soundToggle = document.getElementById('toggleSound');
this.darkModeToggle = document.getElementById('toggleDarkMode');
// Color picker setup
document.querySelectorAll('.color-option').forEach(option => {
option.addEventListener('click', (e) => this.selectColor(e.target));
});
document.querySelector('.color-option').classList.add('selected');
// Event listeners
this.addGoalBtn.addEventListener('click', () => this.addGoal());
this.goalInput.addEventListener('keypress', (e) => {
if (e.key === 'Enter') this.addGoal();
});
this.sortSelect.addEventListener('change', (e) => {
this.sortBy = e.target.value;
this.render();
});
this.soundToggle.addEventListener('click', () => this.toggleSound());
this.darkModeToggle.addEventListener('click', () => this.toggleDarkMode());
// Update button displays
this.soundToggle.textContent = this.soundEnabled ? '🔊 Sound On' : '🔇 Sound Off';
if (!this.soundEnabled) this.soundToggle.classList.add('muted');
// Apply dark mode if enabled
if (this.darkMode) {
document.body.classList.add('dark-mode');
this.darkModeToggle.textContent = '☀️ Light Mode';
} else {
this.darkModeToggle.textContent = '🌙 Dark Mode';
}
this.render();
}
selectColor(element) {
document.querySelectorAll('.color-option').forEach(opt => opt.classList.remove('selected'));
element.classList.add('selected');
this.selectedColor = element.dataset.color;
}
toggleSound() {
this.soundEnabled = !this.soundEnabled;
localStorage.setItem('soundEnabled', this.soundEnabled);
this.soundToggle.textContent = this.soundEnabled ? '🔊 Sound On' : '🔇 Sound Off';
this.soundToggle.classList.toggle('muted');
if (this.soundEnabled) this.playSound('success');
}
toggleDarkMode() {
this.darkMode = !this.darkMode;
localStorage.setItem('darkMode', this.darkMode);
document.body.classList.toggle('dark-mode');
this.darkModeToggle.textContent = this.darkMode ? '☀️ Light Mode' : '🌙 Dark Mode';
this.playSound('success');
}
playSound(type) {
if (!this.soundEnabled || !this.audioContext) return;
// Resume AudioContext if it's suspended (required by modern browsers)
if (this.audioContext.state === 'suspended') {
this.audioContext.resume();
}
const oscillator = this.audioContext.createOscillator();
const gainNode = this.audioContext.createGain();
oscillator.connect(gainNode);
gainNode.connect(this.audioContext.destination);
if (type === 'success') {
oscillator.frequency.value = 800;
gainNode.gain.setValueAtTime(0.3, this.audioContext.currentTime);
gainNode.gain.exponentialRampToValueAtTime(0.01, this.audioContext.currentTime + 0.3);
oscillator.start(this.audioContext.currentTime);
oscillator.stop(this.audioContext.currentTime + 0.3);
} else if (type === 'milestone') {
[600, 800, 1000].forEach((freq, i) => {
const osc = this.audioContext.createOscillator();
const gain = this.audioContext.createGain();
osc.connect(gain);
gain.connect(this.audioContext.destination);
osc.frequency.value = freq;
gain.gain.setValueAtTime(0.2, this.audioContext.currentTime + i * 0.1);
gain.gain.exponentialRampToValueAtTime(0.01, this.audioContext.currentTime + i * 0.1 + 0.3);
osc.start(this.audioContext.currentTime + i * 0.1);
osc.stop(this.audioContext.currentTime + i * 0.1 + 0.3);
});
}
}
addGoal() {
const goalName = this.goalInput.value.trim();
if (!goalName) {
alert('Please enter a goal name!');
return;
}
// Generate initial messages for the new goal
const initialTime = this.calculateTimeElapsed(Date.now(), 0, false, null);
const initialBadge = this.getStreakBadge(Date.now(), initialTime);
const initialMotivationalMsg = this.getMotivationalMessage(Date.now(), initialTime.days);
const goal = {
id: Date.now(),
name: goalName,
startTime: Date.now(),
color: this.selectedColor,
isPaused: false,
pausedTime: 0,
pausedAt: null,
bestStreak: 0,
notes: '',
cachedBadge: {
emoji: initialBadge.emoji,
text: initialBadge.text,
class: initialBadge.class,
message: initialBadge.message
},
cachedMotivationalMsg: initialMotivationalMsg
};
this.goals.push(goal);
this.saveGoals();
this.goalInput.value = '';
this.playSound('success');
this.render();
}
pauseGoal(goalId) {
const goal = this.goals.find(g => g.id === goalId);
if (goal) {
if (goal.isPaused) {
// Resume
const pauseDuration = Date.now() - goal.pausedAt;
goal.pausedTime += pauseDuration;
goal.isPaused = false;
goal.pausedAt = null;
} else {
// Pause
goal.isPaused = true;
goal.pausedAt = Date.now();
}
this.saveGoals();
this.render();
}
}
resetGoal(goalId) {
const goal = this.goals.find(g => g.id === goalId);
if (goal) {
const time = this.calculateTimeElapsed(goal.startTime, goal.pausedTime, goal.isPaused, goal.pausedAt);
const currentStreak = time.days;
const confirmReset = confirm(`Reset streak for "${goal.name}"?\n\nCurrent streak: ${currentStreak} days\nBest streak: ${goal.bestStreak} days`);
if (confirmReset) {
// Update best streak if current is better
if (currentStreak > goal.bestStreak) {
goal.bestStreak = currentStreak;
}
goal.startTime = Date.now();
goal.pausedTime = 0;
goal.isPaused = false;
goal.pausedAt = null;
// Clear cached messages so new ones will be generated for the reset goal
goal.cachedBadge = null;
goal.cachedMotivationalMsg = null;
this.saveGoals();
this.render();
}
}
}
deleteGoal(goalId) {
const goal = this.goals.find(g => g.id === goalId);
if (goal) {
const confirmDelete = confirm(`Delete "${goal.name}"?`);
if (confirmDelete) {
this.goals = this.goals.filter(g => g.id !== goalId);
this.clearGoalMessages(goalId); // Clean up message tracking
this.saveGoals();
this.render();
}
}
}
calculateTimeElapsed(startTime, pausedTime = 0, isPaused = false, pausedAt = null) {
const now = Date.now();
let elapsed = now - startTime - pausedTime;
// If currently paused, subtract the current pause duration
if (isPaused && pausedAt) {
elapsed -= (now - pausedAt);
}
const seconds = Math.floor(elapsed / 1000);
const minutes = Math.floor(seconds / 60);
const hours = Math.floor(minutes / 60);
const days = Math.floor(hours / 24);
const remainingHours = hours % 24;
const remainingMinutes = minutes % 60;
const remainingSeconds = seconds % 60;
return {
days,
hours: remainingHours,
minutes: remainingMinutes,
seconds: remainingSeconds,
totalHours: hours,
totalMinutes: minutes
};
}
formatTime(value) {
return value.toString().padStart(2, '0');
}
getStreakBadge(goalId, time) {
const { days, totalHours, totalMinutes } = time;
// Very granular for first 24 hours
if (days === 0) {
if (totalMinutes < 5) {
const badgeOption = this.selectUniqueMessage(goalId, 'badge', 'just_started');
return {
emoji: badgeOption.emoji,
text: badgeOption.text,
class: badgeOption.class,
message: badgeOption.messages[Math.floor(Math.random() * badgeOption.messages.length)]
};
}
if (totalMinutes < 15) {
const badgeOption = this.selectUniqueMessage(goalId, 'badge', 'five_minutes');
return {
emoji: badgeOption.emoji,
text: badgeOption.text,
class: badgeOption.class,
message: badgeOption.messages[Math.floor(Math.random() * badgeOption.messages.length)]
};
}
if (totalMinutes < 30) {
const badgeOption = this.selectUniqueMessage(goalId, 'badge', 'fifteen_minutes');
return {
emoji: badgeOption.emoji,
text: badgeOption.text,
class: badgeOption.class,
message: badgeOption.messages[Math.floor(Math.random() * badgeOption.messages.length)]
};
}
if (totalHours < 1) {
const badgeOption = this.selectUniqueMessage(goalId, 'badge', 'thirty_minutes');
return {
emoji: badgeOption.emoji,
text: badgeOption.text,
class: badgeOption.class,
message: badgeOption.messages[Math.floor(Math.random() * badgeOption.messages.length)]
};
}
if (totalHours < 3) {
const badgeOption = this.selectUniqueMessage(goalId, 'badge', 'one_hour');
return {
emoji: badgeOption.emoji,
text: badgeOption.text,
class: badgeOption.class,
message: badgeOption.messages[Math.floor(Math.random() * badgeOption.messages.length)]
};
}
if (totalHours < 6) {
const badgeOption = this.selectUniqueMessage(goalId, 'badge', 'three_hours');
return {
emoji: badgeOption.emoji,
text: badgeOption.text,
class: badgeOption.class,
message: badgeOption.messages[Math.floor(Math.random() * badgeOption.messages.length)]
};
}
if (totalHours < 12) {
const badgeOption = this.selectUniqueMessage(goalId, 'badge', 'six_hours');
return {
emoji: badgeOption.emoji,
text: badgeOption.text,
class: badgeOption.class,
message: badgeOption.messages[Math.floor(Math.random() * badgeOption.messages.length)]
};
}
const badgeOption = this.selectUniqueMessage(goalId, 'badge', 'twelve_hours');
return {
emoji: badgeOption.emoji,
text: badgeOption.text,
class: badgeOption.class,
message: badgeOption.messages[Math.floor(Math.random() * badgeOption.messages.length)]
};
}
// Day-based milestones
if (days === 1) {
const badgeOption = this.selectUniqueMessage(goalId, 'badge', 'one_day');
return {
emoji: badgeOption.emoji,
text: badgeOption.text,
class: badgeOption.class,
message: badgeOption.messages[Math.floor(Math.random() * badgeOption.messages.length)]
};
}
if (days === 2) {
const badgeOption = this.selectUniqueMessage(goalId, 'badge', 'two_days');
return {
emoji: badgeOption.emoji,
text: badgeOption.text,
class: badgeOption.class,
message: badgeOption.messages[Math.floor(Math.random() * badgeOption.messages.length)]
};
}
if (days === 3) {
const badgeOption = this.selectUniqueMessage(goalId, 'badge', 'three_days');
return {
emoji: badgeOption.emoji,
text: badgeOption.text,
class: badgeOption.class,
message: badgeOption.messages[Math.floor(Math.random() * badgeOption.messages.length)]
};
}
if (days < 7) {
const badgeOption = this.selectUniqueMessage(goalId, 'badge', 'week_days');
return {
emoji: badgeOption.emoji,
text: badgeOption.text.replace('{{days}}', days),
class: badgeOption.class,
message: badgeOption.messages[Math.floor(Math.random() * badgeOption.messages.length)].replace(/\{\{days\}\}/g, days)
};
}
if (days === 7) {
const badgeOption = this.selectUniqueMessage(goalId, 'badge', 'one_week');
return {
emoji: badgeOption.emoji,
text: badgeOption.text,
class: badgeOption.class,
message: badgeOption.messages[Math.floor(Math.random() * badgeOption.messages.length)]
};
}
if (days < 14) {
const badgeOption = this.selectUniqueMessage(goalId, 'badge', 'week_days');
return {
emoji: badgeOption.emoji,
text: badgeOption.text.replace('{{days}}', days),
class: badgeOption.class,
message: badgeOption.messages[Math.floor(Math.random() * badgeOption.messages.length)].replace(/\{\{days\}\}/g, days)
};
}
if (days === 14) {
const badgeOption = this.selectUniqueMessage(goalId, 'badge', 'two_weeks');
return {
emoji: badgeOption.emoji,
text: badgeOption.text,
class: badgeOption.class,
message: badgeOption.messages[Math.floor(Math.random() * badgeOption.messages.length)]
};
}
if (days < 21) {
const badgeOption = this.selectUniqueMessage(goalId, 'badge', 'week_days');
return {
emoji: badgeOption.emoji,
text: badgeOption.text.replace('{{days}}', days),
class: badgeOption.class,
message: badgeOption.messages[Math.floor(Math.random() * badgeOption.messages.length)].replace(/\{\{days\}\}/g, days)
};
}
if (days === 21) {
const badgeOption = this.selectUniqueMessage(goalId, 'badge', 'three_weeks');
return {
emoji: badgeOption.emoji,
text: badgeOption.text,
class: badgeOption.class,
message: badgeOption.messages[Math.floor(Math.random() * badgeOption.messages.length)]
};
}
if (days < 30) {
const badgeOption = this.selectUniqueMessage(goalId, 'badge', 'week_days');
return {
emoji: badgeOption.emoji,
text: badgeOption.text.replace('{{days}}', days),
class: badgeOption.class,
message: badgeOption.messages[Math.floor(Math.random() * badgeOption.messages.length)].replace(/\{\{days\}\}/g, days)
};
}
if (days === 30) {
const badgeOption = this.selectUniqueMessage(goalId, 'badge', 'one_month');
return {
emoji: badgeOption.emoji,
text: badgeOption.text,
class: badgeOption.class,
message: badgeOption.messages[Math.floor(Math.random() * badgeOption.messages.length)]
};
}
if (days < 60) {
const badgeOption = this.selectUniqueMessage(goalId, 'badge', 'week_days');
return {
emoji: badgeOption.emoji,
text: badgeOption.text.replace('{{days}}', days),
class: badgeOption.class,
message: badgeOption.messages[Math.floor(Math.random() * badgeOption.messages.length)].replace(/\{\{days\}\}/g, days)
};
}
if (days === 60) {
const badgeOption = this.selectUniqueMessage(goalId, 'badge', 'two_months');
return {
emoji: badgeOption.emoji,
text: badgeOption.text,
class: badgeOption.class,
message: badgeOption.messages[Math.floor(Math.random() * badgeOption.messages.length)]
};
}
if (days < 100) {
const badgeOption = this.selectUniqueMessage(goalId, 'badge', 'legend_days');
return {
emoji: badgeOption.emoji,
text: badgeOption.text.replace('{{days}}', days),
class: badgeOption.class,
message: badgeOption.messages[Math.floor(Math.random() * badgeOption.messages.length)].replace(/\{\{days\}\}/g, days)
};
}
if (days === 100) {
const badgeOption = this.selectUniqueMessage(goalId, 'badge', 'hundred_days');
return {
emoji: badgeOption.emoji,
text: badgeOption.text,
class: badgeOption.class,
message: badgeOption.messages[Math.floor(Math.random() * badgeOption.messages.length)]
};
}
if (days < 365) {
const badgeOption = this.selectUniqueMessage(goalId, 'badge', 'legend_days');
return {
emoji: badgeOption.emoji,
text: badgeOption.text.replace('{{days}}', days),
class: badgeOption.class,
message: badgeOption.messages[Math.floor(Math.random() * badgeOption.messages.length)].replace(/\{\{days\}\}/g, days)
};
}
const badgeOption = this.selectUniqueMessage(goalId, 'badge', 'champion_days');
return {
emoji: badgeOption.emoji,
text: badgeOption.text.replace('{{days}}', days),
class: badgeOption.class,
message: badgeOption.messages[Math.floor(Math.random() * badgeOption.messages.length)].replace(/\{\{days\}\}/g, days)
};
}
getNextMilestone(time) {
const { days, totalMinutes } = time;
// Hour-based milestones for first day
if (days === 0) {
const hourMilestones = [5, 15, 30, 60, 180, 360, 720, 1440]; // minutes
for (let milestone of hourMilestones) {
if (totalMinutes < milestone) {
const label = milestone < 60 ? `${milestone} min` : `${milestone / 60} hr`;
return { next: milestone, progress: (totalMinutes / milestone) * 100, label };
}
}
}
// Day-based milestones
const dayMilestones = [1, 2, 3, 7, 14, 21, 30, 60, 100, 365];
for (let milestone of dayMilestones) {
if (days < milestone) {
return { next: milestone, progress: (days / milestone) * 100, label: `${milestone} day${milestone > 1 ? 's' : ''}` };
}
}
return { next: null, progress: 100, label: 'max' };
}
getMotivationalMessage(goalId, days) {
// Check for specific milestone messages first
if (days === 0) {
return this.selectUniqueMessage(goalId, 'general', 0);
}
if (days === 1) {
return this.selectUniqueMessage(goalId, 'general', 1);
}
if (days === 7) {
return this.selectUniqueMessage(goalId, 'general', 7);
}
if (days === 30) {
return this.selectUniqueMessage(goalId, 'general', 30);
}
if (days === 100) {
return this.selectUniqueMessage(goalId, 'general', 100);
}
// For non-milestone days, use the general message pool with variety
const messageIndex = Math.floor(Math.random() * MESSAGE_ALTERNATIVES.general.default.length);
const messageOptions = MESSAGE_ALTERNATIVES.general.default[messageIndex];
return this.selectUniqueMessage(goalId, 'general', messageIndex, messageOptions);
}
getColorGradient(color) {
const colors = {
gray: '#6b7280',
blue: '#3b82f6',
green: '#10b981',
amber: '#f59e0b',
rose: '#f43f5e',
purple: '#8b5cf6'
};
return colors[color] || colors.gray;
}
getBorderColor(color) {
const colors = {
gray: '#6b7280',
blue: '#3b82f6',
green: '#10b981',
amber: '#f59e0b',
rose: '#f43f5e',
purple: '#8b5cf6'
};
return colors[color] || colors.gray;
}
toggleNotes(goalId) {
const goal = this.goals.find(g => g.id === goalId);
if (!goal) return;
const card = document.querySelector(`[data-goal-id="${goalId}"]`);
const existingNotes = card.querySelector('.goal-notes');
if (existingNotes) {
existingNotes.remove();
} else {
const notesDiv = document.createElement('div');
notesDiv.className = 'goal-notes';
notesDiv.innerHTML = goal.notes ? `
<div class="note-display">"${goal.notes}"</div>
<button class="edit-note-btn">✏️ Edit Note</button>
` : `
<textarea placeholder="Add notes about your goal, feelings, or progress..."></textarea>
<button class="save-note-btn">💾 Save Note</button>
`;
card.appendChild(notesDiv);
const saveBtn = notesDiv.querySelector('.save-note-btn');
const editBtn = notesDiv.querySelector('.edit-note-btn');
if (saveBtn) {
saveBtn.addEventListener('click', () => {
const textarea = notesDiv.querySelector('textarea');
goal.notes = textarea.value.trim();
this.saveGoals();
this.toggleNotes(goalId);
this.toggleNotes(goalId);
});
}
if (editBtn) {
editBtn.addEventListener('click', () => {
notesDiv.innerHTML = `
<textarea>${goal.notes}</textarea>
<button class="save-note-btn">💾 Save Note</button>
`;
notesDiv.querySelector('.save-note-btn').addEventListener('click', () => {
const textarea = notesDiv.querySelector('textarea');
goal.notes = textarea.value.trim();
this.saveGoals();
this.toggleNotes(goalId);
this.toggleNotes(goalId);
});
});
}
}
}
toggleColorPicker(goalId) {
const goal = this.goals.find(g => g.id === goalId);
if (!goal) return;
const card = document.querySelector(`[data-goal-id="${goalId}"]`);
const existingPicker = card.querySelector('.color-picker-inline');
if (existingPicker) {
existingPicker.remove();
} else {
const pickerDiv = document.createElement('div');