optimized js

This commit is contained in:
speyll
2025-04-25 01:50:29 +01:00
parent 105dc40b11
commit daee992cfb
6 changed files with 228 additions and 2 deletions

View File

@@ -37,15 +37,22 @@ class ThemeManager {
document.documentElement.setAttribute('data-theme', newTheme);
this.updateIcon(!isDark);
localStorage.setItem('theme', newTheme);
// Lazy load sound only when needed
if (!this.sound && this.soundSrc) {
this.sound = new Audio(this.soundSrc);
}
if (this.sound) {
this.sound.play().catch(() => {});
}
// Use requestAnimationFrame for better performance on transition
requestAnimationFrame(() => {
setTimeout(() => {
document.body.classList.remove('theme-transition');
}, 300);
});
}
updateIcon(isDark) {
@@ -56,6 +63,7 @@ class ThemeManager {
}
}
// Initialize when content is loaded
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', () => new ThemeManager());