English Translation
${item.english.replace(/\n/g, '
')}
`;
verseBlock.appendChild(verseHeader);
verseBlock.appendChild(meaningDropdown);
verseBlock.addEventListener('click', () => {
const isActive = meaningDropdown.classList.contains('active');
document.querySelectorAll('.meaning-dropdown.active').forEach(dropdown => {
dropdown.classList.remove('active');
});
document.querySelectorAll('.dropdown-icon.open').forEach(icon => {
icon.classList.remove('open');
});
if (!isActive) {
meaningDropdown.classList.add('active');
dropdownIcon.classList.add('open');
}
});
chalisaContainer.appendChild(verseBlock);
// Add ad placeholder after every 5th verse
// Add Adsense ad after every 5th verse
if (index === 5 || (index + 1) % 15 === 0) {
const adPlaceholder = document.createElement('div');
adPlaceholder.className = 'ad-placeholder';
adPlaceholder.innerHTML = `
`;
chalisaContainer.appendChild(adPlaceholder);
// Dynamically render AdSense ad (Google's recommendation)
if (window.adsbygoogle && Array.isArray(window.adsbygoogle)) {
window.adsbygoogle.push({});
}
}
// If this is the first match, store it for scrolling
if (firstMatchElement === null) {
firstMatchElement = verseBlock;
}
});
};
// Function to filter verses based on search input
const filterVerses = () => {
const searchTerm = searchInput.value.toLowerCase().trim();
if (!searchTerm) {
renderVerses(chalisaData);
return;
}
const firstMatchIndex = chalisaData.findIndex(item => {
const teluguMatch = fuzzyMatch(item.telugu, searchTerm);
const meaningTeluguMatch = fuzzyMatch(item.meaningTelugu, searchTerm);
const englishMatch = fuzzyMatch(item.english, searchTerm);
const hinglishMatch = fuzzyMatch(item.hinglish, searchTerm);
return teluguMatch || meaningTeluguMatch || englishMatch || hinglishMatch;
});
if (firstMatchIndex !== -1) {
const filteredData = chalisaData.slice(firstMatchIndex);
renderVerses(filteredData);
} else {
renderVerses([]);
}
};
// Function to refresh the page
const refreshPage = () => {
searchInput.value = ''; // Clear search input
renderVerses(chalisaData); // Render all verses
};
// Initial render
renderVerses(chalisaData);
// Add event listener for search button
searchButton.addEventListener('click', filterVerses);
// Add event listener for refresh button
refreshButton.addEventListener('click', refreshPage);
// Optional: Allow pressing Enter key in search bar to trigger search
searchInput.addEventListener('keypress', (event) => {
if (event.key === 'Enter') {
filterVerses();
}
});