-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmyscript.js
More file actions
285 lines (249 loc) · 9.43 KB
/
Copy pathmyscript.js
File metadata and controls
285 lines (249 loc) · 9.43 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
/* =============================================
GOUTHAM JOSH — PORTFOLIO 2026
myscript.js
============================================= */
document.addEventListener('DOMContentLoaded', () => {
/* ---- AUTO AGE CALCULATION ----
Birthday: 19 April 2006
Updates automatically on load and every year */
const BIRTHDAY = new Date('2006-04-19');
function calcAge(birthday) {
const today = new Date();
let age = today.getFullYear() - birthday.getFullYear();
const monthDiff = today.getMonth() - birthday.getMonth();
if (monthDiff < 0 || (monthDiff === 0 && today.getDate() < birthday.getDate())) {
age--;
}
return age;
}
const currentAge = calcAge(BIRTHDAY);
// Update all age display elements
['ageDisplay', 'ageStatDisplay'].forEach(id => {
const el = document.getElementById(id);
if (el) el.textContent = currentAge;
});
// Footer year
const footerYear = document.getElementById('footerYear');
if (footerYear) footerYear.textContent = new Date().getFullYear();
/* ---- CURSOR GLOW ---- */
const glow = document.getElementById('cursorGlow');
if (glow) {
let mouseX = 0, mouseY = 0;
let glowX = 0, glowY = 0;
document.addEventListener('mousemove', e => {
mouseX = e.clientX; mouseY = e.clientY;
});
function animateGlow() {
glowX += (mouseX - glowX) * 0.08;
glowY += (mouseY - glowY) * 0.08;
glow.style.left = glowX + 'px';
glow.style.top = glowY + 'px';
requestAnimationFrame(animateGlow);
}
animateGlow();
}
/* ---- NAVBAR SCROLL ---- */
const navbar = document.getElementById('navbar');
if (navbar) {
window.addEventListener('scroll', () => {
navbar.classList.toggle('scrolled', window.scrollY > 60);
}, { passive: true });
}
/* ---- MOBILE MENU ---- */
const menuBtn = document.getElementById('menuBtn');
const mobileMenu = document.getElementById('mobileMenu');
if (menuBtn && mobileMenu) {
menuBtn.addEventListener('click', () => {
const isOpen = mobileMenu.classList.toggle('open');
menuBtn.classList.toggle('open', isOpen);
menuBtn.setAttribute('aria-expanded', String(isOpen));
mobileMenu.setAttribute('aria-hidden', String(!isOpen));
});
// Close on link click
mobileMenu.querySelectorAll('a').forEach(a => {
a.addEventListener('click', () => {
mobileMenu.classList.remove('open');
menuBtn.classList.remove('open');
menuBtn.setAttribute('aria-expanded', 'false');
mobileMenu.setAttribute('aria-hidden', 'true');
});
});
}
/* ---- SMOOTH SCROLL ---- */
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function (e) {
const target = this.getAttribute('href');
if (!target || target === '#') return;
const el = document.querySelector(target);
if (!el) return;
e.preventDefault();
el.scrollIntoView({ behavior: 'smooth', block: 'start' });
});
});
/* ---- TYPING ANIMATION ---- */
const typingEl = document.getElementById('typingTarget');
const roles = ['BCA Student', 'Bot Developer', 'Cybersecurity Enthusiast', 'Automation Architect', ':)'];
if (typingEl && roles.length) {
let roleIdx = 0;
let charIdx = 0;
let isDeleting = false;
let pause = false;
function type() {
const current = roles[roleIdx];
if (pause) {
setTimeout(type, 1200);
pause = false;
return;
}
if (!isDeleting) {
typingEl.textContent = current.slice(0, charIdx + 1);
charIdx++;
if (charIdx === current.length) {
isDeleting = true; pause = true;
setTimeout(type, 80);
return;
}
} else {
typingEl.textContent = current.slice(0, charIdx - 1);
charIdx--;
if (charIdx === 0) {
isDeleting = false;
roleIdx = (roleIdx + 1) % roles.length;
}
}
setTimeout(type, isDeleting ? 55 : 90);
}
type();
}
/* ---- SCROLL REVEAL ---- */
const revealEls = document.querySelectorAll('[data-reveal]');
if ('IntersectionObserver' in window) {
const observer = new IntersectionObserver((entries) => {
entries.forEach((entry, i) => {
if (entry.isIntersecting) {
const el = entry.target;
const delay = el.dataset.revealDelay || (i * 60);
setTimeout(() => el.classList.add('revealed'), Number(delay));
observer.unobserve(el);
}
});
}, { threshold: 0.12, rootMargin: '0px 0px -40px 0px' });
revealEls.forEach(el => observer.observe(el));
} else {
revealEls.forEach(el => el.classList.add('revealed'));
}
/* ---- MUSIC PLAYER ---- */
const audioFiles = ['assests/music1.mp3', 'assests/music2.mp3', 'assests/music3.mp3'];
const tracks = audioFiles.map(src => {
const a = new Audio(src);
a.preload = 'none';
return a;
});
const trackBtns = [
document.getElementById('pb1'),
document.getElementById('pb2'),
document.getElementById('pb3')
].filter(Boolean);
const nowPlayingEl = document.getElementById('nowPlaying');
const eqEl = document.getElementById('equalizer');
let current = -1;
function stopAll() {
tracks.forEach(t => { t.pause(); t.currentTime = 0; });
trackBtns.forEach((btn, i) => {
if (btn) { btn.textContent = `▶ track_0${i + 1}`; btn.classList.remove('playing'); }
});
if (nowPlayingEl) nowPlayingEl.textContent = '// no track playing';
if (eqEl) eqEl.classList.remove('playing');
current = -1;
}
trackBtns.forEach((btn, idx) => {
if (!btn) return;
const track = tracks[idx];
btn.addEventListener('click', () => {
if (current !== idx) {
stopAll();
current = idx;
track.play().catch(err => { if (err.name !== 'AbortError') console.warn('Audio play error:', err); });
btn.textContent = `⏸ track_0${idx + 1}`;
btn.classList.add('playing');
if (nowPlayingEl) nowPlayingEl.textContent = `// playing: track_0${idx + 1}`;
if (eqEl) eqEl.classList.add('playing');
} else {
if (track.paused) {
track.play().catch(err => { if (err.name !== 'AbortError') console.warn(err); });
btn.textContent = `⏸ track_0${idx + 1}`;
btn.classList.add('playing');
if (eqEl) eqEl.classList.add('playing');
} else {
track.pause();
btn.textContent = `▶ track_0${idx + 1}`;
btn.classList.remove('playing');
if (eqEl) eqEl.classList.remove('playing');
}
}
});
track.addEventListener('ended', () => stopAll());
});
/* ---- CONTACT FORM ---- */
const contactForm = document.getElementById('contactForm');
if (contactForm) {
contactForm.addEventListener('submit', function (e) {
e.preventDefault();
const name = (this.querySelector('[name="name"]')?.value || '').trim();
const email = (this.querySelector('[name="email"]')?.value || '').trim();
const message = (this.querySelector('[name="message"]')?.value || '').trim();
if (!name || !email || !message) {
alert('Please fill in all fields before sending.');
return;
}
const subject = encodeURIComponent(`Portfolio Contact from ${name}`);
const body = encodeURIComponent(`Name: ${name}\nEmail: ${email}\n\n${message}`);
window.location.href = `mailto:gouthamjosh22@gmail.com?subject=${subject}&body=${body}`;
});
}
/* ---- BACK TO TOP ---- */
const backToTop = document.getElementById('backToTop');
if (backToTop) {
window.addEventListener('scroll', () => {
backToTop.classList.toggle('show', window.scrollY > 300);
}, { passive: true });
backToTop.addEventListener('click', () => window.scrollTo({ top: 0, behavior: 'smooth' }));
}
/* ---- GLITCH / SHUFFLE TEXT LOGO ---- */
const logoText = document.getElementById('logoText');
if (logoText) {
const original = 'GJ';
const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
logoText.addEventListener('mouseenter', () => {
let iter = 0;
const interval = setInterval(() => {
logoText.textContent = original.split('').map((c, i) =>
i < iter ? original[i] : chars[Math.floor(Math.random() * chars.length)]
).join('');
if (iter >= original.length) clearInterval(interval);
iter += 0.5;
}, 60);
});
}
/* ---- PROJECT CARD STAGGER ---- */
document.querySelectorAll('.project-card[data-reveal]').forEach((card, i) => {
card.dataset.revealDelay = i * 100;
});
/* ---- ACTIVE NAV HIGHLIGHT on scroll ---- */
const sections = document.querySelectorAll('section[id]');
const navAs = document.querySelectorAll('.nav-links a');
if (sections.length && navAs.length) {
const sectionObserver = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
navAs.forEach(a => {
a.style.color = '';
});
const active = document.querySelector(`.nav-links a[href="#${entry.target.id}"]`);
if (active) active.style.color = 'var(--cyan)';
}
});
}, { threshold: 0.4 });
sections.forEach(s => sectionObserver.observe(s));
}
});