From 19bb73a8eecaf292087da7b9fb2aa3c01beba495 Mon Sep 17 00:00:00 2001 From: mileswa1q22 Date: Tue, 7 Oct 2025 20:23:03 -0500 Subject: [PATCH] Create ai-chat.js --- ai-chat.js | 91 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 ai-chat.js diff --git a/ai-chat.js b/ai-chat.js new file mode 100644 index 00000000..79c1f318 --- /dev/null +++ b/ai-chat.js @@ -0,0 +1,91 @@ +// --- AI Chat Widget --- +let aiChatWindow = null; +let chatVisible = false; + +// Detect Shift+T +document.addEventListener("keydown", (e) => { + if (e.shiftKey && e.key.toLowerCase() === "t") { + e.preventDefault(); + toggleAIChat(); + } +}); + +async function toggleAIChat() { + if (!chatVisible) { + aiChatWindow = document.createElement("div"); + aiChatWindow.style = ` + position: fixed; + bottom: 20px; + right: 20px; + width: 400px; + height: 500px; + background: #1e1e1e; + color: #f0f0f0; + border: 2px solid #444; + border-radius: 12px; + box-shadow: 0 0 20px rgba(0,0,0,0.5); + z-index: 9999; + display: flex; + flex-direction: column; + overflow: hidden; + font-family: system-ui, sans-serif; + `; + aiChatWindow.innerHTML = ` +
+ 🎮 Fun Miles AI Chat +
+
+
+ + +
+ `; + document.body.appendChild(aiChatWindow); + + const chatLog = aiChatWindow.querySelector("#chatLog"); + const chatInput = aiChatWindow.querySelector("#chatInput"); + const chatSend = aiChatWindow.querySelector("#chatSend"); + + // Intro message + chatLog.innerHTML = ` +
+ AI: 👋 Hi! I'm the Fun Miles AI — here to answer your gaming questions, chat about mods, or just have fun. + Ask me anything! +
+ `; + + // Send message handler + chatSend.onclick = async () => { + const msg = chatInput.value.trim(); + if (!msg) return; + chatLog.innerHTML += `
You: ${msg}
`; + chatInput.value = ""; + + try { + const response = await puter.ai.chat(msg); + chatLog.innerHTML += `
AI: ${response}
`; + chatLog.scrollTop = chatLog.scrollHeight; + } catch (err) { + chatLog.innerHTML += `
Error: ${err.message}
`; + } + }; + + // Enter key sends message + chatInput.addEventListener("keydown", (e) => { + if (e.key === "Enter") chatSend.click(); + }); + + chatVisible = true; + } else { + aiChatWindow.remove(); + chatVisible = false; + } +} + +// --- Dark Mode Logic --- +function applyDarkMode() { + const isDarkMode = localStorage.getItem('darkMode') === 'true'; + document.body.classList.toggle('dark-mode', isDarkMode); +} +window.onload = applyDarkMode;