-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
95 lines (85 loc) · 3.07 KB
/
script.js
File metadata and controls
95 lines (85 loc) · 3.07 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
function yearsSince(birthdate) {
const currentDate = new Date();
let age = currentDate.getFullYear() - birthdate.getFullYear();
if (currentDate.getMonth() < birthdate.getMonth() ||
(currentDate.getMonth() === birthdate.getMonth() && currentDate.getDate() < birthdate.getDate())) {
age--;
}
return age;
}
function initTheme() {
const storedTheme = localStorage.getItem('theme');
const systemPrefersDark = window.matchMedia('(prefers-color-scheme: dark)').matches;
if (storedTheme === 'dark' || (!storedTheme && systemPrefersDark)) {
document.documentElement.setAttribute('data-theme', 'dark');
} else {
document.documentElement.setAttribute('data-theme', 'light');
}
}
function toggleTheme() {
const currentTheme = document.documentElement.getAttribute('data-theme');
const newTheme = currentTheme === 'dark' ? 'light' : 'dark';
document.documentElement.setAttribute('data-theme', newTheme);
localStorage.setItem('theme', newTheme);
}
document.addEventListener('DOMContentLoaded', () => {
initTheme();
const pfp = document.querySelector('.pfp');
if (pfp) {
pfp.style.opacity = 0;
setTimeout(() => {
pfp.style.transition = 'opacity 0.8s ease';
pfp.style.opacity = 1;
}, 100);
}
const navLinks = document.querySelectorAll('.nav-link');
navLinks.forEach(link => {
link.addEventListener('click', (e) => {
const href = link.getAttribute('href');
// Only prevent default for hash links (internal navigation)
if (!href || !href.startsWith('#')) {
return;
}
e.preventDefault();
const targetId = href;
const targetSection = document.querySelector(targetId);
if (targetSection) {
targetSection.scrollIntoView({
behavior: 'smooth',
block: 'start'
});
history.pushState(null, '', targetId);
}
});
});
const navLogo = document.querySelector('.nav-logo');
if (navLogo) {
navLogo.addEventListener('click', (e) => {
e.preventDefault();
window.scrollTo({
top: 0,
behavior: 'smooth'
});
history.pushState(null, '', '#');
});
}
const sectionTitles = document.querySelectorAll('.section-title');
sectionTitles.forEach(title => {
title.style.cursor = 'pointer';
title.addEventListener('click', (e) => {
const section = e.target.closest('.section');
if (section) {
const targetId = `#${section.id}`;
section.scrollIntoView({
behavior: 'smooth',
block: 'start'
});
history.pushState(null, '', targetId);
}
});
});
const themeToggle = document.getElementById('theme-toggle');
if (themeToggle) {
themeToggle.addEventListener('click', toggleTheme);
}
});