-
Notifications
You must be signed in to change notification settings - Fork 95
Expand file tree
/
Copy pathscript.js
More file actions
2263 lines (1999 loc) · 69.1 KB
/
script.js
File metadata and controls
2263 lines (1999 loc) · 69.1 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
// script.js — Love Alchemy (numerology-based, feature rich)
// Author: ChatGPT (adapt & enhance as you like)
/* ============================
Configuration & Helpers
============================ */
// Pythagorean letter mapping
document.getElementById('themeToggleBtn').addEventListener('click', function() {
document.body.classList.toggle('light-theme');
const btn = this;
btn.textContent = document.body.classList.contains('light-theme') ? '🌙 Dark Mode' : '☀️ Light Mode';
});
const LETTER_MAP = {
A: 1,
J: 1,
S: 1,
B: 2,
K: 2,
T: 2,
C: 3,
L: 3,
U: 3,
D: 4,
M: 4,
V: 4,
E: 5,
N: 5,
W: 5,
F: 6,
O: 6,
X: 6,
G: 7,
P: 7,
Y: 7,
H: 8,
Q: 8,
Z: 8,
I: 9,
R: 9,
}
// DOM elements
const name1El = document.getElementById('name1')
const name2El = document.getElementById('name2')
const calcBtn = document.getElementById('calcBtn')
const shareBtn = document.getElementById('shareBtn')
const percentText = document.getElementById('percentText')
const heading = document.getElementById('heading')
const description = document.getElementById('description')
const progressRing = document.querySelector('.ring')
const confettiToggle = document.getElementById('confettiToggle')
const particleCanvas = document.getElementById('particleCanvas')
const allowJitterEl = document.getElementById('allowJitter')
const useMasterEl = document.getElementById('useMaster')
const resetBtn = document.getElementById('resetBtn')
const historyBtn = document.getElementById('historyBtn')
const historyPanel = document.getElementById('historyPanel')
const historyPopupOverlay = document.getElementById('historyPopupOverlay')
const closeHistoryPopup = document.getElementById('closeHistoryPopup')
const historyList = document.getElementById('historyList')
const clearHistory = document.getElementById('clearHistory')
// const chime = document.getElementById('chime') // unused audio element removed from DOM
const themeToggleBtn = document.getElementById('themeToggleBtn')
// Premium UI elements
const app = document.querySelector('.app')
const moodIndicator = document.getElementById('moodIndicator')
const moodIcon = document.getElementById('moodIcon')
const moodLabel = document.getElementById('moodLabel')
const loveOracle = document.getElementById('loveOracle')
const oracleText = document.getElementById('oracleText')
// share preview modal elements
const sharePreviewOverlay = document.getElementById('sharePreviewOverlay')
const closeSharePreview = document.getElementById('closeSharePreview')
const shareCanvas = document.getElementById('shareCanvas')
const downloadImageBtn = document.getElementById('downloadImageBtn')
const copyImageBtn = document.getElementById('copyImageBtn')
const nativeShareBtn = document.getElementById('nativeShareBtn')
const feedbackBtn = document.getElementById('feedbackBtn')
const feedbackPopupOverlay = document.getElementById('feedbackPopupOverlay')
const shareLinkPopupOverlay = document.getElementById('shareLinkPopupOverlay')
const closeFeedbackPopup = document.getElementById('closeFeedbackPopup')
const closeShareLinkPopup = document.getElementById('closeShareLinkPopup')
const closeShareLink = document.getElementById('closeShareLink')
const copyShareLink = document.getElementById('copyShareLink')
const coupleSongBtn = document.getElementById('coupleSongBtn')
const coupleSongPopupOverlay = document.getElementById('coupleSongPopupOverlay')
const closeCoupleSongPopup = document.getElementById('closeCoupleSongPopup')
const closeCoupleSong = document.getElementById('closeCoupleSong')
const getSongBtn = document.getElementById('getSongBtn')
const songPercentInput = document.getElementById('songPercentInput')
const songRecommendation = document.getElementById('songRecommendation')
const songTitle = document.getElementById('songTitle')
const songArtist = document.getElementById('songArtist')
const songMood = document.getElementById('songMood')
const songYouTubeLink = document.getElementById('songYouTubeLink')
const feedbackForm = document.getElementById('feedbackForm')
const cancelFeedback = document.getElementById('cancelFeedback')
const feedbackSuccess = document.getElementById('feedbackSuccess')
const feedbackList = document.getElementById('feedbackList')
const clearFeedbackBtn = document.getElementById('clearFeedback') // May not exist in HTML
const ratingStars = document.querySelectorAll('.rating-stars .star')
const feedbackRatingInput = document.getElementById('feedbackRating')
const feedbackMessage = document.getElementById('feedbackMessage')
const charCount = document.getElementById('charCount')
let feedbacks = JSON.parse(localStorage.getItem('lovecalc_feedbacks')) || []
// Song recommendations by percentage range
const SONG_RECOMMENDATIONS = {
'0-29': {
title: 'You\'ve Got a Friend in Me',
artist: 'Randy Newman',
mood: 'Chill 🤝 - Friendship is the best foundation',
youtubeUrl: 'https://www.youtube.com/watch?v=DNZUKm0ApEM&list=RDDNZUKm0ApEM&start_radio=1'
},
'30-39': {
title: 'Just Give Me a Reason',
artist: 'P!nk ft. Nate Ruess',
mood: 'Friendly 😊 - Every relationship is worth exploring',
youtubeUrl: 'https://www.youtube.com/watch?v=OpQFFLBMEPI'
},
'40-49': {
title: 'Style',
artist: 'Taylor Swift',
mood: 'Curious 🤔 - There\'s something intriguing here',
youtubeUrl: 'https://www.youtube.com/watch?v=-CmadmM5cOk'
},
'50-59': {
title: 'Rather Be',
artist: 'Clean Bandit ft. Jess Glynne',
mood: 'Playful ✨ - Promising connection, let it grow naturally',
youtubeUrl: 'https://www.youtube.com/watch?v=m-M1AtrxztU'
},
'60-69': {
title: 'Love Story',
artist: 'Taylor Swift',
mood: 'Flirty 😍 - A playful love story in the making',
youtubeUrl: 'https://www.youtube.com/watch?v=8xg3vE8Ie_E'
},
'70-79': {
title: 'Can\'t Help Falling in Love',
artist: 'Elvis Presley',
mood: 'Adventurous 🌟 - Adventure awaits when you fall in love',
youtubeUrl: 'https://www.youtube.com/watch?v=vGJTaP6anOU'
},
'80-89': {
title: 'Thinking Out Loud',
artist: 'Ed Sheeran',
mood: 'Passionate 🔥 - When sparks fly, this is your anthem',
youtubeUrl: 'https://www.youtube.com/watch?v=lp-EO5I60KA'
},
'90-100': {
title: 'Perfect',
artist: 'Ed Sheeran',
mood: 'Dreamy 💫 - A cosmic match deserves a perfect song!',
youtubeUrl: 'https://www.youtube.com/watch?v=2Vv-BfVoq4g'
}
};
let confettiEnabled = true
let soundEnabled = true
// Love Song functionality - Initialize immediately after DOM elements
if (coupleSongBtn) {
coupleSongBtn.addEventListener('click', () => {
if (coupleSongPopupOverlay) {
coupleSongPopupOverlay.classList.remove('hidden')
const currentPercent = parseInt(percentText.textContent.replace('%', '')) || 0
if (currentPercent > 0 && songPercentInput) {
songPercentInput.value = currentPercent
// Automatically get song recommendation
setTimeout(() => {
if (getSongBtn) getSongBtn.click()
}, 100)
}
}
})
}
if (closeCoupleSongPopup) {
closeCoupleSongPopup.addEventListener('click', () => {
if (coupleSongPopupOverlay) coupleSongPopupOverlay.classList.add('hidden')
if (songRecommendation) songRecommendation.classList.add('hidden')
})
}
if (closeCoupleSong) {
closeCoupleSong.addEventListener('click', () => {
if (coupleSongPopupOverlay) coupleSongPopupOverlay.classList.add('hidden')
if (songRecommendation) songRecommendation.classList.add('hidden')
})
}
if (getSongBtn) {
getSongBtn.addEventListener('click', () => {
const percent = parseInt(songPercentInput.value)
const errorEl = document.getElementById('songPercentError')
if (isNaN(percent) || percent < 0 || percent > 100) {
if (errorEl) errorEl.classList.remove('hidden')
if (songRecommendation) songRecommendation.classList.add('hidden')
return
}
if (errorEl) errorEl.classList.add('hidden')
const song = getSongForPercentage(percent)
if (songTitle) songTitle.textContent = song.title
if (songArtist) songArtist.textContent = `by ${song.artist}`
if (songMood) songMood.textContent = song.mood
if (songYouTubeLink) songYouTubeLink.href = song.youtubeUrl
// Set up YouTube thumbnail
const videoId = extractYouTubeVideoId(song.youtubeUrl)
const thumbnailImg = document.getElementById('thumbnailImg')
const songThumbnail = document.getElementById('songThumbnail')
if (thumbnailImg && videoId) {
thumbnailImg.src = `https://img.youtube.com/vi/${videoId}/maxresdefault.jpg`
thumbnailImg.onload = () => {
// Check if it's the default "no thumbnail" image (120x90)
if (thumbnailImg.naturalWidth === 120 && thumbnailImg.naturalHeight === 90) {
thumbnailImg.src = `https://img.youtube.com/vi/${videoId}/hqdefault.jpg`
}
}
thumbnailImg.onerror = () => {
thumbnailImg.src = `https://img.youtube.com/vi/${videoId}/hqdefault.jpg`
}
if (songThumbnail) {
songThumbnail.onclick = () => window.open(song.youtubeUrl, '_blank')
}
}
if (songRecommendation) songRecommendation.classList.remove('hidden')
// Setup share song button
const shareSongBtn = document.getElementById('shareSongBtn')
if (shareSongBtn) {
shareSongBtn.onclick = (event) => {
event.preventDefault()
event.stopPropagation()
navigator.clipboard.writeText(song.youtubeUrl).then(() => {
const originalContent = shareSongBtn.innerHTML
shareSongBtn.innerHTML = '<i class="fa-solid fa-check"></i><span>Copied!</span>'
showToast('Song link copied to clipboard!')
setTimeout(() => {
shareSongBtn.innerHTML = originalContent
}, 2000)
}).catch(() => {
alertDialog('Failed to copy link', 'Error')
})
}
}
})
}
if (coupleSongPopupOverlay) {
coupleSongPopupOverlay.addEventListener('click', (e) => {
if (e.target === coupleSongPopupOverlay) {
coupleSongPopupOverlay.classList.add('hidden')
if (songRecommendation) songRecommendation.classList.add('hidden')
}
})
}
// Setup canvas size with performance optimization
const ctx = particleCanvas.getContext ? particleCanvas.getContext('2d') : null
// Performance optimization: limit canvas size to reasonable dimensions
const MAX_CANVAS_WIDTH = 1920
const MAX_CANVAS_HEIGHT = 1080
// Performance monitoring (development/debugging helper)
let performanceMetrics = {
particleCount: 0,
lastFrameTime: 0,
averageFrameTime: 0,
frameTimeHistory: [],
droppedFrames: 0,
canvasResizeCount: 0
};
function resizeCanvas() {
const width = Math.min(window.innerWidth, MAX_CANVAS_WIDTH)
const height = Math.min(window.innerHeight, MAX_CANVAS_HEIGHT)
// Only resize if dimensions actually changed to avoid unnecessary operations
if (particleCanvas.width !== width || particleCanvas.height !== height) {
particleCanvas.width = width
particleCanvas.height = height
// Track resize count for performance monitoring
if (typeof performanceMetrics !== 'undefined') {
performanceMetrics.canvasResizeCount++
}
}
}
resizeCanvas()
// Throttle resize events for better performance
let resizeTimeout
window.addEventListener('resize', () => {
if (resizeTimeout) clearTimeout(resizeTimeout)
resizeTimeout = setTimeout(resizeCanvas, 100)
})
let oracleInterval;
function typeOracleText(elementId, text, delay = 50) {
const element = document.getElementById(elementId);
if (!element) return // Performance safety check
if (oracleInterval) clearInterval(oracleInterval); // stop any running animation
element.textContent = '';
element.classList.add('oracle-text');
let i = 0;
const chars = [...text]; // splits text into proper Unicode characters
oracleInterval = setInterval(() => {
if (i < chars.length) {
element.textContent += chars[i];
i++;
} else {
clearInterval(oracleInterval);
oracleInterval = null; // Performance: clear reference
element.classList.remove('oracle-text');
}
}, delay);
}
// Performance optimization: cleanup oracle interval on page unload
window.addEventListener('beforeunload', () => {
if (oracleInterval) {
clearInterval(oracleInterval);
oracleInterval = null;
}
// Cleanup resize timeout
if (resizeTimeout) {
clearTimeout(resizeTimeout);
resizeTimeout = null;
}
});
function sanitizeName(s) {
if (!s) return ''
return s.replace(/[^A-Za-z]/g, '').toUpperCase()
}
function nameToNumber(name, supportMaster = true) {
// Convert to letter values and sum
name = sanitizeName(name)
let sum = 0
for (let ch of name) {
if (LETTER_MAP[ch]) sum += LETTER_MAP[ch]
}
// Reduce: keep master numbers optionally
if (supportMaster) {
while (sum > 9 && sum !== 11 && sum !== 22 && sum !== 33) {
sum = sum
.toString()
.split('')
.reduce((a, b) => a + parseInt(b), 0)
}
} else {
while (sum > 9)
sum = sum
.toString()
.split('')
.reduce((a, b) => a + parseInt(b), 0)
}
return sum || 0
}
function combineNumbers(num1, num2, supportMaster = true) {
let combined = num1 + num2
if (supportMaster) {
while (combined > 9 && combined !== 11 && combined !== 22 && combined !== 33) {
combined = combined
.toString()
.split('')
.reduce((a, b) => a + parseInt(b), 0)
}
} else {
while (combined > 9)
combined = combined
.toString()
.split('')
.reduce((a, b) => a + parseInt(b), 0)
}
return combined
}
function mapToPercent(combined, num1, num2) {
let base
if (combined === 11) base = 95
else if (combined === 22) base = 99
else if (combined === 33) base = 99
else base = 30 + combined * 7 // gives 37..93-ish depending on combined
// Boosts and penalties
if (num1 === num2 && num1 !== 0) base += 6 // same core = better sync
if ([11, 22, 33].includes(num1) || [11, 22, 33].includes(num2)) base += 6 // master influence
// Favor odd mystical numbers a bit
if (combined === 1) base = 92
if (combined === 7) base += 10
// Cap and final rounding
base = Math.min(100, Math.max(1, Math.round(base)))
return base
}
/* ============================
UI helpers: ring animation
============================ */
const RADIUS = 64
const CIRCUMFERENCE = 2 * Math.PI * RADIUS
function setRing(percent) {
const val = Math.max(0, Math.min(100, percent))
const dash = (val / 100) * CIRCUMFERENCE
progressRing.style.strokeDasharray = `${dash} ${CIRCUMFERENCE}`
// color shift (green-ish for high, pink for mid)
const hue = Math.round(340 - (val / 100) * 200) // pink -> greenish
progressRing.style.filter = `drop-shadow(0 12px 24px rgba(255,46,99,${0.14 * (val / 100)}))`
percentText.textContent = `${val}%`
}
/* ============================
Message Generation
============================ */
function messageForPercent(p) {
if (p >= 95) return '💞 Cosmic Bond — Truly rare!'
if (p >= 85) return '💕 Soulmates in the making!'
if (p >= 70) return '💖 Strong connection — nurture it!'
if (p >= 50) return '✨ Promising — work & communicate!'
if (p >= 30) return '🤍 Some sparks — effort required.'
return '💔 Friendly vibes — maybe best as friends.'
}
/* ============================
Mood & Tips System
============================ */
// Mood data with icons and CSS classes
const MOODS = {
dreamy: { icon: '💫', label: 'Dreamy', class: 'mood-dreamy' },
passionate: { icon: '🔥', label: 'Passionate', class: 'mood-passionate' },
adventurous: { icon: '🌟', label: 'Adventurous', class: 'mood-adventurous' },
flirty: { icon: '😍', label: 'Flirty', class: 'mood-flirty' },
playful: { icon: '✨', label: 'Playful', class: 'mood-playful' },
curious: { icon: '🤔', label: 'Curious', class: 'mood-curious' },
friendly: { icon: '😊', label: 'Friendly', class: 'mood-friendly' },
chill: { icon: '🤝', label: 'Chill', class: 'mood-chill' },
}
// Mood-specific tip collections
const MOOD_TIPS = {
dreamy: [
'🌙 Stargaze together tonight',
'💌 Write them a heartfelt letter',
'🎵 Create a dreamy playlist for them',
'🌸 Leave a sweet note on their pillow',
'☁️ Plan a cozy afternoon nap together',
],
passionate: [
'💋 Surprise them with a passionate kiss',
'🌹 Leave rose petals on their path',
'🕯️ Set up a candlelit dinner',
'💃 Dance together to your favorite song',
'🔥 Write them a love poem',
],
adventurous: [
'🗺️ Plan a spontaneous mini-adventure',
'🥾 Go on an unexpected hike together',
'🎢 Try something new and exciting',
'📍 Explore a new place in your city',
'🎯 Challenge them to a fun competition',
],
flirty: [
'😉 Send them a cheeky text',
'💄 Leave a lipstick mark on their mirror',
'🍓 Feed them something sweet',
'💐 Surprise them with their favorite flowers',
'📱 Send a cute selfie with a flirty caption',
],
playful: [
'🎈 Plan a silly photo shoot together',
'🎮 Have a game night with their favorite games',
'🍕 Build a blanket fort and order pizza',
'🎭 Do silly impressions of each other',
'🧩 Work on a puzzle together',
],
curious: [
'❓ Ask them about their wildest dream',
'📚 Share an interesting article with them',
'🔍 Explore a new hobby together',
'🎨 Try creating something artistic together',
'🌟 Learn something new about each other',
],
friendly: [
'☕ Share a warm cup of coffee',
'🤗 Give them an unexpected hug',
'📞 Call them just to hear their voice',
'🍪 Bake their favorite treat together',
'💬 Have a deep, meaningful conversation',
],
chill: [
'🛋️ Have a relaxing movie marathon',
'🧘 Try meditation or yoga together',
'🍵 Enjoy a peaceful tea time',
'📖 Read books in comfortable silence',
'🌅 Watch the sunrise or sunset together',
],
}
// Get mood based on compatibility score
function getMoodForPercent(p) {
if (p >= 90) return MOODS.dreamy
if (p >= 80) return MOODS.passionate
if (p >= 70) return MOODS.adventurous
if (p >= 60) return MOODS.flirty
if (p >= 50) return MOODS.playful
if (p >= 40) return MOODS.curious
if (p >= 30) return MOODS.friendly
return MOODS.chill
}
// Get random tip based on mood
function getRandomTipForMood(moodKey) {
const tips = MOOD_TIPS[moodKey] || MOOD_TIPS.playful
return tips[Math.floor(Math.random() * tips.length)]
}
// Apply mood theme to entire page
function applyMoodTheme(mood) {
// Remove all existing mood classes
Object.values(MOODS).forEach((m) => app.classList.remove(m.class))
// Add current mood class
app.classList.add(mood.class)
// Update mood indicator
moodIcon.textContent = mood.icon
moodLabel.textContent = mood.label
moodIndicator.classList.remove('hidden')
}
// Enhanced Oracle Messages with mystical flair
const ORACLE_MESSAGES = {
dreamy: [
'The cosmos whispers secrets of eternal connection... ✨',
'Stars align in perfect harmony for your love story... 🌟',
'Moonlight reveals the depth of your cosmic bond... 🌙',
'Celestial energies dance in your romantic aura... 💫',
'Your love resonates through the universal symphony... 🎵',
],
passionate: [
'Flames of passion burn eternally in your hearts... 🔥',
'Your souls ignite with irresistible magnetic fire... 💥',
'Passion flows like molten gold through your connection... 🌋',
'Hearts beat in perfect sync with burning intensity... ❤️🔥',
'Love\'s fire consumes all doubts and fears... 🔥',
],
adventurous: [
'Embark on love\'s greatest adventure together... 🗺️',
'Your spirits soar on wings of shared exploration... 🦅',
'Every moment becomes an exciting chapter... 📖',
'Love\'s journey unfolds with thrilling discoveries... 🧭',
'Together you conquer love\'s highest peaks... ⛰️',
],
flirty: [
'Butterflies dance in anticipation of your touch... 🦋',
'Love\'s playful whispers tease the heart... 😘',
'Sparks fly in your flirtatious energy field... ⚡',
'Hearts flutter with delightful anticipation... 💕',
'Love blooms in your charming interactions... 🌸',
],
playful: [
'Love sparkles with joyful playfulness... ✨',
'Hearts giggle in harmonious delight... 😄',
'Your connection dances with lighthearted magic... 💃',
'Love\'s energy bubbles with sweet mischief... 🫧',
'Joyful hearts create beautiful memories... 🎈',
],
curious: [
'Love\'s mysteries unfold in your shared curiosity... 🔍',
'Hearts explore the depths of connection... 🌊',
'Questions lead to beautiful discoveries... 💭',
'Love grows through shared wonder... 🌱',
'Curiosity strengthens your romantic bond... 🤔',
],
friendly: [
'Love blooms from the seeds of friendship... 🌻',
'Hearts connect in warm, gentle harmony... ☕',
'Love grows in the garden of companionship... 🌷',
'Your friendship forms love\'s strong foundation... 🤝',
'Love flourishes in your caring connection... 💝',
],
chill: [
'Love flows peacefully like a gentle stream... 🏞️',
'Hearts find tranquility in each other\'s presence... 🧘',
'Love whispers softly in moments of calm... 🍃',
'Peaceful energy surrounds your connection... ☮️',
'Love rests comfortably in your shared space... 🛋️',
],
}
// Get mystical oracle message based on mood
function getMysticalOracleMessage(moodKey) {
const messages = ORACLE_MESSAGES[moodKey] || ORACLE_MESSAGES.playful
return messages[Math.floor(Math.random() * messages.length)]
}
// Show Love Oracle with magical animation
function showLoveOracle(message) {
// oracleText.textContent = message
typeOracleText('oracleText', message, 50);
loveOracle.classList.remove('hidden')
// Add typewriter effect delay
setTimeout(() => {
oracleText.style.animation = 'typewriterReveal 3s ease-out forwards'
}, 200)
}
// Hide mood and oracle displays
function hideMoodAndTips() {
moodIndicator.classList.add('hidden')
loveOracle.classList.add('hidden')
// Remove all mood classes
Object.values(MOODS).forEach((m) => app.classList.remove(m.class))
}
function getRandomTip() {
const tips = [
'💌 Send a sweet message today',
'☕ Plan a surprise coffee date',
'🌅 Watch the sunrise together',
'🎵 Share your favorite song',
'🌸 Leave a cute note somewhere',
'🍕 Cook something special together',
'📚 Read the same book',
'🌙 Stargaze tonight',
'🎨 Try a creative activity together',
'💐 Surprise with flowers',
'🚶♀️ Take a romantic walk',
'📷 Take a silly photo together',
]
return tips[Math.floor(Math.random() * tips.length)]
}
/* ============================
Confetti & Heart Particles
============================ */
let particles = []
let particleAnimId = null
function random(min, max) {
return Math.random() * (max - min) + min
}
class Particle {
constructor(x, y, vx, vy, size, life, color, shape = 'confetti') {
this.x = x
this.y = y
this.vx = vx
this.vy = vy
this.size = size
this.life = life
this.initialLife = life
this.color = color
this.shape = shape
this.angle = Math.random() * Math.PI * 2
this.spin = Math.random() * 0.2 - 0.1
// Performance optimization: pre-calculate some values
this.halfSize = this.size / 2
this.sizeRect = this.size * 0.6
}
update(dt) {
this.x += this.vx * dt
this.y += this.vy * dt
this.vy += 0.02 * dt // gravity
this.life -= dt
this.angle += this.spin * dt
}
draw(ctx) {
// Performance optimization: skip drawing very transparent particles
const alpha = Math.max(0, this.life / this.initialLife)
if (alpha < 0.05) return
ctx.save()
ctx.globalAlpha = alpha
ctx.translate(this.x, this.y)
ctx.rotate(this.angle)
if (this.shape === 'heart') {
// draw simple heart - using pre-calculated size values
const s = this.size
ctx.beginPath()
ctx.moveTo(0, s * 0.35)
ctx.bezierCurveTo(-s * 0.6, -s * 0.6, -s * 1.2, s * 0.5, 0, s * 1.2)
ctx.bezierCurveTo(s * 1.2, s * 0.5, s * 0.6, -s * 0.6, 0, s * 0.35)
ctx.fillStyle = this.color
ctx.fill()
} else {
// confetti rectangle - using pre-calculated values
ctx.fillStyle = this.color
ctx.fillRect(-this.halfSize, -this.halfSize, this.size, this.sizeRect)
}
ctx.restore()
}
}
function spawnBurst(x, y, count = 40, heartChance = 0.25) {
// Performance optimization: limit particle count based on device capability
const maxParticles = 200 // Prevent too many particles at once
const availableSlots = maxParticles - particles.length
const actualCount = Math.min(count, availableSlots)
if (actualCount <= 0) return // Skip if already at max particles
for (let i = 0; i < actualCount; i++) {
const speed = random(1, 6)
const angle = random(0, Math.PI * 2)
const vx = Math.cos(angle) * speed
const vy = Math.sin(angle) * speed * 0.6 - random(1, 3) // upward bias
const size = random(6, 18)
const life = random(60, 120)
const color =
Math.random() > 0.5
? `hsl(${Math.round(random(340, 360))}, 90%, ${Math.round(random(45, 65))}%)`
: `hsl(${Math.round(random(0, 50))}, 85%, ${Math.round(random(55, 70))}%)`
const shape = Math.random() < heartChance ? 'heart' : 'confetti'
particles.push(new Particle(x, y, vx, vy, size, life, color, shape))
}
}
let lastTime = performance.now()
function animateParticles(now) {
// Performance optimization: stop animation immediately if no particles exist
if (particles.length === 0) {
particleAnimId = null
return
}
const frameStartTime = performance.now()
// Skip frame if not enough time has passed (cap at 60fps)
if (now - lastTime < 16) {
particleAnimId = requestAnimationFrame(animateParticles)
return
}
const dt = Math.min(3, (now - lastTime) / 16) // normalized delta
lastTime = now
if (!ctx) return
// Performance optimization: only clear and render if canvas is visible
if (particleCanvas.offsetParent === null) {
particleAnimId = requestAnimationFrame(animateParticles)
return
}
ctx.clearRect(0, 0, particleCanvas.width, particleCanvas.height)
// Batch particle updates and removes for better performance
const particlesToRemove = []
for (let i = 0; i < particles.length; i++) {
const p = particles[i]
p.update(dt)
p.draw(ctx)
if (p.life <= 0 || p.y > particleCanvas.height + 100) {
particlesToRemove.push(i)
}
}
// Remove particles in reverse order to maintain indices
for (let i = particlesToRemove.length - 1; i >= 0; i--) {
particles.splice(particlesToRemove[i], 1)
}
// Update performance metrics
const frameTime = performance.now() - frameStartTime
if (typeof updatePerformanceMetrics === 'function') {
updatePerformanceMetrics(frameTime)
}
if (particles.length > 0) particleAnimId = requestAnimationFrame(animateParticles)
else particleAnimId = null
}
function triggerCelebration(percent) {
// Skip if confetti is disabled
if (!confettiEnabled) return
// big celebration for high %
const cx = particleCanvas.width / 2
const cy = particleCanvas.height / 4
if (percent >= 70) {
spawnBurst(cx, cy, 120, 0.45)
} else {
spawnBurst(cx, cy, 50, 0.25)
}
if (!particleAnimId) {
lastTime = performance.now()
particleAnimId = requestAnimationFrame(animateParticles)
}
}
// Performance optimization: cleanup function for particles
function cleanupParticles() {
if (particleAnimId) {
cancelAnimationFrame(particleAnimId)
particleAnimId = null
}
particles = []
if (ctx) {
ctx.clearRect(0, 0, particleCanvas.width, particleCanvas.height)
}
}
// Cleanup on page unload to prevent memory leaks
window.addEventListener('beforeunload', cleanupParticles)
// Cleanup when page becomes hidden (mobile/tab switching)
document.addEventListener('visibilitychange', () => {
if (document.hidden) {
cleanupParticles()
}
})
/* ============================
Small floating hearts background
============================ */
function createFloatingHeart() {
const heart = document.createElement('div')
heart.className = 'floating-heart'
heart.style.position = 'fixed'
heart.style.left = Math.random() * window.innerWidth + 'px'
heart.style.top = window.innerHeight + 20 + 'px'
heart.style.pointerEvents = 'none'
heart.style.zIndex = 0
heart.style.fontSize = `${Math.round(random(12, 36))}px`
heart.style.opacity = `${random(0.25, 0.9)}`
heart.style.transform = `translateY(0) rotate(${Math.random() * 360}deg)`
heart.textContent = '❤'
document.body.appendChild(heart)
const duration = random(5, 14)
heart.animate(
[
{ transform: `translateY(0)`, opacity: heart.style.opacity },
{
transform: `translateY(-${window.innerHeight + 200}px) rotate(${Math.random() * 720}deg)`,
opacity: 0,
},
],
{ duration: duration * 1000, easing: 'cubic-bezier(.2,.8,.2,1)' }
)
setTimeout(() => heart.remove(), duration * 1000 + 300)
}
setInterval(createFloatingHeart, 700)
/* ============================
Storage: history
============================ */
const STORAGE_KEY = 'love_alchemy_history_v1'
function saveHistory(item) {
const h = getHistory()
h.unshift(item)
// keep last 10
while (h.length > 10) h.pop()
localStorage.setItem(STORAGE_KEY, JSON.stringify(h))
renderHistory()
}
function getHistory() {
try {
const raw = localStorage.getItem(STORAGE_KEY)
return raw ? JSON.parse(raw) : []
} catch (e) {
return []
}
}
function clearHistoryStorage() {
localStorage.removeItem(STORAGE_KEY)
renderHistory()
}
function renderHistory() {
const h = getHistory()
historyList.innerHTML = ''
if (h.length === 0) {
historyList.innerHTML =
'<div style="color:var(--muted); font-size:13px">No history yet — calculate something romantic!</div>'
return
}
for (const entry of h) {
const el = document.createElement('div')
el.className = 'history-item'
const left = document.createElement('div')
left.innerHTML = `<strong>${entry.name1}</strong> + <strong>${
entry.name2
}</strong><div style="color:var(--muted); font-size:12px">${new Date(
entry.t
).toLocaleString()}</div>`
const right = document.createElement('div')
right.innerHTML = `<div style="text-align:right"><span style="font-weight:800">${entry.percent}%</span><div style="font-size:12px;color:var(--muted)">${entry.msg}</div></div>`
el.appendChild(left)
el.appendChild(right)
historyList.appendChild(el)
}
}
/* ============================
Share / URL
============================ */
function makeShareableUrl(name1, name2, percent) {
const base = location.origin + location.pathname
const params = new URLSearchParams({ n1: name1, n2: name2, p: percent })
return `${base}?${params.toString()}`
}
function isValidName(name) {
// Allows letters, spaces; rejects numbers, symbols
return /^[A-Za-z\s]+$/.test(name.trim())
}
function alertDialog(message, title = 'Warning') {
const alertBox = document.getElementById('customAlert')
const alertTitle = document.getElementById('alertTitle')
const alertMessage = document.getElementById('alertMessage')
const alertBtn = document.getElementById('alertOkBtn')
alertTitle.textContent = title
alertMessage.textContent = message
// Show alert
alertBox.classList.add('show')
// Hide alert on button click
alertBtn.onclick = () => {
alertBox.classList.remove('show')
}
}
// Lightweight toast notification
function showToast(message) {
try {
const existing = document.querySelector('.lc-toast')
if (existing) existing.remove()
const toast = document.createElement('div')
toast.className = 'lc-toast'
toast.textContent = message
document.body.appendChild(toast)
// auto remove after animation
setTimeout(() => {
toast.classList.add('hide')
setTimeout(() => toast.remove(), 300)
}, 1800)
} catch (_) {}
}
/* ============================
Main calculate function
============================ */
function calculateLove() {
const name1 = name1El.value.trim()
const name2 = name2El.value.trim()
const allowJitter = allowJitterEl.checked
const supportMaster = useMasterEl.checked
if (!name1 || !name2) {
alertDialog('Please enter both names to calculate love ✨')
return
}
if (!isValidName(name1) || !isValidName(name2)) {
alertDialog('Please enter valid names: letters, spaces only.', 'Invalid Input')
return
}
// Compute numerology numbers
const num1 = nameToNumber(name1, supportMaster)