const adOverlay = document.getElementById('thank-you-message'); const content = document.getElementById('content'); let adTimeout; function closeAd() { clearTimeout(adTimeout); adOverlay.style.display = 'none'; adOverlay.setAttribute('aria-hidden', 'true'); content.style.visibility = 'visible'; document.querySelectorAll('.emoji').forEach(button => button.classList.remove('selected')); } function showAd(duration, hideContent = false) { clearTimeout(adTimeout); adOverlay.style.display = 'block'; adOverlay.setAttribute('aria-hidden', 'false'); content.style.visibility = hideContent ? 'hidden' : 'visible'; adTimeout = setTimeout(closeAd, duration); } document.getElementById('on-vote-ad-button').addEventListener('click', () => showAd(10000)); document.getElementById('close-ad-button').addEventListener('click', closeAd); document.querySelectorAll('.emoji').forEach(button => { button.addEventListener('click', () => { const category = button.getAttribute('data-category'); const results = {}; results[category] = button.id; fetch('/submit', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(results) }) .then(response => response.json()) .then(data => { console.log('Success:', data); showAd(4000, true); }) .catch((error) => { console.error('Error:', error); }); }); });