-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
856 lines (754 loc) · 30.8 KB
/
Copy pathscript.js
File metadata and controls
856 lines (754 loc) · 30.8 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
var bornTime = new Date("2022-03-30T00:33:00+02:00"); // Paris time
var timer = null;
var effectTimeouts = []; // Track effect timeouts for cleanup
function prefersReducedMotion() {
return window.matchMedia && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
}
function clearEffectTimeouts() {
for (var i = 0; i < effectTimeouts.length; i++) {
clearTimeout(effectTimeouts[i]);
}
effectTimeouts = [];
}
function clearSpecialEffectNodes(container) {
if (!container) return;
const selectors = [".confetti-piece", ".falling-item", ".rising-item", ".sparkle-item", ".firework"];
for (const sel of selectors) {
const nodes = container.querySelectorAll(sel);
for (const n of nodes) n.remove();
}
}
function scheduleEffectCleanup(container, ms) {
const timeoutId = setTimeout(function() {
clearSpecialEffectNodes(container);
}, ms);
effectTimeouts.push(timeoutId);
}
// ═══════════════════════════════════════════════════════════════
// 🎁 SURPRISE ENGINE — Something new every visit!
// ═══════════════════════════════════════════════════════════════
// 🎊 SECRET SPECIAL DAYS & MOMENTS
const specialEvents = {
// Check for special day/moment - returns special event or null
check: function(now, totalDays) {
const month = now.getMonth() + 1; // 1-12
const day = now.getDate();
const hour = now.getHours();
const minute = now.getMinutes();
const dayOfWeek = now.getDay(); // 0 = Sunday
// ═══ BIRTHDAY! (March 30) ═══
if (month === 3 && day === 30) {
return {
type: "birthday",
headline: "🎂 Happy Birthday Mathis! 🎂",
message: "Today is the most special day of the year!",
particles: ["🎂", "🎁", "🎈", "🎉", "🥳", "🎊", "🍰", "🧁", "🎀", "⭐"],
theme: { bg: "#fff0f5", text: "#c71585", accent: "#ff69b4" },
effect: "confetti"
};
}
// ═══ BIRTH MOMENT (00:33) — Secret midnight magic! ═══
if (hour === 0 && minute === 33) {
return {
type: "birthMoment",
headline: "✨ 00:33 — The Magic Moment ✨",
message: "This is the exact minute Mathis was born!",
particles: ["✨", "🌟", "💫", "⭐", "🌙", "🔮", "💜", "🌌"],
theme: { bg: "#1a1a2e", text: "#eee", accent: "#9d4edd" },
effect: "sparkle",
darkOverride: true
};
}
// ═══ HALF BIRTHDAY (September 30) ═══
if (month === 9 && day === 30) {
return {
type: "halfBirthday",
headline: "🎈 Happy Half-Birthday! 🎈",
message: "6 months until the next big celebration!",
particles: ["🎈", "½", "🎉", "🌟", "🎊", "💫"],
theme: { bg: "#e8f5e9", text: "#2e7d32", accent: "#66bb6a" },
effect: "balloons"
};
}
// ═══ NEW YEAR'S DAY ═══
if (month === 1 && day === 1) {
return {
type: "newYear",
headline: "🎆 Happy New Year! 🎆",
message: "A brand new year of adventures begins!",
particles: ["🎆", "🎇", "✨", "🥳", "🍾", "🎊", "🌟", "💫"],
theme: { bg: "#0d1b2a", text: "#ffd700", accent: "#ffc107" },
effect: "fireworks",
darkOverride: true
};
}
// ═══ CHRISTMAS ═══
if (month === 12 && day === 25) {
return {
type: "christmas",
headline: "🎄 Merry Christmas! 🎄",
message: "May your day be filled with joy and wonder!",
particles: ["🎄", "🎅", "🤶", "🎁", "⭐", "❄️", "🦌", "🔔", "🕯️"],
theme: { bg: "#165b33", text: "#f8f8f8", accent: "#bb2528" },
effect: "snow",
darkOverride: true
};
}
// ═══ CHRISTMAS EVE ═══
if (month === 12 && day === 24) {
return {
type: "christmasEve",
headline: "🌟 Christmas Eve Magic 🌟",
message: "Santa is getting ready...",
particles: ["🌟", "❄️", "🎄", "🎁", "✨", "🔔"],
theme: { bg: "#1a237e", text: "#e8eaf6", accent: "#ffd54f" },
effect: "snow",
darkOverride: true
};
}
// ═══ VALENTINE'S DAY ═══
if (month === 2 && day === 14) {
return {
type: "valentines",
headline: "💝 Happy Valentine's Day! 💝",
message: "Spreading love and happiness!",
particles: ["❤️", "💕", "💖", "💗", "💓", "💞", "💘", "🌹", "😍"],
theme: { bg: "#ffe4ec", text: "#c2185b", accent: "#e91e63" },
effect: "hearts"
};
}
// ═══ HALLOWEEN ═══
if (month === 10 && day === 31) {
return {
type: "halloween",
headline: "🎃 Happy Halloween! 🎃",
message: "Boo! Time for some spooky fun!",
particles: ["🎃", "👻", "🦇", "🕷️", "🕸️", "💀", "🧙", "🌙", "🍬"],
theme: { bg: "#1a1a1a", text: "#ff6600", accent: "#9c27b0" },
effect: "spooky",
darkOverride: true
};
}
// ═══ EASTER (approximate - algorithm for any year) ═══
if (month >= 3 && month <= 4 && dayOfWeek === 0) {
// Anonymous Gregorian algorithm for Easter calculation
const easterDate = calculateEaster(now.getFullYear());
if (easterDate && month === (easterDate.getMonth() + 1) && day === easterDate.getDate()) {
return {
type: "easter",
headline: "🐰 Happy Easter! 🐰",
message: "Hop hop hop! Have an egg-cellent day!",
particles: ["🐰", "🥚", "🐣", "🌷", "🌸", "🦋", "🐥", "🌈"],
theme: { bg: "#fff8e1", text: "#6a1b9a", accent: "#ab47bc" },
effect: "spring"
};
}
}
// ═══ PI DAY (March 14) ═══
if (month === 3 && day === 14) {
return {
type: "piDay",
headline: "🥧 Happy Pi Day! 🥧",
message: "3.14159265358979... Math is beautiful!",
particles: ["🥧", "π", "🔢", "📐", "🧮", "∞", "✨"],
theme: { bg: "#e3f2fd", text: "#1565c0", accent: "#42a5f5" },
effect: "sparkle"
};
}
// ═══ STAR WARS DAY (May 4th) ═══
if (month === 5 && day === 4) {
return {
type: "starWars",
headline: "⭐ May the 4th Be With You ⭐",
message: "Happy Star Wars Day, young Padawan!",
particles: ["⭐", "🌟", "✨", "🚀", "🌌", "💫", "🔮"],
theme: { bg: "#000", text: "#ffd700", accent: "#4fc3f7" },
effect: "sparkle",
darkOverride: true
};
}
// ═══ WORLD CHILDREN'S DAY (November 20) ═══
if (month === 11 && day === 20) {
return {
type: "childrenDay",
headline: "🧒 World Children's Day! 🧒",
message: "Celebrating all the wonderful children!",
particles: ["🧒", "👶", "🎈", "🎨", "📚", "⚽", "🎭", "🌈"],
theme: { bg: "#e1f5fe", text: "#0277bd", accent: "#03a9f4" },
effect: "balloons"
};
}
// ═══ MILESTONE DAYS ═══
const milestoneEvents = {
1000: { headline: "🏆 1,000 DAYS! 🏆", message: "One thousand days of wonder!", effect: "confetti" },
1111: { headline: "✨ 1,111 Days — Make a Wish! ✨", message: "11:11 but for days!", effect: "sparkle" },
1234: { headline: "🔢 1-2-3-4 Days! 🔢", message: "A perfectly sequential milestone!", effect: "confetti" },
1500: { headline: "🌟 1,500 Days! 🌟", message: "Halfway to 3,000!", effect: "balloons" },
2000: { headline: "🎊 2,000 DAYS! 🎊", message: "Two thousand days of amazing!", effect: "fireworks" },
2222: { headline: "✨ 2,222 Days — Angel Number! ✨", message: "A magical number!", effect: "sparkle" },
2500: { headline: "🌈 2,500 Days! 🌈", message: "A quarter of 10,000!", effect: "confetti" },
3000: { headline: "🚀 3,000 DAYS! 🚀", message: "Three thousand days of adventure!", effect: "fireworks" },
3333: { headline: "✨ 3,333 Days! ✨", message: "Triple threes — extra lucky!", effect: "sparkle" },
4000: { headline: "🎆 4,000 DAYS! 🎆", message: "Four thousand days strong!", effect: "fireworks" },
5000: { headline: "👑 5,000 DAYS! 👑", message: "Halfway to 10,000!", effect: "confetti" },
10000: { headline: "🏆👑🎊 10,000 DAYS! 🎊👑🏆", message: "TEN THOUSAND DAYS!", effect: "fireworks" }
};
if (milestoneEvents[totalDays]) {
const m = milestoneEvents[totalDays];
return {
type: "milestone",
headline: m.headline,
message: m.message,
particles: ["🎉", "🎊", "✨", "🌟", "💫", "🏆", "⭐", "🎈"],
theme: { bg: "#fff3e0", text: "#e65100", accent: "#ff9800" },
effect: m.effect
};
}
// ═══ FRIDAY THE 13TH ═══
if (dayOfWeek === 5 && day === 13) {
return {
type: "friday13",
headline: "🖤 Friday the 13th 🖤",
message: "Not unlucky — just mysterious!",
particles: ["🖤", "🐈⬛", "🌙", "✨", "🔮", "💜", "⚫"],
theme: { bg: "#212121", text: "#b388ff", accent: "#7c4dff" },
effect: "sparkle",
darkOverride: true
};
}
// ═══ SUMMER SOLSTICE (June 20-21) ═══
if (month === 6 && (day === 20 || day === 21)) {
return {
type: "summerSolstice",
headline: "☀️ Summer Solstice! ☀️",
message: "The longest day of the year!",
particles: ["☀️", "🌻", "🌴", "🏖️", "🌊", "🍦", "🌞", "🕶️"],
theme: { bg: "#fffde7", text: "#f57f17", accent: "#ffeb3b" },
effect: "sparkle"
};
}
// ═══ WINTER SOLSTICE (December 21-22) ═══
if (month === 12 && (day === 21 || day === 22)) {
return {
type: "winterSolstice",
headline: "❄️ Winter Solstice ❄️",
message: "The shortest day — now days get longer!",
particles: ["❄️", "⛄", "🌨️", "🧣", "☃️", "🌙", "✨"],
theme: { bg: "#e3f2fd", text: "#0d47a1", accent: "#2196f3" },
effect: "snow"
};
}
return null; // No special event
}
};
// Calculate Easter date for any year (Anonymous Gregorian algorithm)
function calculateEaster(year) {
const a = year % 19;
const b = Math.floor(year / 100);
const c = year % 100;
const d = Math.floor(b / 4);
const e = b % 4;
const f = Math.floor((b + 8) / 25);
const g = Math.floor((b - f + 1) / 3);
const h = (19 * a + b - d - g + 15) % 30;
const i = Math.floor(c / 4);
const k = c % 4;
const l = (32 + 2 * e + 2 * i - h - k) % 7;
const m = Math.floor((a + 11 * h + 22 * l) / 451);
const month = Math.floor((h + l - 7 * m + 114) / 31);
const day = ((h + l - 7 * m + 114) % 31) + 1;
return new Date(year, month - 1, day);
}
const surprises = {
// Beautiful quotes about childhood, time, and growth
quotes: [
{ text: "Every day is a new beginning.", emoji: "🌅" },
{ text: "Growing up is an adventure.", emoji: "🚀" },
{ text: "The future belongs to those who dream…", emoji: "✨" },
{ text: "Little moments become big memories.", emoji: "📸" },
{ text: "Wonder is the beginning of wisdom.", emoji: "🦋" },
{ text: "Today you are you, that is truer than true.", emoji: "⭐" },
{ text: "Life is a beautiful journey.", emoji: "🌈" },
{ text: "Every second is a gift.", emoji: "🎁" },
{ text: "Dream big, little one.", emoji: "🌙" },
{ text: "The best is yet to come.", emoji: "🌻" },
{ text: "You make the world brighter.", emoji: "☀️" },
{ text: "Magic is something you make.", emoji: "🪄" },
{ text: "Kindness changes everything.", emoji: "💝" },
{ text: "Curiosity leads to discovery.", emoji: "🔭" },
{ text: "Every sunrise holds new promise.", emoji: "🌄" }
],
// Amazing fun facts
funFacts: [
{ text: "A day on Venus is longer than its year!", emoji: "🪐" },
{ text: "Octopuses have three hearts!", emoji: "🐙" },
{ text: "Honey never spoils — ever!", emoji: "🍯" },
{ text: "Butterflies taste with their feet!", emoji: "🦋" },
{ text: "The Moon is slowly moving away from Earth.", emoji: "🌙" },
{ text: "A group of flamingos is called a 'flamboyance'!", emoji: "🦩" },
{ text: "Bananas are berries, but strawberries aren't!", emoji: "🍌" },
{ text: "There are more stars than grains of sand on Earth.", emoji: "⭐" },
{ text: "Dolphins sleep with one eye open!", emoji: "🐬" },
{ text: "Rainbows are actually full circles!", emoji: "🌈" },
{ text: "Koalas have fingerprints like humans!", emoji: "🐨" },
{ text: "Lightning strikes Earth 8 million times a day!", emoji: "⚡" },
{ text: "The Eiffel Tower grows 15cm taller in summer!", emoji: "🗼" },
{ text: "Elephants can't jump!", emoji: "🐘" },
{ text: "A snail can sleep for three years!", emoji: "🐌" }
],
// Different headlines to show
headlines: [
"Make every second count",
"Growing stronger every day",
"Another beautiful day",
"Time flies when you're having fun",
"Every moment matters",
"Living life to the fullest",
"Counting blessings, not just seconds",
"Adventures await",
"One day at a time",
"Making memories every day"
],
// Color themes [background, text, accent]
colorThemes: [
{ name: "Ocean", bg: "#e8f4f8", text: "#1a5276", accent: "#3498db" },
{ name: "Sunset", bg: "#fdf2e9", text: "#7b4a2d", accent: "#e67e22" },
{ name: "Forest", bg: "#e9f7ef", text: "#1e5631", accent: "#27ae60" },
{ name: "Lavender", bg: "#f5eef8", text: "#4a235a", accent: "#9b59b6" },
{ name: "Rose", bg: "#fdedec", text: "#7b241c", accent: "#e74c3c" },
{ name: "Mint", bg: "#e8f6f3", text: "#0e6251", accent: "#1abc9c" },
{ name: "Golden", bg: "#fef9e7", text: "#7d6608", accent: "#f1c40f" },
{ name: "Sky", bg: "#ebf5fb", text: "#1b4f72", accent: "#5dade2" }
],
// Floating particles
particles: ["✨", "⭐", "💫", "🌟", "❤️", "💖", "🎈", "🎀", "🦋", "🌸", "🍀", "🌙"]
};
// Get moon phase
function getMoonPhase() {
const now = new Date();
let year = now.getFullYear();
let month = now.getMonth() + 1;
const day = now.getDate();
let c = 0, e = 0, jd = 0, b = 0;
if (month < 3) {
year--;
month += 12;
}
month++;
c = 365.25 * year;
e = 30.6 * month;
jd = c + e + day - 694039.09;
jd /= 29.5305882;
b = parseInt(jd, 10);
jd -= b;
b = Math.round(jd * 8);
if (b >= 8) b = 0;
const phases = [
{ name: "New Moon", emoji: "🌑" },
{ name: "Waxing Crescent", emoji: "🌒" },
{ name: "First Quarter", emoji: "🌓" },
{ name: "Waxing Gibbous", emoji: "🌔" },
{ name: "Full Moon", emoji: "🌕" },
{ name: "Waning Gibbous", emoji: "🌖" },
{ name: "Last Quarter", emoji: "🌗" },
{ name: "Waning Crescent", emoji: "🌘" }
];
return phases[b];
}
// Calculate age in fun units
function getFunUnit(seconds) {
const units = [
{ value: seconds, name: "seconds", emoji: "⏱️" },
{ value: Math.round(seconds * 1000), name: "milliseconds", emoji: "⚡" },
{ value: Math.round(seconds / 60), name: "minutes", emoji: "⏰" },
{ value: Math.round(seconds * 1.2), name: "heartbeats (approx)", emoji: "💓" },
{ value: Math.round(seconds * 15), name: "breaths (approx)", emoji: "🌬️" },
{ value: Math.round(seconds / 86400 * 3), name: "meals (approx)", emoji: "🍽️" },
{ value: Math.round(seconds / 86400 * 10), name: "smiles (at least)", emoji: "😊" },
{ value: Math.round(seconds / 86400 * 14), name: "hours of sleep (approx)", emoji: "😴" },
{ value: Math.round(seconds / 86400 * 100), name: "hugs (we hope!)", emoji: "🤗" }
];
return units[Math.floor(Math.random() * units.length)];
}
// Check for special milestones coming up
function getUpcomingMilestone(totalSeconds) {
const totalDays = Math.floor(totalSeconds / 86400);
const milestones = [
{ days: 100, label: "100 days" },
{ days: 365, label: "1 year" },
{ days: 500, label: "500 days" },
{ days: 730, label: "2 years" },
{ days: 1000, label: "1,000 days" },
{ days: 1095, label: "3 years" },
{ days: 1234, label: "1,234 days" },
{ days: 1460, label: "4 years" },
{ days: 1500, label: "1,500 days" },
{ days: 1825, label: "5 years" },
{ days: 2000, label: "2,000 days" },
{ days: 2222, label: "2,222 days" },
{ days: 2500, label: "2,500 days" },
{ days: 3000, label: "3,000 days" }
];
for (const m of milestones) {
const daysUntil = m.days - totalDays;
if (daysUntil > 0 && daysUntil <= 30) {
return { ...m, daysUntil };
}
if (daysUntil === 0) {
return { ...m, daysUntil: 0, isToday: true };
}
}
return null;
}
// Create floating particles (with custom particle set option)
function createParticles(customParticles) {
const container = document.getElementById("surprise-bg");
if (!container) return;
if (prefersReducedMotion()) {
container.textContent = "";
return;
}
// Clear existing particles
container.textContent = "";
const particleSet = customParticles || surprises.particles;
// Fewer particles on mobile for performance
const isMobile = window.innerWidth < 480;
const count = isMobile ? (6 + Math.floor(Math.random() * 4)) : (12 + Math.floor(Math.random() * 8));
for (let i = 0; i < count; i++) {
const particle = document.createElement("span");
particle.className = "floating-particle";
particle.textContent = particleSet[Math.floor(Math.random() * particleSet.length)];
particle.style.left = Math.random() * 100 + "%";
particle.style.animationDelay = Math.random() * 15 + "s";
particle.style.animationDuration = (15 + Math.random() * 10) + "s";
// Smaller particles on mobile
const baseSize = isMobile ? 0.7 : 0.8;
const sizeRange = isMobile ? 0.8 : 1.2;
particle.style.fontSize = (baseSize + Math.random() * sizeRange) + "rem";
container.appendChild(particle);
}
}
// ═══════════════════════════════════════════════════════════════
// 🎆 SPECIAL EFFECTS FOR CELEBRATIONS
// ═══════════════════════════════════════════════════════════════
function triggerSpecialEffect(effectType) {
const container = document.getElementById("surprise-bg");
if (!container) return;
if (prefersReducedMotion()) return;
// Ensure previous one-off effects don't accumulate if re-triggered.
clearSpecialEffectNodes(container);
switch (effectType) {
case "confetti":
createConfetti(container);
break;
case "fireworks":
createFireworks(container);
break;
case "hearts":
createFallingEffect(container, ["❤️", "💕", "💖", "💗", "💓", "💞", "💘"]);
break;
case "snow":
createFallingEffect(container, ["❄️", "❅", "❆", "🌨️", "⛄"]);
break;
case "balloons":
createRisingEffect(container, ["🎈", "🎈", "🎈", "🎉", "🎊"]);
break;
case "sparkle":
createSparkle(container);
break;
case "spooky":
createFallingEffect(container, ["🦇", "👻", "🕷️", "🎃"]);
break;
case "spring":
createFallingEffect(container, ["🌸", "🌷", "🦋", "🌼", "🌺"]);
break;
}
}
function createConfetti(container) {
const confettiColors = ["🎊", "🎉", "✨", "🌟", "💫", "⭐"];
const isMobile = window.innerWidth < 480;
const count = isMobile ? 25 : 50;
for (let i = 0; i < count; i++) {
const confetti = document.createElement("span");
confetti.className = "confetti-piece";
confetti.textContent = confettiColors[Math.floor(Math.random() * confettiColors.length)];
confetti.style.left = Math.random() * 100 + "%";
confetti.style.animationDelay = Math.random() * 3 + "s";
confetti.style.animationDuration = (3 + Math.random() * 2) + "s";
container.appendChild(confetti);
}
// Max delay 3s + max duration 5s => cleanup after ~9s
scheduleEffectCleanup(container, 9000);
}
function createFireworks(container) {
const fireworks = ["🎆", "🎇", "✨", "💥", "⭐"];
const isMobile = window.innerWidth < 480;
const count = isMobile ? 8 : 15;
for (let i = 0; i < count; i++) {
const timeoutId = setTimeout(function() {
// Check if container still exists
if (!container || !container.parentNode) return;
const fw = document.createElement("span");
fw.className = "firework";
fw.textContent = fireworks[Math.floor(Math.random() * fireworks.length)];
fw.style.left = (10 + Math.random() * 80) + "%";
fw.style.top = (10 + Math.random() * 60) + "%";
container.appendChild(fw);
// Remove after animation
const removeTimeoutId = setTimeout(function() {
if (fw && fw.parentNode) fw.remove();
}, 2000);
effectTimeouts.push(removeTimeoutId);
}, i * 500);
effectTimeouts.push(timeoutId);
}
}
function createFallingEffect(container, items) {
const isMobile = window.innerWidth < 480;
const count = isMobile ? 15 : 30;
for (let i = 0; i < count; i++) {
const item = document.createElement("span");
item.className = "falling-item";
item.textContent = items[Math.floor(Math.random() * items.length)];
item.style.left = Math.random() * 100 + "%";
item.style.animationDelay = Math.random() * 5 + "s";
item.style.animationDuration = (4 + Math.random() * 3) + "s";
container.appendChild(item);
}
// Max delay 5s + max duration 7s => cleanup after ~13s
scheduleEffectCleanup(container, 13000);
}
function createRisingEffect(container, items) {
const isMobile = window.innerWidth < 480;
const count = isMobile ? 10 : 20;
for (let i = 0; i < count; i++) {
const item = document.createElement("span");
item.className = "rising-item";
item.textContent = items[Math.floor(Math.random() * items.length)];
item.style.left = Math.random() * 100 + "%";
item.style.animationDelay = Math.random() * 8 + "s";
item.style.animationDuration = (6 + Math.random() * 4) + "s";
container.appendChild(item);
}
// Max delay 8s + max duration 10s => cleanup after ~19s
scheduleEffectCleanup(container, 19000);
}
function createSparkle(container) {
const sparkles = ["✨", "💫", "⭐", "🌟"];
const isMobile = window.innerWidth < 480;
const count = isMobile ? 12 : 25;
for (let i = 0; i < count; i++) {
const sparkle = document.createElement("span");
sparkle.className = "sparkle-item";
sparkle.textContent = sparkles[Math.floor(Math.random() * sparkles.length)];
sparkle.style.left = Math.random() * 100 + "%";
sparkle.style.top = Math.random() * 100 + "%";
sparkle.style.animationDelay = Math.random() * 2 + "s";
container.appendChild(sparkle);
}
// Sparkles are a "burst" here; cleanup after a few seconds.
scheduleEffectCleanup(container, 6000);
}
// Apply random color theme
function applyRandomTheme(customTheme, darkOverride) {
const isDark = window.matchMedia("(prefers-color-scheme: dark)").matches;
// Special events can override dark mode
if (customTheme && (darkOverride || !isDark)) {
document.body.style.background = customTheme.bg;
document.body.style.color = customTheme.text;
return;
}
if (isDark) return; // Keep dark mode as-is
const theme = surprises.colorThemes[Math.floor(Math.random() * surprises.colorThemes.length)];
document.body.style.background = theme.bg;
document.body.style.color = theme.text;
// Store for this session
try {
sessionStorage.setItem("currentTheme", JSON.stringify(theme));
} catch (e) {
// Ignore storage failures (privacy mode / disabled storage).
}
}
// Main surprise initialization
function initSurprises() {
const now = new Date();
const totalSeconds = Math.round((now - bornTime) / 1000);
const totalDays = Math.floor(totalSeconds / 86400);
// Check for special events first!
const specialEvent = specialEvents.check(now, totalDays);
const headlineEl = document.getElementById("headline");
const surpriseBox = document.getElementById("surprise-box");
// ═══ SPECIAL EVENT MODE ═══
if (specialEvent) {
// Set special headline
if (headlineEl) {
headlineEl.textContent = specialEvent.headline;
}
// Set special message in surprise box
if (surpriseBox) {
surpriseBox.textContent = "";
const textSpan = document.createElement("span");
textSpan.className = "surprise-text special-message";
textSpan.textContent = specialEvent.message;
surpriseBox.appendChild(textSpan);
}
// Apply special theme
applyRandomTheme(specialEvent.theme, specialEvent.darkOverride);
// Create special particles
createParticles(specialEvent.particles);
// Trigger special effect
if (specialEvent.effect) {
triggerSpecialEffect(specialEvent.effect);
}
// Add celebration class
document.body.classList.add("special-event", "special-" + specialEvent.type);
return; // Skip normal surprise logic
}
// ═══ NORMAL MODE ═══
// Random headline (changes each visit)
if (headlineEl) {
headlineEl.textContent = surprises.headlines[Math.floor(Math.random() * surprises.headlines.length)];
}
// Surprise box content
if (surpriseBox) {
const surpriseType = Math.floor(Math.random() * 4);
// Clear existing content safely
surpriseBox.textContent = "";
const emojiSpan = document.createElement("span");
emojiSpan.className = "surprise-emoji";
const textSpan = document.createElement("span");
textSpan.className = "surprise-text";
if (surpriseType === 0) {
// Quote
const quote = surprises.quotes[Math.floor(Math.random() * surprises.quotes.length)];
emojiSpan.textContent = quote.emoji;
textSpan.textContent = '"' + quote.text + '"';
surpriseBox.appendChild(emojiSpan);
surpriseBox.appendChild(textSpan);
} else if (surpriseType === 1) {
// Fun fact
const fact = surprises.funFacts[Math.floor(Math.random() * surprises.funFacts.length)];
emojiSpan.textContent = fact.emoji;
textSpan.textContent = "Did you know? " + fact.text;
surpriseBox.appendChild(emojiSpan);
surpriseBox.appendChild(textSpan);
} else if (surpriseType === 2) {
// Moon phase
const moon = getMoonPhase();
emojiSpan.textContent = moon.emoji;
textSpan.textContent = "Tonight's moon: " + moon.name;
surpriseBox.appendChild(emojiSpan);
surpriseBox.appendChild(textSpan);
} else {
// Today's special
const dayOfWeek = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"][now.getDay()];
const messages = [
"Happy " + dayOfWeek + "! ☀️",
"It's " + dayOfWeek + " — a great day to be alive! 🎉",
dayOfWeek + " vibes ✨",
"Another wonderful " + dayOfWeek + "! 🌟"
];
textSpan.textContent = messages[Math.floor(Math.random() * messages.length)];
surpriseBox.appendChild(textSpan);
}
}
// Apply color theme
applyRandomTheme();
// Create floating particles
createParticles();
// Add logo wiggle animation randomly
const logo = document.getElementById("logo");
if (logo && Math.random() > 0.5) {
logo.classList.add("wiggle");
}
}
// Start counting
function startClock() {
var currentTime = new Date();
var bornYear = bornTime.getFullYear();
var currentYear = currentTime.getFullYear();
var currentYearBirthday = new Date(bornTime.getTime());
currentYearBirthday.setFullYear(currentYear);
var lastYearBirthday = new Date(bornTime.getTime());
lastYearBirthday.setFullYear(currentYear - 1);
var deltaTime;
var age = currentYear - bornYear;
if (currentTime > currentYearBirthday) {
deltaTime = currentTime - currentYearBirthday;
} else {
deltaTime = currentTime - lastYearBirthday;
age = age - 1;
}
var showDetailEl = document.getElementById("showDetail");
var showDaysEl = document.getElementById("showDays");
var funUnitEl = document.getElementById("fun-unit");
if (showDetailEl) {
showDetailEl.textContent = forHumans(Math.round(deltaTime / 1000), age);
}
const totalSeconds = Math.round((currentTime - bornTime) / 1000);
if (age > 0 && showDaysEl) {
const totalDays = toDays(totalSeconds);
let daysText = "(" + totalDays.toLocaleString("fr") + " days)";
// Check for milestone
const milestone = getUpcomingMilestone(totalSeconds);
if (milestone) {
if (milestone.isToday) {
daysText += " 🎉 Today is " + milestone.label + "!";
document.body.classList.add("celebration");
} else {
daysText += " ⏳ " + milestone.daysUntil + " days until " + milestone.label + "!";
}
}
showDaysEl.textContent = daysText;
}
// Update fun unit occasionally (every 10 seconds to avoid distraction)
if (funUnitEl && Math.round(totalSeconds) % 10 === 0) {
const funUnit = getFunUnit(totalSeconds);
// Use textContent for security (no user input, but good practice)
funUnitEl.textContent = funUnit.emoji + " That's " + funUnit.value.toLocaleString("fr") + " " + funUnit.name + "!";
}
// sleep for 1s
timer = setTimeout(startClock, 1000);
}
// Start the clock when the DOM is ready
document.addEventListener("DOMContentLoaded", function() {
initSurprises();
startClock();
});
// Clean up timer and effects on page unload to prevent memory leaks
window.addEventListener("pagehide", function() {
if (timer) {
clearTimeout(timer);
timer = null;
}
clearEffectTimeouts();
// Clear one-off effect nodes to avoid bfcache keeping animations alive.
const container = document.getElementById("surprise-bg");
clearSpecialEffectNodes(container);
});
// If restored from back/forward cache, restart timers.
window.addEventListener("pageshow", function(e) {
if (!e || !e.persisted) return;
if (timer) return;
initSurprises();
startClock();
});
function forHumans(seconds, age) {
var countDays = Math.floor(seconds / 86400);
var levels = [
[age, age === 1 ? "year" : "years"],
[countDays, countDays === 1 ? "day" : "days"],
[Math.floor((seconds % 86400) / 3600), "hr"],
[Math.floor(((seconds % 86400) % 3600) / 60), "min"],
[((seconds % 86400) % 3600) % 60, "sec"]
];
var returntext = "";
for (var i = 0, max = levels.length; i < max; i++) {
if (levels[i][0] === 0) continue;
returntext += " " + levels[i][0] + " " + levels[i][1];
}
return returntext.trim();
}
function toDays(seconds) {
return Math.floor(seconds / 86400);
}