personal-website/assets/script.js

44 lines
1.3 KiB
JavaScript
Raw Normal View History

2024-03-16 04:04:38 -05:00
if (typeof age !== 'undefined') {
const difference = (Date.now() - 1182722400000) / (1000 * 60 * 60 * 24 * 365);
age.textContent = difference.toFixed(4);
}
2024-03-16 05:03:32 -05:00
if (typeof arrow_top !== 'undefined' && typeof arrow_bottom !== 'undefined') {
[arrow_top, arrow_bottom].forEach(arrow => {
arrow.addEventListener('click', () => {
console.warn('scroll!')
window.scrollTo({
top: arrow === arrow_top ? 0 : document.body.scrollHeight,
behavior: 'smooth'
});
2024-03-16 04:04:38 -05:00
});
});
}
const smoothScrollLinks = document.querySelectorAll('a[href^="#"]');
smoothScrollLinks.forEach(link => {
link.addEventListener('click', event => {
event.preventDefault();
const target = document.querySelector(event.target.hash);
target.scrollIntoView({
behavior: 'smooth'
});
});
});
const theme = localStorage.getItem('theme');
2024-03-16 05:03:32 -05:00
switch_theme?.addEventListener('click', () => {
2024-03-16 04:04:38 -05:00
if (theme === 'dark') {
localStorage.setItem('theme', 'light');
} else {
localStorage.setItem('theme', 'dark');
}
document.body.classList.toggle('dark');
});
if (theme === 'dark') {
document.body.classList.add('dark');
}