File size: 2,572 Bytes
6c93a54
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
// Main JavaScript for SxHub

document.addEventListener('DOMContentLoaded', function() {
    console.log('SxHub loaded successfully! 🔧');

    // Initialize any global functionality here
    initThemeToggle();
    initCopyButtons();
    initSmoothLinks();
});

// Example: Simple theme toggle (can be expanded)
function initThemeToggle() {
    const themeToggle = document.getElementById('theme-toggle');
    if (themeToggle) {
        themeToggle.addEventListener('click', function() {
            document.documentElement.classList.toggle('dark');
            const isDark = document.documentElement.classList.contains('dark');
            localStorage.setItem('theme', isDark ? 'dark' : 'light');
            feather.replace(); // Refresh icons
        });
    }
}

// Example: Add copy-to-clipboard functionality to code snippets
function initCopyButtons() {
    document.querySelectorAll('[data-copy]').forEach(button => {
        button.addEventListener('click', async function() {
            const textToCopy = this.getAttribute('data-copy');
            try {
                await navigator.clipboard.writeText(textToCopy);
                const originalHTML = this.innerHTML;
                this.innerHTML = '<i data-feather="check" class="w-4 h-4"></i> Copied!';
                feather.replace();
                setTimeout(() => {
                    this.innerHTML = originalHTML;
                    feather.replace();
                }, 2000);
            } catch (err) {
                console.error('Failed to copy: ', err);
            }
        });
    });
}

// Enhance smooth scrolling for internal links
function initSmoothLinks() {
    document.querySelectorAll('a[href^="#"]').forEach(anchor => {
        anchor.addEventListener('click', function (e) {
            const href = this.getAttribute('href');
            if (href === '#') return;
            e.preventDefault();
            const targetElement = document.querySelector(href);
            if (targetElement) {
                targetElement.scrollIntoView({
                    behavior: 'smooth',
                    block: 'start'
                });
            }
        });
    });
}

// Utility function to fetch and display API status (example)
async function checkApiStatus(endpoint) {
    try {
        const response = await fetch(`https://api.allorigins.win/get?url=${encodeURIComponent(endpoint)}`);
        const data = await response.json();
        return response.ok ? '🟢 Operational' : '🔴 Down';
    } catch (error) {
        return '🟡 Unstable';
    }
}