// 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 = ' 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'; } }