D
Draco AI
New Chat
Draco Assistant
D
Welcome to Draco AI
I'm Draco, your AI assistant, ready to help with any questions or tasks you have.
function toggleMusic() { const audio = document.getElementById('backgroundMusic'); const playIcon = document.getElementById('playIcon'); const pauseIcon = document.getElementById('pauseIcon'); if (audio.paused) { audio.volume = Math.min(0.9, 1.0); // Ensure volume is within valid range audio.play().catch(e => console.log('Auto-play blocked by browser, user interaction required')); playIcon.style.display = 'none'; pauseIcon.style.display = 'block'; } else { audio.pause(); playIcon.style.display = 'block'; pauseIcon.style.display = 'none'; } } function setVolume(value) { const audio = document.getElementById('backgroundMusic'); // Ensure value is a valid number and clamp between 0 and 100 const numericValue = parseFloat(value); if (isNaN(numericValue)) return; const clampedValue = Math.min(Math.max(numericValue, 0), 100); const volumeValue = clampedValue / 100; // Convert to 0-1 range try { if (audio && volumeValue >= 0 && volumeValue <= 1) { audio.volume = volumeValue; } } catch (e) { console.error('Volume setting error:', e); } } // Initialize music on page load document.addEventListener('DOMContentLoaded', function() { const audio = document.getElementById('backgroundMusic'); // Set volume safely audio.addEventListener('loadstart', function() { try { audio.volume = 0.5; // Set to 50% as safe default } catch (e) { console.error('Volume setting error:', e); } }); // Add error handling audio.addEventListener('error', function(e) { console.error('Audio error:', e); document.querySelector('.music-title').textContent = 'Audio unavailable'; }); audio.addEventListener('loadeddata', function() { console.log('Audio loaded successfully'); // Set volume safely after loading try { audio.volume = 0.5; } catch (e) { console.error('Volume setting error after load:', e); } // Auto-play when loaded audio.play().then(() => { // Update button icons document.getElementById('playIcon').style.display = 'none'; document.getElementById('pauseIcon').style.display = 'block'; }).catch(e => { console.log('Auto-play blocked by browser, user interaction required'); // Add click handler to start music on first user interaction const startMusic = () => { audio.play().then(() => { document.getElementById('playIcon').style.display = 'none'; document.getElementById('pauseIcon').style.display = 'block'; document.removeEventListener('click', startMusic); }); }; document.addEventListener('click', startMusic, { once: true }); }); }); // Try to load the audio audio.load(); });