document.addEventListener('DOMContentLoaded', function() {
lucide.createIcons();
initScrollAnimations();
initSmoothScroll();
});
function copyCode(text) {
navigator.clipboard.writeText(text).then(() => {
const btn = event.target.closest('.copy-btn');
if (!btn) return;
const originalHTML = btn.innerHTML;
btn.innerHTML = '<i data-lucide="check" class="w-3 h-3"></i><span>Copied!</span>';
btn.classList.add('text-github-accent');
lucide.createIcons();
setTimeout(() => {
btn.innerHTML = originalHTML;
btn.classList.remove('text-github-accent');
lucide.createIcons();
}, 2000);
}).catch(err => {
console.error('Failed to copy:', err);
});
}
function initSmoothScroll() {
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function(e) {
e.preventDefault();
const targetId = this.getAttribute('href');
const target = document.querySelector(targetId);
if (target) {
const headerOffset = 80;
const elementPosition = target.getBoundingClientRect().top;
const offsetPosition = elementPosition + window.pageYOffset - headerOffset;
window.scrollTo({
top: offsetPosition,
behavior: 'smooth'
});
}
});
});
}
function initScrollAnimations() {
const observerOptions = {
threshold: 0.1,
rootMargin: '0px 0px -50px 0px'
};
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.classList.add('is-visible');
observer.unobserve(entry.target);
}
});
}, observerOptions);
document.querySelectorAll('.feature-card').forEach((el, index) => {
el.style.transitionDelay = `${index * 0.1}s`;
observer.observe(el);
});
}
document.querySelectorAll('a[target="_blank"]').forEach(link => {
link.addEventListener('click', function(e) {
if (!this.rel || !this.rel.includes('noopener')) {
this.rel = this.rel ? `${this.rel} noopener` : 'noopener';
}
});
});
document.addEventListener('keydown', function(e) {
if ((e.metaKey || e.ctrlKey) && e.key === 'k') {
e.preventDefault();
const featuresSection = document.getElementById('features');
if (featuresSection) {
featuresSection.scrollIntoView({ behavior: 'smooth' });
}
}
});