// Daily Activities System with Anti-Cheat Trivia - FIXED VERSION let triviaTimer = null; let triviaTimeRemaining = 150; // 2:30 minutes let currentTriviaQuestion = 0; let triviaScore = 0; let userPoints = parseInt(localStorage.getItem('conchPoints') || '250'); // Popup tracking let popupTimer = null; let hasSeenPopup = localStorage.getItem('hasSeenActivitiesPopup') === 'true'; let lastPopupDate = localStorage.getItem('lastActivitiesPopupDate'); let hasUsedActivities = localStorage.getItem('hasUsedDailyActivities') === 'true'; // Trivia questions bank const triviaQuestions = [ { question: "Which island is home to the famous swimming pigs?", options: ["Nassau", "Big Major Cay (Pig Beach)", "Paradise Island", "Grand Bahama"], correct: 1, explanation: "Big Major Cay, also known as Pig Beach, is home to the famous swimming pigs of the Bahamas!" }, { question: "What is the national bird of the Bahamas?", options: ["Flamingo", "Pelican", "Hummingbird", "Chickcharnie"], correct: 0, explanation: "The Caribbean Flamingo is the national bird of the Bahamas, often seen in flocks around the islands." }, { question: "How many islands make up the Bahamas?", options: ["Around 200", "Over 500", "About 700", "More than 1000"], correct: 2, explanation: "The Bahamas consists of about 700 islands and cays, though only about 30 are inhabited." }, { question: "What is the traditional Bahamian currency?", options: ["Bahamian Dollar", "Caribbean Peso", "Conch Shell", "Island Token"], correct: 0, explanation: "The Bahamian Dollar (BSD) is the official currency, equal in value to the US Dollar." }, { question: "Which famous explorer is believed to have first landed in the Bahamas?", options: ["Vasco da Gama", "Christopher Columbus", "Ferdinand Magellan", "Sir Francis Drake"], correct: 1, explanation: "Christopher Columbus is believed to have made his first landfall in the New World in the Bahamas in 1492." } ]; // Daily activity completion tracking const activityStatus = { trivia: localStorage.getItem('triviaCompleted') === getToday(), folklore: localStorage.getItem('folkloreCompleted') === getToday(), jokes: localStorage.getItem('jokesCompleted') === getToday(), puzzle: localStorage.getItem('puzzleCompleted') === getToday() }; function getToday() { return new Date().toISOString().split('T')[0]; } // MAIN DAILY ACTIVITIES INITIALIZATION function initializeDailyActivities() { console.log('🎯 Initializing daily activities system...'); // 1. Fix daily activities tab fixDailyActivitiesTab(); // 2. Fix daily activities panel fixDailyActivitiesPanel(); // 3. Fix trivia modal fixTriviaModal(); // 4. Fix other activity modals fixActivityModals(); console.log('✅ Daily activities system initialized!'); } // Fix daily activities tab function fixDailyActivitiesTab() { const activitiesTab = document.getElementById('dailyActivitiesTab'); if (!activitiesTab) { console.log('⚠️ Daily activities tab not found'); return; } // Remove existing listeners by cloning const newActivitiesTab = activitiesTab.cloneNode(true); activitiesTab.parentNode.replaceChild(newActivitiesTab, activitiesTab); newActivitiesTab.addEventListener('click', (e) => { e.preventDefault(); e.stopPropagation(); // Mark as used when panel is opened markActivitiesAsUsed(); const tabContentArea = document.getElementById('tabContentArea'); if (tabContentArea) { const isHidden = tabContentArea.classList.contains('hidden'); if (isHidden) { tabContentArea.classList.remove('hidden'); } else { tabContentArea.classList.add('hidden'); } } }); console.log('✅ Fixed daily activities tab'); } // Fix daily activities panel function fixDailyActivitiesPanel() { const panel = document.getElementById('dailyActivitiesPanel'); if (!panel) { console.log('⚠️ Daily activities panel not found'); return; } // Update points display const pointsElement = panel.querySelector('#userPoints'); if (pointsElement) { pointsElement.textContent = `${userPoints} Conch Points`; } console.log('✅ Fixed daily activities panel'); } // Fix trivia modal function fixTriviaModal() { const triviaBtn = document.getElementById('dailyTriviaBtn'); const triviaModal = document.getElementById('triviaModal'); if (!triviaBtn || !triviaModal) { console.log('⚠️ Trivia elements not found'); return; } // Remove existing listeners by cloning const newTriviaBtn = triviaBtn.cloneNode(true); triviaBtn.parentNode.replaceChild(newTriviaBtn, triviaBtn); newTriviaBtn.addEventListener('click', (e) => { e.preventDefault(); e.stopPropagation(); startTrivia(); }); console.log('✅ Fixed trivia modal'); } // Fix other activity modals function fixActivityModals() { const modals = [ { id: 'folkloreModal', btnId: 'dailyFolkloreBtn', closeId: 'closeFolkloreBtn' }, { id: 'jokesModal', btnId: 'dailyJokesBtn', closeId: 'closeJokesBtn' }, { id: 'puzzleModal', btnId: 'dailyPuzzleBtn', closeId: 'closePuzzleBtn' } ]; modals.forEach(({ id, btnId, closeId }) => { const modal = document.getElementById(id); const btn = document.getElementById(btnId); const closeBtn = document.getElementById(closeId); if (btn && modal) { // Remove existing listeners by cloning const newBtn = btn.cloneNode(true); btn.parentNode.replaceChild(newBtn, btn); newBtn.addEventListener('click', (e) => { e.preventDefault(); e.stopPropagation(); markActivitiesAsUsed(); // Check completion status based on modal type let completed = false; let message = ''; if (id === 'folkloreModal') { completed = activityStatus.folklore; message = 'You\\'ve already read today\\'s folklore! Come back tomorrow.'; } else if (id === 'jokesModal') { completed = activityStatus.jokes; message = 'You\\'ve already enjoyed today\\'s jokes! Come back tomorrow.'; } else if (id === 'puzzleModal') { completed = activityStatus.puzzle; message = 'You\\'ve already solved today\\'s puzzle! Come back tomorrow.'; } if (completed) { showNotification(message, 'info'); return; } modal.classList.remove('hidden'); document.body.style.overflow = 'hidden'; // Hide daily activities panel const tabContentArea = document.getElementById('tabContentArea'); if (tabContentArea) { tabContentArea.classList.add('hidden'); } }); } if (closeBtn && modal) { // Remove existing listeners by cloning const newCloseBtn = closeBtn.cloneNode(true); closeBtn.parentNode.replaceChild(newCloseBtn, closeBtn); newCloseBtn.addEventListener('click', (e) => { e.preventDefault(); modal.classList.add('hidden'); document.body.style.overflow = ''; }); } }); console.log('✅ Fixed activity modals'); } // SCROLL TO TOP BUTTON FIX function fixScrollToTopButton() { let scrollBtn = document.getElementById('scrollToTopBtn'); // If button doesn't exist, create it if (!scrollBtn) { scrollBtn = document.createElement('button'); scrollBtn.id = 'scrollToTopBtn'; scrollBtn.className = 'fixed bottom-8 right-8 w-12 h-12 bg-[var(--primary-color)] hover:bg-[var(--primary-button-hover-bg-color)] text-white rounded-full shadow-lg hover:shadow-xl transition-all duration-300 z-[50] opacity-0 translate-y-2 pointer-events-none'; scrollBtn.innerHTML = ''; scrollBtn.setAttribute('aria-label', 'Scroll to top'); document.body.appendChild(scrollBtn); console.log('📤 Created scroll to top button'); } // Remove existing event listeners by cloning const newScrollBtn = scrollBtn.cloneNode(true); scrollBtn.parentNode.replaceChild(newScrollBtn, scrollBtn); scrollBtn = newScrollBtn; // Add click functionality scrollBtn.addEventListener('click', (e) => { e.preventDefault(); window.scrollTo({ top: 0, behavior: 'smooth' }); }); // Show/hide on scroll const handleScroll = () => { if (window.scrollY > 300) { scrollBtn.classList.remove('opacity-0', 'translate-y-2', 'pointer-events-none'); scrollBtn.classList.add('opacity-100', 'translate-y-0', 'pointer-events-auto'); } else { scrollBtn.classList.add('opacity-0', 'translate-y-2', 'pointer-events-none'); scrollBtn.classList.remove('opacity-100', 'translate-y-0', 'pointer-events-auto'); } }; window.removeEventListener('scroll', handleScroll); window.addEventListener('scroll', handleScroll); handleScroll(); // Initial check console.log('✅ Fixed scroll to top button'); } function updatePointsDisplay() { const pointsElements = document.querySelectorAll('#userPoints, .user-points'); pointsElements.forEach(element => { if (element) { element.textContent = `${userPoints} Conch Points`; } }); localStorage.setItem('conchPoints', userPoints.toString()); } function updateActivityStatus() { // Update status indicators const indicators = { triviaStatus: activityStatus.trivia, folkloreStatus: activityStatus.folklore, jokesStatus: activityStatus.jokes, puzzleStatus: activityStatus.puzzle }; Object.entries(indicators).forEach(([id, completed]) => { const elements = document.querySelectorAll(`#${id}`); elements.forEach(element => { if (element) { element.className = completed ? 'w-3 h-3 bg-gray-400 rounded-full' : 'w-3 h-3 bg-green-400 rounded-full animate-pulse'; } }); }); // Update progress const completed = Object.values(activityStatus).filter(Boolean).length; const progressElement = document.getElementById('progressBar'); const completedElement = document.getElementById('activitiesCompleted'); if (progressElement) { progressElement.style.width = `${(completed / 4) * 100}%`; } if (completedElement) { completedElement.textContent = `${completed}/4`; } } function showNotification(message, type = 'info') { const bgColor = type === 'success' ? 'bg-green-500' : type === 'error' ? 'bg-red-500' : 'bg-blue-500'; const notification = document.createElement('div'); notification.className = `fixed top-4 right-4 ${bgColor} text-white px-6 py-3 rounded-lg shadow-lg z-[101] transform translate-x-full transition-transform duration-300`; notification.innerHTML = `
${question.explanation}
`; } if (feedbackElement) { feedbackElement.className = `mb-6 p-4 rounded-xl ${isCorrect ? 'bg-green-50 border border-green-200' : 'bg-red-50 border border-red-200'}`; feedbackElement.classList.remove('hidden'); } // Enable next button const nextBtn = document.getElementById('nextTriviaBtn'); if (nextBtn) { nextBtn.disabled = false; } } function nextTriviaQuestion() { if (currentTriviaQuestion >= triviaQuestions.length - 1) { endTrivia(true); } else { loadTriviaQuestion(currentTriviaQuestion + 1); } } function endTrivia(completed) { // Clear timer if (triviaTimer) { clearInterval(triviaTimer); triviaTimer = null; } // Remove cheat protection document.removeEventListener('contextmenu', preventCheat); document.removeEventListener('keydown', preventCheatKeys); window.removeEventListener('blur', handleTabSwitch); window.removeEventListener('focus', handleTabReturn); // Re-enable page document.body.style.overflow = ''; if (completed) { // Award points based on score const pointsEarned = triviaScore * 10; // 10 points per correct answer userPoints += pointsEarned; updatePointsDisplay(); // Mark as completed localStorage.setItem('triviaCompleted', getToday()); activityStatus.trivia = true; updateActivityStatus(); // Show completion message showNotification(`Trivia completed! You scored ${triviaScore}/${triviaQuestions.length} and earned ${pointsEarned} points!`, 'success'); } else { showNotification('Time\'s up! Try again tomorrow.', 'error'); } // Close modal document.getElementById('triviaModal').classList.add('hidden'); // Reset trivia state currentTriviaQuestion = 0; triviaScore = 0; triviaTimeRemaining = 150; } // Initialize everything function init() { updatePointsDisplay(); updateActivityStatus(); // Fix scroll to top button setTimeout(() => { fixScrollToTopButton(); }, 200); // Initialize daily activities system initializeDailyActivities(); // Start periodic popup system startPeriodicPopup(); // Popup Event Listeners const closePopupBtn = document.getElementById('closeActivitiesPopup'); if (closePopupBtn) { const newClosePopupBtn = closePopupBtn.cloneNode(true); closePopupBtn.parentNode.replaceChild(newClosePopupBtn, closePopupBtn); newClosePopupBtn.addEventListener('click', (e) => { e.stopPropagation(); hideActivitiesPopup(); }); } const tryActivitiesBtn = document.getElementById('tryActivitiesBtn'); if (tryActivitiesBtn) { const newTryActivitiesBtn = tryActivitiesBtn.cloneNode(true); tryActivitiesBtn.parentNode.replaceChild(newTryActivitiesBtn, tryActivitiesBtn); newTryActivitiesBtn.addEventListener('click', (e) => { e.stopPropagation(); markActivitiesAsUsed(); // Show daily activities panel document.getElementById('tabContentArea').classList.remove('hidden'); }); } // Close panels when clicking outside document.addEventListener('click', (e) => { const tabArea = document.getElementById('tabContentArea'); const dailyBtn = document.getElementById('dailyActivitiesTab'); const popup = document.getElementById('activitiesPopup'); if (tabArea && !tabArea.contains(e.target) && dailyBtn && !dailyBtn.contains(e.target)) { tabArea.classList.add('hidden'); } // Close popup when clicking outside if (popup && !popup.contains(e.target) && dailyBtn && !dailyBtn.contains(e.target)) { hideActivitiesPopup(); } }); // Setup reward claim buttons setupRewardButtons(); // Setup puzzle functionality setupPuzzleFunctionality(); console.log('🎉 Page initialized with WORKING daily activities and scroll to top!'); } // Setup reward claim buttons function setupRewardButtons() { // Folklore reward const folkloreBtn = document.getElementById('claimFolkloreBtn'); if (folkloreBtn) { const newFolkloreBtn = folkloreBtn.cloneNode(true); folkloreBtn.parentNode.replaceChild(newFolkloreBtn, folkloreBtn); newFolkloreBtn.addEventListener('click', () => { userPoints += 20; updatePointsDisplay(); localStorage.setItem('folkloreCompleted', getToday()); activityStatus.folklore = true; updateActivityStatus(); document.getElementById('folkloreModal').classList.add('hidden'); document.body.style.overflow = ''; showNotification('Folklore read! You earned 20 points!', 'success'); }); } // Jokes reward const jokesBtn = document.getElementById('claimJokesBtn'); if (jokesBtn) { const newJokesBtn = jokesBtn.cloneNode(true); jokesBtn.parentNode.replaceChild(newJokesBtn, jokesBtn); newJokesBtn.addEventListener('click', () => { userPoints += 15; updatePointsDisplay(); localStorage.setItem('jokesCompleted', getToday()); activityStatus.jokes = true; updateActivityStatus(); document.getElementById('jokesModal').classList.add('hidden'); document.body.style.overflow = ''; showNotification('Jokes enjoyed! You earned 15 points!', 'success'); }); } } // Setup puzzle functionality function setupPuzzleFunctionality() { const hintBtn = document.getElementById('hintBtn'); if (hintBtn) { const newHintBtn = hintBtn.cloneNode(true); hintBtn.parentNode.replaceChild(newHintBtn, hintBtn); newHintBtn.addEventListener('click', () => { document.getElementById('hintDisplay').classList.remove('hidden'); newHintBtn.style.display = 'none'; }); } const submitBtn = document.getElementById('submitPuzzleBtn'); if (submitBtn) { const newSubmitBtn = submitBtn.cloneNode(true); submitBtn.parentNode.replaceChild(newSubmitBtn, submitBtn); newSubmitBtn.addEventListener('click', () => { const answer = document.getElementById('puzzleAnswer').value.toUpperCase().trim(); const correct = answer === 'NASSAU'; const resultElement = document.getElementById('puzzleResult'); const resultContent = document.getElementById('puzzleResultContent'); if (correct) { const basePoints = 30; const hintPenalty = document.getElementById('hintDisplay').classList.contains('hidden') ? 0 : 5; const pointsEarned = basePoints - hintPenalty; userPoints += pointsEarned; updatePointsDisplay(); localStorage.setItem('puzzleCompleted', getToday()); activityStatus.puzzle = true; updateActivityStatus(); if (resultContent) { resultContent.innerHTML = `You earned ${pointsEarned} points!
That's not quite right. Think about the capital city!