|
|
|
|
|
|
|
|
document.addEventListener('DOMContentLoaded', function() { |
|
|
console.log('SxHub loaded successfully! π§'); |
|
|
|
|
|
|
|
|
initThemeToggle(); |
|
|
initCopyButtons(); |
|
|
initSmoothLinks(); |
|
|
}); |
|
|
|
|
|
|
|
|
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(); |
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
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); |
|
|
} |
|
|
}); |
|
|
}); |
|
|
} |
|
|
|
|
|
|
|
|
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' |
|
|
}); |
|
|
} |
|
|
}); |
|
|
}); |
|
|
} |
|
|
|
|
|
|
|
|
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'; |
|
|
} |
|
|
} |