-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathscript.js
More file actions
382 lines (323 loc) · 10.3 KB
/
script.js
File metadata and controls
382 lines (323 loc) · 10.3 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
// SOUND EFFECTS MANAGEMENT
class SoundManager {
constructor() {
this.sounds = {
hover: document.getElementById("hoverSound"),
click: document.getElementById("clickSound"),
social: document.getElementById("socialSound"),
};
this.isMuted = false;
this.volume = 0.3;
this.init();
}
init() {
// Set volume for all sounds
Object.values(this.sounds).forEach((sound) => {
if (sound) {
sound.volume = this.volume;
}
});
this.createMuteButton();
}
play(soundName) {
if (this.isMuted || !this.sounds[soundName]) return;
try {
this.sounds[soundName].currentTime = 0;
this.sounds[soundName].play().catch((e) => {
console.log("Audio play failed:", e);
});
} catch (error) {
console.log("Sound error:", error);
}
}
toggleMute() {
this.isMuted = !this.isMuted;
localStorage.setItem("soundMuted", this.isMuted);
return this.isMuted;
}
setVolume(volume) {
this.volume = Math.max(0, Math.min(0.3, volume));
Object.values(this.sounds).forEach((sound) => {
if (sound) {
sound.volume = this.volume;
}
});
}
createMuteButton() {
const muteButton = document.createElement("button");
muteButton.innerHTML = "🔊";
muteButton.id = "muteToggle";
muteButton.setAttribute("aria-label", "Toggle sound effects");
const savedMuteState = localStorage.getItem("soundMuted");
if (savedMuteState === "true") {
this.isMuted = true;
muteButton.innerHTML = "🔇";
}
muteButton.addEventListener("click", () => {
const isMuted = this.toggleMute();
muteButton.innerHTML = isMuted ? "🔇" : "🔊";
muteButton.style.borderColor = isMuted
? "#ff6b6b"
: "var(--accent-color)";
if (!isMuted) {
this.play("click");
}
});
muteButton.addEventListener("mouseenter", () => {
if (!this.isMuted) {
this.play("hover");
}
});
document.body.appendChild(muteButton);
}
}
const soundManager = new SoundManager();
function initHoverSounds() {
// Navigation links
const navLinks = document.querySelectorAll(".main-nav a");
navLinks.forEach((link) => {
link.addEventListener("mouseenter", () => {
soundManager.play("hover");
});
link.addEventListener("click", () => {
soundManager.play("click");
});
});
const ctaButton = document.querySelector(".cta-button");
if (ctaButton) {
ctaButton.addEventListener("mouseenter", () => {
soundManager.play("hover");
});
ctaButton.addEventListener("click", () => {
soundManager.play("click");
});
}
const socialIcons = document.querySelectorAll(".social-icon");
socialIcons.forEach((icon) => {
icon.addEventListener("mouseenter", () => {
soundManager.play("social");
});
icon.addEventListener("click", () => {
soundManager.play("click");
});
});
const contactItems = document.querySelectorAll(".contact-item");
contactItems.forEach((item) => {
item.addEventListener("mouseenter", () => {
soundManager.play("hover");
});
item.addEventListener("click", () => {
soundManager.play("click");
});
});
const avatar = document.querySelector(".avatar");
if (avatar) {
avatar.addEventListener("mouseenter", () => {
soundManager.play("hover");
});
avatar.addEventListener("click", () => {
soundManager.play("click");
});
}
const profileAvatar = document.querySelector(".avatar--small");
if (profileAvatar) {
profileAvatar.addEventListener("mouseenter", () => {
soundManager.play("hover");
});
}
// Cards hover
const cards = document.querySelectorAll(".about-me-box, .detail-box");
cards.forEach((card) => {
card.addEventListener("mouseenter", () => {
soundManager.play("hover");
});
});
}
// Pupil tracking
const leftPupil = document.getElementById("leftPupil");
const rightPupil = document.getElementById("rightPupil");
const leftEye = document.getElementById("leftEye");
const rightEye = document.getElementById("rightEye");
const mouth = document.getElementById("mouth");
const avatar = document.getElementById("avatar");
const maxMove = 14;
// FETCH DATA FROM JSON FILE
function getMemberIndexFromURL() {
const urlParams = new URLSearchParams(window.location.search);
const memberParam = urlParams.get("member");
return memberParam !== null ? parseInt(memberParam) : 0;
}
const SELECTED_USER_INDEX = getMemberIndexFromURL();
async function loadUserData() {
try {
const response = await fetch("./data/data_info.json");
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const jsonData = await response.json();
let userData;
if (Array.isArray(jsonData)) {
userData = jsonData.find((user) => user.index === SELECTED_USER_INDEX);
if (!userData) {
userData = jsonData[SELECTED_USER_INDEX];
}
if (!userData) {
throw new Error(`User with index ${SELECTED_USER_INDEX} not found`);
}
console.log(
`Loaded user profile at index ${SELECTED_USER_INDEX}:`,
userData
);
} else {
userData = jsonData;
console.log("Loaded single user profile:", userData);
}
// Update hero section name
const heroName = document.getElementById("hero-name");
if (heroName) {
heroName.textContent = userData.name;
}
const aboutText = document.getElementById("about-text");
if (aboutText && userData.about) {
aboutText.textContent = userData.about;
}
const profileAvatar = document.getElementById("profile-avatar");
if (profileAvatar && userData.avatar) {
profileAvatar.src = userData.avatar;
profileAvatar.alt = `${userData.name}'s Avatar`;
}
// Update detail section
const detailName = document.getElementById("detail-name");
if (detailName) {
detailName.textContent = userData.name;
}
const detailAge = document.getElementById("detail-age");
if (detailAge) {
detailAge.textContent = `${userData.age} years`;
}
const detailLocation = document.getElementById("detail-location");
if (detailLocation && userData.location) {
detailLocation.textContent = userData.location;
}
const detailUniversity = document.getElementById("detail-university");
if (detailUniversity && userData.university) {
detailUniversity.textContent = userData.university;
}
const detailPhone = document.getElementById("detail-phone");
if (detailPhone) {
detailPhone.textContent = userData.phone;
}
const detailEmail = document.getElementById("detail-email");
if (detailEmail) {
detailEmail.textContent = userData.email;
}
// Update footer section
const footerPhone = document.getElementById("footer-phone");
if (footerPhone) {
footerPhone.textContent = userData.phone;
}
const footerEmail = document.getElementById("footer-email");
if (footerEmail) {
footerEmail.textContent = userData.email;
footerEmail.href = `mailto:${userData.email}`;
}
} catch (error) {
console.error("Error loading user data:", error);
alert("Failed to load user data. Please check the console for details.");
}
}
document.addEventListener("DOMContentLoaded", function () {
loadUserData();
initHoverSounds();
});
// PUPIL TRACKING
document.addEventListener("mousemove", function (e) {
const mouseX = e.clientX;
const mouseY = e.clientY;
updatePupil(leftPupil, mouseX, mouseY);
updatePupil(rightPupil, mouseX, mouseY);
});
function updatePupil(pupil, mouseX, mouseY) {
const eye = pupil.parentElement;
const eyeRect = eye.getBoundingClientRect();
const eyeCenterX = eyeRect.left + eyeRect.width / 2;
const eyeCenterY = eyeRect.top + eyeRect.height / 2;
const deltaX = mouseX - eyeCenterX;
const deltaY = mouseY - eyeCenterY;
const angle = Math.atan2(deltaY, deltaX);
const distance = Math.sqrt(deltaX * deltaX + deltaY * deltaY);
const moveDistance = Math.min(maxMove, distance / 12);
const pupilX = Math.cos(angle) * moveDistance;
const pupilY = Math.sin(angle) * moveDistance;
pupil.style.transform = `translate(${pupilX}px, ${pupilY}px)`;
}
function blink() {
leftEye.classList.add("blinking");
rightEye.classList.add("blinking");
setTimeout(() => {
leftEye.classList.remove("blinking");
rightEye.classList.remove("blinking");
}, 150);
}
setInterval(blink, 4000);
avatar.addEventListener("mouseenter", () => {
mouth.classList.add("smiling");
});
avatar.addEventListener("mouseleave", () => {
mouth.classList.remove("smiling");
});
avatar.addEventListener("click", () => {
avatar.classList.add("clicked");
setTimeout(() => avatar.classList.remove("clicked"), 600);
});
// Scroll progress bar
const scrollContainer = document.getElementById("scrollContainer");
const scrollProgress = document.getElementById("scrollProgress");
scrollContainer.addEventListener("scroll", () => {
const scrollTop = scrollContainer.scrollTop;
const scrollHeight =
scrollContainer.scrollHeight - scrollContainer.clientHeight;
const scrollPercentage = (scrollTop / scrollHeight) * 100;
scrollProgress.style.width = scrollPercentage + "%";
});
// Smooth scroll to section
function scrollToSection(sectionId) {
const section = document.getElementById(sectionId);
section.scrollIntoView({ behavior: "smooth" });
}
function copyToClipboard(text) {
navigator.clipboard
.writeText(text)
.then(() => {
showCopyNotification();
})
.catch((err) => {
console.error("Failed to copy:", err);
});
}
function showCopyNotification() {
const notification = document.getElementById("copyNotification");
notification.classList.add("show");
setTimeout(() => {
notification.classList.remove("show");
}, 2500);
}
const observerOptions = {
threshold: 0.2,
rootMargin: "0px 0px -100px 0px",
};
const observer = new IntersectionObserver((entries) => {
entries.forEach((entry) => {
if (entry.isIntersecting) {
entry.target.style.opacity = "1";
entry.target.style.transform = "translateY(0)";
}
});
}, observerOptions);
// Observe elements for animation
document.querySelectorAll(".about-me-box, .detail-box").forEach((el) => {
el.style.opacity = "0";
el.style.transform = "translateY(50px)";
el.style.transition = "all 0.8s ease-out";
observer.observe(el);
});