document.addEventListener('DOMContentLoaded', () => { // Load surahs data fetch('https://api.alquran.cloud/v1/surah') .then(response => response.json()) .then(data => { const surahsContainer = document.querySelector('#surahs .grid'); data.data.forEach(surah => { const surahCard = document.createElement('div'); surahCard.className = 'surah-card bg-white rounded-xl shadow-md overflow-hidden hover:shadow-lg cursor-pointer'; surahCard.innerHTML = `
${surah.number} ${surah.englishName}

${surah.englishNameTranslation}

${surah.revelationType} • ${surah.numberOfAyahs} verses

`; surahsContainer.appendChild(surahCard); }); }) .catch(error => console.error('Error loading surahs:', error)); }); // Function to load specific surah (to be used in surah.html) function loadSurah(number) { fetch(`https://api.alquran.cloud/v1/surah/${number}/en.asad`) .then(response => response.json()) .then(data => { const surahData = data.data; document.title = `${surahData.englishName} (${surahData.englishNameTranslation}) | Quranic Insights Explorer`; // Update header const header = document.querySelector('.surah-header'); if (header) { header.innerHTML = `

${surahData.englishNameTranslation} (${surahData.englishName})

${surahData.revelationType} • ${surahData.numberOfAyahs} verses

${surahData.name}

`; } // Load verses const versesContainer = document.querySelector('.verses-container'); if (versesContainer) { surahData.ayahs.forEach(ayah => { const verseElement = document.createElement('div'); verseElement.className = 'verse-container bg-white p-4 rounded-lg mb-4 shadow-sm'; verseElement.innerHTML = `
${ayah.numberInSurah}

${ayah.text}

${ayah.translation}

`; versesContainer.appendChild(verseElement); }); } }) .catch(error => console.error('Error loading surah:', error)); } // Check if we're on surah.html and load the specific surah if (window.location.pathname.includes('surah.html')) { const params = new URLSearchParams(window.location.search); const surahNumber = params.get('number'); if (surahNumber) { loadSurah(surahNumber); } }