File size: 1,581 Bytes
b2a125d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
document.addEventListener('DOMContentLoaded', function() {
    // Theme toggle functionality
    const themeToggle = document.getElementById('theme-toggle');
    const htmlElement = document.documentElement;
    
    // Check for saved theme preference or use preferred color scheme
    if (localStorage.getItem('theme') === 'dark' || 
        (!localStorage.getItem('theme') && window.matchMedia('(prefers-color-scheme: dark)').matches)) {
        htmlElement.classList.add('dark');
    } else {
        htmlElement.classList.remove('dark');
    }
    
    themeToggle.addEventListener('click', function() {
        htmlElement.classList.toggle('dark');
        localStorage.setItem('theme', htmlElement.classList.contains('dark') ? 'dark' : 'light');
        feather.replace();
    });
    
    // Update feather icons when theme changes
    const observer = new MutationObserver(function(mutations) {
        mutations.forEach(function(mutation) {
            if (mutation.attributeName === 'class') {
                feather.replace();
            }
        });
    });
    
    observer.observe(htmlElement, {
        attributes: true
    });
    
    // Initialize tooltips for buttons
    const buttons = document.querySelectorAll('button');
    buttons.forEach(button => {
        if (button.querySelector('[data-feather]')) {
            const icon = button.querySelector('[data-feather]');
            const iconName = icon.getAttribute('data-feather');
            button.setAttribute('title', iconName.charAt(0).toUpperCase() + iconName.slice(1));
        }
    });
});