metapodcast / script.js
belos's picture
mets cette muisque en fond et modifie les liens youtube
c260a3c verified
Raw History Blame Contribute Delete
6.54 kB
// Theme toggle functionality
const themeToggle = document.createElement('button');
themeToggle.innerHTML = '<i data-feather="moon" class="w-5 h-5"></i>';
themeToggle.className = 'dark-mode-toggle p-2 rounded-full bg-gray-200 dark:bg-gray-700 text-gray-700 dark:text-gray-300';
themeToggle.setAttribute('aria-label', 'Toggle theme');
// Check for saved theme preference or default to light mode
const savedTheme = localStorage.getItem('theme') || 'light';
document.documentElement.classList.toggle('dark', savedTheme === 'dark');
// Update icon based on current theme
function updateThemeIcon() {
const isDark = document.documentElement.classList.contains('dark');
themeToggle.innerHTML = `<i data-feather="${isDark ? 'sun' : 'moon'}" class="w-5 h-5"></i>`;
localStorage.setItem('theme', isDark ? 'dark' : 'light');
}
// Toggle theme
themeToggle.addEventListener('click', () => {
document.documentElement.classList.toggle('dark');
updateThemeIcon();
feather.replace();
});
// Initialize theme icon
updateThemeIcon();
// Newsletter form handling
document.querySelector('form').addEventListener('submit', (e) => {
e.preventDefault();
const email = e.target.querySelector('input[type="email"]').value;
if (email) {
// Simulate form submission
const button = e.target.querySelector('button');
const originalText = button.textContent;
button.textContent = '✓';
button.classList.add('bg-green-500');
setTimeout(() => {
button.textContent = originalText;
button.classList.remove('bg-green-500');
e.target.reset();
}, 2000);
}
});
// Smooth scroll for anchor links
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function (e) {
e.preventDefault();
const target = document.querySelector(this.getAttribute('href'));
if (target) {
target.scrollIntoView({
behavior: 'smooth',
block: 'start'
});
}
});
});
// Intersection Observer for fade-in animations
const observerOptions = {
threshold: 0.1,
rootMargin: '0px 0px -50px 0px'
};
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.style.opacity = '1';
entry.target.style.transform = 'translateY(0)';
}
});
}, observerOptions);
// Observe all cards
document.querySelectorAll('article').forEach(card => {
card.style.opacity = '0';
card.style.transform = 'translateY(20px)';
card.style.transition = 'opacity 0.6s ease, transform 0.6s ease';
observer.observe(card);
});
// Add loading states for dynamic content
function showLoading(element) {
element.innerHTML = `
<div class="flex justify-center items-center py-12">
<div class="loading-dots">
<div></div>
<div></div>
<div></div>
<div></div>
</div>
</div>
`;
}
// Simulate content loading
window.addEventListener('load', () => {
// Add a subtle loading animation for stats
const stats = document.querySelectorAll('.text-4xl');
stats.forEach((stat, index) => {
const finalValue = stat.textContent;
stat.textContent = '0';
setTimeout(() => {
let counter = 0;
const increment = finalValue.includes('M') ? 1000000 :
finalValue.includes('k') ? 1000 : 1;
const max = parseInt(finalValue);
const timer = setInterval(() => {
counter += increment/10;
stat.textContent = Math.floor(counter).toLocaleString() + finalValue.replace(/[0-9,]/g, '');
if (counter >= max) {
clearInterval(timer);
stat.textContent = finalValue;
}
}, 50);
}, index * 200);
});
});
// Add keyboard navigation
document.addEventListener('keydown', (e) => {
if (e.key === 't' && e.ctrlKey) {
e.preventDefault();
themeToggle.click();
}
});
// Background music player
let musicPlaying = true; // Start with music playing
let youtubePlayer = null;
// Initialize background music
function initBackgroundMusic() {
const musicToggle = document.getElementById('music-toggle');
const volumeSlider = document.getElementById('volume-slider');
const backgroundAudio = document.getElementById('background-audio');
// Start audio automatically
if (backgroundAudio) {
backgroundAudio.volume = 0.2; // Set initial volume
backgroundAudio.play().catch(e => {
console.log('Autoplay prevented:', e);
});
if (musicToggle) {
musicToggle.addEventListener('click', () => {
musicPlaying = !musicPlaying;
if (musicPlaying) {
backgroundAudio.play();
musicToggle.innerHTML = '<i data-feather="pause" class="w-5 h-5"></i>';
} else {
backgroundAudio.pause();
musicToggle.innerHTML = '<i data-feather="play" class="w-5 h-5"></i>';
}
feather.replace();
});
}
if (volumeSlider) {
volumeSlider.addEventListener('input', (e) => {
const volume = e.target.value / 100;
if (backgroundAudio) {
backgroundAudio.volume = volume;
}
});
}
}
// Initialize tooltips
function initTooltips() {
const tooltips = document.querySelectorAll('[data-tooltip]');
tooltips.forEach(element => {
const tooltip = document.createElement('span');
tooltip.className = 'tooltiptext';
tooltip.textContent = element.getAttribute('data-tooltip');
element.classList.add('tooltip');
element.appendChild(tooltip);
});
}
// Run after DOM loads
document.addEventListener('DOMContentLoaded', () => {
initTooltips();
initBackgroundMusic();
// Add subtle parallax effect to hero
window.addEventListener('scroll', () => {
const scrolled = window.pageYOffset;
const hero = document.querySelector('section');
if (hero) {
hero.style.transform = `translateY(${scrolled * 0.5}px)`;
}
});
});
// Export for components
window.METAPODCAST = {
themeToggle,
updateThemeIcon,
musicPlaying
};