๐ฑ Magic 8 Ball
Ask the mystical Magic 8 Ball any yes/no question and receive ancient wisdom! The digital version of the classic fortune-telling toy with magical effects and answer history.
๐ค What Is a Magic 8 Ball?
Think of a crystal ball for yes/no questions - that's a Magic 8 Ball! It's the mystical oracle that's helped people make decisions since 1950.
Magic 8 Ball provides mystical guidance and answers to life's burning yes/no questions with ancient wisdom.
๐ค
Decision Making
Get guidance when you can't decide between options
๐
Party Games
Fun entertainment for gatherings and celebrations
๐ญ
Future Insights
Mystical glimpses into what tomorrow might bring
๐ฏ
Quick Choices
Instant answers when time is running short
๐ฎ
Mystical Guidance
Spiritual consultation for life's mysteries
โจ
Daily Oracle
Morning wisdom to guide your entire day
๐ฏ Choose Your Learning Mode
Choose Your Mystical Experience Level
๐ข
Beginner
Simple mystical guidance!
๐ก
Mystic
Enhanced magical features
๐ด
Oracle
Full mystical powers!
Click to ask your question
โ๏ธ Mystical Options
๐ญ Try These Mystical Questions
โ๏ธ
Will I have a wonderful day today?
๐ฒ
Should I take that risk I've been considering?
โจ
Will my dreams come true soon?
๐ญ
Is someone thinking about me right now?
๐ฏ
Should I trust my instincts on this?
๐
Will good fortune find me this week?
${item.question}
${item.answer}
${item.timestamp}
`;
historyList.appendChild(historyItem);
});
}
// Use sample question
function useSampleQuestion(question) {
document.getElementById('questionInput').value = question;
// Smooth scroll to 8 ball
document.getElementById('magic8Ball').scrollIntoView({
behavior: 'smooth',
block: 'center'
});
// Highlight the 8 ball
const ball = document.getElementById('magic8Ball');
ball.style.animation = 'pulse 0.8s ease-in-out';
setTimeout(() => ball.style.animation = '', 800);
showNotification('Question loaded! Click the 8 ball for your answer.', 'success');
}
// Set difficulty level
function setDifficulty(level) {
OnboardingManager.currentDifficulty = level;
OnboardingManager.updateDifficultyUI();
// Show achievement for trying different difficulties
if (level === 'expert') {
OnboardingManager.unlockAchievement('oracle_level', '๐ด Oracle Master', 'Unlocked all mystical powers!');
}
trackEvent('difficulty_changed', { level });
}
// Toggle custom answers UI
function toggleCustomAnswers() {
const customAnswers = document.getElementById('customAnswers').value === 'true';
const customInput = document.getElementById('customAnswerInput');
if (customInput) {
if (customAnswers) {
customInput.classList.remove('hidden');
} else {
customInput.classList.add('hidden');
}
}
}
// Export history
function exportHistory() {
if (Magic8BallState.history.length === 0) {
showNotification('No mystical consultations to export', 'warning');
return;
}
const csvContent = [
'Timestamp,Question,Answer,Mood',
...Magic8BallState.history.map(item =>
`"${item.timestamp}","${item.question.replace(/"/g, '""')}","${item.answer.replace(/"/g, '""')}","${item.mood || 'balanced'}"`
)
].join('\n');
const blob = new Blob([csvContent], { type: 'text/csv' });
const url = window.URL.createObjectURL(blob);
const link = document.createElement('a');
link.href = url;
link.download = `magic-8-ball-consultations-${new Date().toISOString().split('T')[0]}.csv`;
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
window.URL.revokeObjectURL(url);
showNotification('๐ Mystical consultations exported successfully!', 'success');
OnboardingManager.unlockAchievement('data_mystic', '๐ Data Mystic', 'Exported mystical consultation history!');
}
// Clear history
function clearHistory() {
if (confirm('Are you sure you want to clear all mystical consultation history?')) {
Magic8BallState.history = [];
localStorage.removeItem('magic_8_ball_history');
updateHistoryDisplay();
showNotification('Mystical history cleared successfully', 'success');
}
}
// Play magic sound
function playMagicSound() {
if (typeof AudioContext !== 'undefined' || typeof webkitAudioContext !== 'undefined') {
const audioContext = new (AudioContext || webkitAudioContext)();
// Create mystical chord progression
const frequencies = [261.63, 329.63, 392.00]; // C, E, G
const duration = 1.5;
frequencies.forEach((freq, index) => {
const oscillator = audioContext.createOscillator();
const gainNode = audioContext.createGain();
oscillator.connect(gainNode);
gainNode.connect(audioContext.destination);
oscillator.frequency.value = freq;
oscillator.type = 'sine';
gainNode.gain.value = 0.1 / frequencies.length;
// Add tremolo effect
gainNode.gain.setValueAtTime(0.05, audioContext.currentTime);
gainNode.gain.setValueAtTime(0.15, audioContext.currentTime + 0.5);
gainNode.gain.setValueAtTime(0.05, audioContext.currentTime + duration);
oscillator.start();
oscillator.stop(audioContext.currentTime + duration);
});
}
}
// ========== UTILITY FUNCTIONS ==========
// Show notification toast
function showNotification(message, type = 'success') {
const toast = document.createElement('div');
toast.className = `toast ${type}`;
toast.textContent = message;
document.body.appendChild(toast);
setTimeout(() => {
toast.remove();
}, 3000);
}
// Show OTA section (dynamic)
function showOTA() {
const otaContainer = document.getElementById('otaContainer');
if (otaContainer && (otaContainer.style.display === 'none' || !otaContainer.style.display)) {
otaContainer.style.display = 'block';
// Attention-grabbing pulse effect
setTimeout(() => {
const otaHeader = document.querySelector('.ota-header h3');
if (otaHeader) {
otaHeader.style.animation = 'pulse 1s ease-in-out';
}
}, 100);
}
}
// Analytics tracking
function trackEvent(eventName, data = {}) {
if (typeof gtag !== 'undefined') {
gtag('event', eventName, {
'event_category': TOOL_CONFIG.category,
'event_label': TOOL_CONFIG.name,
...data
});
}
}
// ========== AI ASSISTANT FUNCTIONS ==========
// AI ๋ชจ๋ฌ ์ด๊ธฐ
function openAIModal() {
const modal = document.getElementById('aiModal');
if(modal) modal.classList.add('show');
// ํ์ฌ ์ํ์ ๋ฐ๋ผ ์ ์ ํ ํ๋ฉด ํ์
if (aiModalState.apiKey && aiModalState.currentView === 'gemini') {
showGeminiChat();
} else {
showAISelector();
}
updateAPIKeyStatus();
}
// AI ๋ชจ๋ฌ ๋ซ๊ธฐ
function closeAIModal() {
const modal = document.getElementById('aiModal');
if(modal) modal.classList.remove('show');
// 300ms ํ ์ํ ๋ฆฌ์
(์ ๋๋ฉ์ด์
์๋ฃ ํ)
setTimeout(() => {
aiModalState.currentView = 'selector';
showAISelector();
}, 300);
}
// AI ์ ํ ํ๋ฉด ํ์
function showAISelector() {
document.getElementById('aiModalTitle').textContent = 'Choose Your AI Assistant';
document.getElementById('aiSelector').style.display = 'flex';
document.getElementById('geminiChat').style.display = 'none';
document.getElementById('apiKeySetup').style.display = 'none';
aiModalState.currentView = 'selector';
}
// Gemini ์ฑํ
ํ๋ฉด ํ์
function showGeminiChat() {
document.getElementById('aiModalTitle').innerHTML = 'โจ Gemini AI Assistant';
document.getElementById('aiSelector').style.display = 'none';
document.getElementById('geminiChat').style.display = 'flex';
document.getElementById('apiKeySetup').style.display = 'none';
aiModalState.currentView = 'gemini';
// ์ด๊ธฐ ๋ฉ์์ง๊ฐ ์์ผ๋ฉด ์ถ๊ฐ
const chatMessages = document.getElementById('chatMessages');
if (!chatMessages.innerHTML.trim()) {
addMessage('assistant', `Hello! I can help you with:
โข How to ask better Magic 8 Ball questions
โข Understanding mystical answer meanings
โข Using different difficulty levels
โข Interpreting fortune-telling wisdom
What mystical guidance do you seek?`);
}
}
// API ํค ์ค์ ํ๋ฉด ํ์
function showAPIKeySetup() {
document.getElementById('aiModalTitle').textContent = 'Setup Gemini API';
document.getElementById('aiSelector').style.display = 'none';
document.getElementById('geminiChat').style.display = 'none';
document.getElementById('apiKeySetup').style.display = 'block';
aiModalState.currentView = 'setup';
}
// AI ์ ํ ์ฒ๋ฆฌ
function selectAI(aiType) {
switch(aiType) {
case 'chatgpt':
const toolContext = `I need help with Magic 8 Ball fortune telling. This is an entertainment tool on WIA Pin Code platform for mystical guidance and decision making.`;
const chatUrl = `https://chat.openai.com/?q=${encodeURIComponent(toolContext)}`;
window.open(chatUrl, '_blank');
closeAIModal();
trackEvent('ai_selection', { ai_type: 'chatgpt' });
break;
case 'claude':
const claudeContext = `I need help with Magic 8 Ball fortune telling. This is an entertainment tool on WIA Pin Code platform for mystical guidance and decision making.`;
const claudeUrl = `https://claude.ai/chat?q=${encodeURIComponent(claudeContext)}`;
window.open(claudeUrl, '_blank');
closeAIModal();
trackEvent('ai_selection', { ai_type: 'claude' });
break;
case 'gemini':
if (!aiModalState.apiKey) {
showAPIKeySetup();
} else {
showGeminiChat();
}
trackEvent('ai_selection', { ai_type: 'gemini' });
break;
}
}
// API ํค ์ ์ฅ
function saveGeminiApiKey() {
const apiKey = document.getElementById('geminiApiKeyInput').value.trim();
if (apiKey) {
localStorage.setItem('geminiApiKey', apiKey);
aiModalState.apiKey = apiKey;
showGeminiChat();
updateAPIKeyStatus();
} else {
alert('Please enter a valid API key');
}
}
// API ํค ์ํ ์
๋ฐ์ดํธ
function updateAPIKeyStatus() {
const statusEl = document.getElementById('apiKeyStatus');
if (aiModalState.apiKey) {
statusEl.innerHTML = 'Change API Key';
} else {
statusEl.textContent = 'No API key set';
}
}
// ์ฑํ
๋ฉ์์ง ์ถ๊ฐ
function addMessage(type, content) {
const chatMessages = document.getElementById('chatMessages');
const messageDiv = document.createElement('div');
messageDiv.className = `message ${type}`;
if (type === 'user') {
messageDiv.innerHTML = `You: ${content}`;
} else {
messageDiv.innerHTML = `โจ Gemini:${content.replace(/\n/g, '
')}`; } chatMessages.appendChild(messageDiv); chatMessages.scrollTop = chatMessages.scrollHeight; } // Gemini์ ๋ฉ์์ง ์ ์ก async function sendToGemini() { const input = document.getElementById('geminiInput'); const message = input.value.trim(); if (!message) return; // ์ฌ์ฉ์ ๋ฉ์์ง ์ถ๊ฐ addMessage('user', message); input.value = ''; // ๋ก๋ฉ ํ์ const loadingMsg = document.createElement('div'); loadingMsg.className = 'message assistant'; loadingMsg.innerHTML = 'โจ Gemini:
Consulting the mystical database...'; loadingMsg.id = 'loading-message'; document.getElementById('chatMessages').appendChild(loadingMsg); try { const response = await fetch(`https://generativelanguage.googleapis.com/v1beta/models/gemini-pro:generateContent?key=${aiModalState.apiKey}`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ contents: [{ parts: [{ text: `Context: User is using Magic 8 Ball tool on WIA Pin Code platform. This tool provides mystical guidance for yes/no questions. Features include: classic answers, mood-based answers, custom answers, mystical effects. Use cases: decision making, fortune telling, party games, daily guidance. Respond with mystical wisdom and practical advice. User question: ${message}` }] }], generationConfig: { temperature: 0.7, maxOutputTokens: 1000 } }) }); const data = await response.json(); // ๋ก๋ฉ ๋ฉ์์ง ์ ๊ฑฐ document.getElementById('loading-message').remove(); if (data.candidates && data.candidates[0] && data.candidates[0].content) { const reply = data.candidates[0].content.parts[0].text; addMessage('assistant', reply); } else { addMessage('assistant', 'The mystical energies are unclear at this moment. Please try again.'); } } catch (error) { // ๋ก๋ฉ ๋ฉ์์ง ์ ๊ฑฐ document.getElementById('loading-message')?.remove(); if (error.message.includes('API key')) { addMessage('error', 'Invalid API key. Please check your API key and try again.'); showAPIKeySetup(); } else { addMessage('error', 'Failed to connect to the mystical realm. Please check your connection and try again.'); } } } // ========== GLOBAL FUNCTIONS ========== // Start tutorial (global for onboarding button) function startTutorial() { OnboardingManager.startTutorial(); } // Skip onboarding (global for onboarding button) function skipOnboarding() { OnboardingManager.skipOnboarding(); } // ========== EVENT LISTENERS ========== // Enter key support and initialization document.addEventListener('DOMContentLoaded', function() { // Initialize onboarding OnboardingManager.init(); updateHistoryDisplay(); const questionInput = document.getElementById('questionInput'); if (questionInput) { questionInput.addEventListener('keypress', function(e) { if (e.key === 'Enter') { askQuestion(); } }); questionInput.addEventListener('input', function() { // Reset border color when typing questionInput.style.borderColor = ''; }); } // AI ๋ฒํผ ์ด๋ฒคํธ document.getElementById('aiBtn').addEventListener('click', openAIModal); // ๋ชจ๋ฌ ์ธ๋ถ ํด๋ฆญ์ ๋ซ๊ธฐ document.getElementById('aiModal').addEventListener('click', function(e) { if (e.target === this) { closeAIModal(); } }); // ์ํฐ ํค ์ง์ ๋ฐ ESC ํค๋ก ๋ชจ๋ฌ ๋ซ๊ธฐ document.addEventListener('keydown', function(e) { if (e.key === 'Enter') { const geminiInput = document.getElementById('geminiInput'); if (document.activeElement === geminiInput) { sendToGemini(); } } // ESC ํค๋ก ๋ชจ๋ฌ ๋ซ๊ธฐ if (e.key === 'Escape') { closeAIModal(); } }); // ์ด๊ธฐ API ํค ์ํ ์ ๋ฐ์ดํธ updateAPIKeyStatus(); updateCurrentYear(); updateToolCount(); }); // Track WIA Pin Code clicks for analytics document.querySelectorAll('a[href*="wia"]').forEach(link => { link.addEventListener('click', function() { trackEvent('wia_link_click', { link: link.textContent }); }); }); // ========== DYNAMIC TOOL COUNT ========== // Update tool count dynamically async function updateToolCount() { try { const response = await fetch('/api/tool-count.php'); const data = await response.json(); // Update dynamic tools description document.querySelectorAll('.dynamic-tools-count').forEach(el => { el.textContent = `${data.count}+ free online tools in 211 languages. No signup, no fees, just tools that work.`; }); // Update "All X+ Tools" links document.querySelectorAll('.dynamic-count').forEach(el => { const prefix = el.getAttribute('data-text') || ''; const suffix = el.getAttribute('data-suffix') || ''; const icon = el.textContent.split(' ')[0] || ''; el.textContent = `${icon} ${prefix} ${data.count}+ ${suffix}`; }); } catch (error) { // Fallback: use current actual count from server const fallbackCount = 333; document.querySelectorAll('.dynamic-tools-count').forEach(el => { el.textContent = `${fallbackCount}+ free online tools in 211 languages. No signup, no fees, just tools that work.`; }); document.querySelectorAll('.dynamic-count').forEach(el => { const prefix = el.getAttribute('data-text') || ''; const suffix = el.getAttribute('data-suffix') || ''; const icon = el.textContent.split(' ')[0] || ''; el.textContent = `${icon} ${prefix} ${fallbackCount}+ ${suffix}`; }); console.log('Tool count API not available, using current count:', fallbackCount); } } // Update current year dynamically function updateCurrentYear() { const currentYear = new Date().getFullYear(); document.querySelectorAll('.current-year').forEach(el => { el.textContent = currentYear; }); } // ========== ANALYTICS ========== // Google Analytics window.dataLayer = window.dataLayer || []; function gtag(){dataLayer.push(arguments);} gtag('js', new Date()); gtag('config', 'G-XXXXXXXXX'); // Track page view trackEvent('page_view', { tool: TOOL_CONFIG.name, category: TOOL_CONFIG.category });