forked from End2EndAI/valentine-website-2025
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
242 lines (206 loc) · 8.38 KB
/
Copy pathscript.js
File metadata and controls
242 lines (206 loc) · 8.38 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
// Initialize configuration
const config = window.VALENTINE_CONFIG;
// Validate configuration
function validateConfig() {
const warnings = [];
// Check required fields
if (!config.valentineName) {
warnings.push("Valentine's name is not set! Using default.");
config.valentineName = "meu amorzinho";
}
// Validate colors
const isValidHex = (hex) => /^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/.test(hex);
Object.entries(config.colors).forEach(([key, value]) => {
if (!isValidHex(value)) {
warnings.push(`Invalid color for ${key}! Using default.`);
config.colors[key] = getDefaultColor(key);
}
});
// Validate animation values
if (parseFloat(config.animations.floatDuration) < 5) {
warnings.push("Float duration too short! Setting to 5s minimum.");
config.animations.floatDuration = "5s";
}
if (config.animations.heartExplosionSize < 1 || config.animations.heartExplosionSize > 3) {
warnings.push("Heart explosion size should be between 1 and 3! Using default.");
config.animations.heartExplosionSize = 1.5;
}
// Log warnings if any
if (warnings.length > 0) {
console.warn("⚠️ Configuration Warnings:");
warnings.forEach(warning => console.warn("- " + warning));
}
}
// Default color values
function getDefaultColor(key) {
const defaults = {
backgroundStart: "#ffafbd",
backgroundEnd: "#ffc3a0",
buttonBackground: "#ff6b6b",
buttonHover: "#ff8787",
textColor: "#ff4757"
};
return defaults[key];
}
// Set page title
document.title = config.pageTitle;
// Initialize the page content when DOM is loaded
window.addEventListener('DOMContentLoaded', () => {
// Validate configuration first
validateConfig();
// Set texts from config
document.getElementById('valentineTitle').textContent = `${config.valentineName}, meu amorzinho...`;
// Set first question texts
document.getElementById('question1Text').textContent = config.questions.first.text;
document.getElementById('yesBtn1').textContent = config.questions.first.yesBtn;
document.getElementById('noBtn1').textContent = config.questions.first.noBtn;
document.getElementById('secretAnswerBtn').textContent = config.questions.first.secretAnswer;
// Set second question texts
document.getElementById('question2Text').textContent = config.questions.second.text;
document.getElementById('startText').textContent = config.questions.second.startText;
document.getElementById('nextBtn').textContent = config.questions.second.nextBtn;
// Set third question texts
document.getElementById('question3Text').textContent = config.questions.third.text;
document.getElementById('yesBtn3').textContent = config.questions.third.yesBtn;
document.getElementById('noBtn3').textContent = config.questions.third.noBtn;
// Create initial floating elements
createFloatingElements();
// Setup music player
setupMusicPlayer();
});
// Create floating hearts and bears
function createFloatingElements() {
const container = document.querySelector('.floating-elements');
// Create hearts
config.floatingEmojis.hearts.forEach(heart => {
const div = document.createElement('div');
div.className = 'heart';
div.innerHTML = heart;
setRandomPosition(div);
container.appendChild(div);
});
// Create bears
config.floatingEmojis.bears.forEach(bear => {
const div = document.createElement('div');
div.className = 'bear';
div.innerHTML = bear;
setRandomPosition(div);
container.appendChild(div);
});
}
// Set random position for floating elements
function setRandomPosition(element) {
element.style.left = Math.random() * 100 + 'vw';
element.style.animationDelay = Math.random() * 5 + 's';
element.style.animationDuration = 10 + Math.random() * 20 + 's';
}
// Function to show next question
function showNextQuestion(questionNumber) {
document.querySelectorAll('.question-section').forEach(q => q.classList.add('hidden'));
document.getElementById(`question${questionNumber}`).classList.remove('hidden');
}
// Function to move the "No" button when clicked
function moveButton(button) {
const x = Math.random() * (window.innerWidth - button.offsetWidth);
const y = Math.random() * (window.innerHeight - button.offsetHeight);
button.style.position = 'fixed';
button.style.left = x + 'px';
button.style.top = y + 'px';
}
// Love meter functionality
const loveMeter = document.getElementById('loveMeter');
const loveValue = document.getElementById('loveValue');
const extraLove = document.getElementById('extraLove');
function setInitialPosition() {
loveMeter.value = 100;
loveValue.textContent = 100;
loveMeter.style.width = '100%';
}
loveMeter.addEventListener('input', () => {
const value = parseInt(loveMeter.value);
loveValue.textContent = value;
if (value > 100) {
extraLove.classList.remove('hidden');
const overflowPercentage = (value - 100) / 9900;
const extraWidth = overflowPercentage * window.innerWidth * 0.8;
loveMeter.style.width = `calc(100% + ${extraWidth}px)`;
loveMeter.style.transition = 'width 0.3s';
// Show different messages based on the value
if (value >= 5000) {
extraLove.classList.add('super-love');
extraLove.textContent = config.loveMessages.extreme;
} else if (value > 1000) {
extraLove.classList.remove('super-love');
extraLove.textContent = config.loveMessages.high;
} else {
extraLove.classList.remove('super-love');
extraLove.textContent = config.loveMessages.normal;
}
} else {
extraLove.classList.add('hidden');
extraLove.classList.remove('super-love');
loveMeter.style.width = '100%';
}
});
// Initialize love meter
window.addEventListener('DOMContentLoaded', setInitialPosition);
window.addEventListener('load', setInitialPosition);
// Celebration function
function celebrate() {
document.querySelectorAll('.question-section').forEach(q => q.classList.add('hidden'));
const celebration = document.getElementById('celebration');
celebration.classList.remove('hidden');
// Set celebration messages
document.getElementById('celebrationTitle').textContent = config.celebration.title;
document.getElementById('celebrationMessage').textContent = config.celebration.message;
document.getElementById('celebrationEmojis').textContent = config.celebration.emojis;
// Create heart explosion effect
createHeartExplosion();
}
// Create heart explosion animation
function createHeartExplosion() {
for (let i = 0; i < 50; i++) {
const heart = document.createElement('div');
const randomHeart = config.floatingEmojis.hearts[Math.floor(Math.random() * config.floatingEmojis.hearts.length)];
heart.innerHTML = randomHeart;
heart.className = 'heart';
document.querySelector('.floating-elements').appendChild(heart);
setRandomPosition(heart);
}
}
// Music Player Setup
function setupMusicPlayer() {
const musicControls = document.getElementById('musicControls');
const musicToggle = document.getElementById('musicToggle');
const bgMusic = document.getElementById('bgMusic');
const musicSource = document.getElementById('musicSource');
// Only show controls if music is enabled in config
if (!config.music.enabled) {
musicControls.style.display = 'none';
return;
}
// Set music source and volume
musicSource.src = config.music.musicUrl;
bgMusic.volume = config.music.volume || 0.5;
bgMusic.load();
// Try autoplay if enabled
if (config.music.autoplay) {
const playPromise = bgMusic.play();
if (playPromise !== undefined) {
playPromise.catch(error => {
console.log("Autoplay prevented by browser");
musicToggle.textContent = config.music.startText;
});
}
}
// Toggle music on button click
musicToggle.addEventListener('click', () => {
if (bgMusic.paused) {
bgMusic.play();
musicToggle.textContent = config.music.stopText;
} else {
bgMusic.pause();
musicToggle.textContent = config.music.startText;
}
});
}