-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
49 lines (43 loc) · 1.65 KB
/
script.js
File metadata and controls
49 lines (43 loc) · 1.65 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
document.addEventListener('DOMContentLoaded', () => {
const themeSwitch = document.querySelector('.theme-switch');
const body = document.body;
// Check for saved theme preference or use system preference
const savedTheme = localStorage.getItem('theme');
if (savedTheme) {
body.dataset.theme = savedTheme;
updateIcon(savedTheme);
} else {
const prefersDark = window.matchMedia('(prefers-color-scheme: dark)').matches;
const initialTheme = prefersDark ? 'dark' : 'light';
body.dataset.theme = initialTheme;
updateIcon(initialTheme);
}
themeSwitch.addEventListener('click', () => {
let newTheme = body.dataset.theme === 'light' ? 'dark' : 'light';
body.dataset.theme = newTheme;
localStorage.setItem('theme', newTheme);
updateIcon(newTheme);
});
function updateIcon(theme) {
const icon = themeSwitch.querySelector('i');
if (theme === 'dark') {
icon.classList.remove('fa-moon');
icon.classList.add('fa-sun');
} else {
icon.classList.remove('fa-sun');
icon.classList.add('fa-moon');
}
}
const socialLinks = document.querySelectorAll('.social-link-item');
const linkPreview = document.getElementById('link-preview');
socialLinks.forEach(link => {
link.addEventListener('mouseenter', () => {
const url = link.getAttribute('href');
linkPreview.textContent = url;
linkPreview.style.opacity = '1';
});
link.addEventListener('mouseleave', () => {
linkPreview.style.opacity = '0';
});
});
});