// --- 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 = `
🎮 AI Chat to help with games
`;
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 Moon Gaming 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;