/** * Main initialization and event handlers */ // Initialize on DOM load document.addEventListener('DOMContentLoaded', () => { initializeForms(); loadProviders(); loadDownloads(); setInterval(loadDownloads, 1000); // Load home content (recommendations & releases) loadHomeContent(); }); /** * Initialize form event listeners */ function initializeForms() { // Search form document.getElementById('searchInput').addEventListener('keypress', (e) => { if (e.key === 'Enter') { handleSearch(); } }); // Direct download form document.getElementById('downloadForm').addEventListener('submit', handleDirectDownload); } /** * Load providers dynamically */ async function loadProviders() { try { const data = await getProvidersInfo(); // Update anime tabs const animeTabsContainer = document.querySelector('.tabs'); const existingAnimeTabs = animeTabsContainer.querySelectorAll('.tab[data-tab-type="anime"]'); existingAnimeTabs.forEach(tab => tab.remove()); // Add anime provider tabs Object.entries(data.anime_providers).forEach(([id, provider]) => { // Check if tab doesn't exist if (!document.querySelector(`.tab[data-provider="${id}"]`)) { const button = document.createElement('button'); button.className = 'tab'; button.setAttribute('data-tab-type', 'anime'); button.setAttribute('data-provider', id); button.innerHTML = `${provider.icon} ${provider.name}`; button.onclick = () => switchTab(`anime-${id}`); animeTabsContainer.appendChild(button); // Create corresponding tab content const tabContent = document.createElement('div'); tabContent.id = `tab-anime-${id}`; tabContent.className = 'tab-content'; tabContent.innerHTML = createAnimeTabContent(id, provider); document.querySelector('.container').insertBefore( tabContent, document.getElementById('downloadsList') ); } }); // Add series provider tabs const existingSeriesTabs = animeTabsContainer.querySelectorAll('.tab[data-tab-type="series"]'); existingSeriesTabs.forEach(tab => tab.remove()); Object.entries(data.series_providers || {}).forEach(([id, provider]) => { // Check if tab doesn't exist if (!document.querySelector(`.tab[data-provider="${id}"]`)) { const button = document.createElement('button'); button.className = 'tab'; button.setAttribute('data-tab-type', 'series'); button.setAttribute('data-provider', id); button.innerHTML = `${provider.icon} ${provider.name}`; button.onclick = () => switchTab(`series-${id}`); animeTabsContainer.appendChild(button); // Create corresponding tab content const tabContent = document.createElement('div'); tabContent.id = `tab-series-${id}`; tabContent.className = 'tab-content'; tabContent.innerHTML = createSeriesTabContent(id, provider); document.querySelector('.container').insertBefore( tabContent, document.getElementById('downloadsList') ); } }); // Update supported hosts badges const hostsContainer = document.querySelector('.supported-hosts'); hostsContainer.innerHTML = ''; Object.values(data.file_hosts).forEach(host => { const badge = document.createElement('span'); badge.className = 'host-badge'; badge.textContent = `${host.icon} ${host.name}`; hostsContainer.appendChild(badge); }); } catch (error) { console.error('Error loading providers:', error); } } /** * Create anime provider tab content */ function createAnimeTabContent(providerId, provider) { return `