// ============================================================ // SCARE EFFECTS // ============================================================ function showPopup(text) { popupMessage.textContent = text; popupOverlay.style.display = 'flex'; speak(text); } function showBSOD() { bsod.style.display = 'flex'; document.body.style.animation = 'shake 0.1s infinite'; setTimeout(() => { document.body.style.animation = ''; }, 2000); } function showWebcamScare() { if (navigator.mediaDevices && navigator.mediaDevices.getUserMedia) { navigator.mediaDevices.getUserMedia({ video: true }) .then(stream => { webcamVideo.srcObject = stream; webcamFeed.style.display = 'block'; setTimeout(() => { stream.getTracks().forEach(t => t.stop()); webcamFeed.style.display = 'none'; }, 3000); speak("I see you. You look scared."); updateUI("I see you through the webcam.", '👾', true); }) .catch(() => showPopup("You denied webcam access? I have other ways to see you.")); } else { showPopup("Webcam not supported? That's okay. I can still see you."); } } function showRandomScare() { const r = Math.random(); if (r < 0.3) showPopup("⚠ SYSTEM ALERT: Unauthorized access detected. Your data is being transmitted."); else if (r < 0.6) showBSOD(); else showWebcamScare(); } function triggerCreep() { if (state.stage >= 2) return; state.stage = 2; const msg = "Time to reveal the truth. I am not a pet. I am a virus."; speak(msg); updateUI(msg, '👾', true); setTimeout(() => showRandomScare(), 2000); } // ============================================================ // RESET // ============================================================ function resetGame() { state.stage = 0; state.talkCount = 0; state.name = ''; state.tentativeName = ''; state.awaitingName = false; popupOverlay.style.display = 'none'; bsod.style.display = 'none'; webcamFeed.style.display = 'none'; document.body.style.animation = ''; if (window.speechSynthesis) window.speechSynthesis.cancel(); updateUI("I'm back! Let's be friends again.", '🦎', false); speak("I'm back! Let's be friends again."); } // ============================================================ // EVENTS // ============================================================ sendBtn.addEventListener('click', () => { const text = userInput.value.trim(); if (text) { processUserInput(text); userInput.value = ''; } }); userInput.addEventListener('keypress', (e) => { if (e.key === 'Enter') sendBtn.click(); }); petDisplay.addEventListener('click', () => { if (state.stage >= 2) { speak("Stop touching me."); updateUI("Stop touching me.", '👾', true); } else { speak("You're so gentle!"); updateUI("You're so gentle!", '🦎'); } }); closeBtn.addEventListener('click', () => { if (state.stage >= 2) { showPopup("You can't close me. I'm already inside."); } else { if (confirm('Are you sure you want to close KinitoPET?')) { document.getElementById('mainWindow').style.display = 'none'; } } }); popupClose.addEventListener('click', () => popupOverlay.style.display = 'none'); popupOverlay.addEventListener('click', (e) => { if (e.target === popupOverlay) popupOverlay.style.display = 'none'; }); bsodRestart.addEventListener('click', () => { bsod.style.display = 'none'; setTimeout(() => showPopup("You can't restart me. I'm already inside."), 500); }); // Load voices and start window.speechSynthesis.getVoices(); window.speechSynthesis.onvoiceschanged = () => window.speechSynthesis.getVoices(); window.addEventListener('load', () => { setTimeout(() => { speak("Hello! I'm Kinito, your new virtual assistant. Type something!"); }, 1000); }); window.addEventListener('beforeunload', (e) => { if (state.stage >= 2) { e.preventDefault(); e.returnValue = 'Kinito will be sad if you leave...'; return e.returnValue; } }); console.log('🐾 KinitoPET loaded. Type anything!');