nikhilkumar76778's picture
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1, user-scalable=no" /> <title>CodeChatter Pro</title> <script src="https://cdn.tailwindcss.com"></script> <script src="https://unpkg.com/feather-icons"></script> <script src="https://cdn.jsdelivr.net/npm/feather-icons/dist/feather.min.js"></script> <style> :root { --primary: #00ffc8; --bg-dark: #0a0a0a; --bg-mid: #111111; --bg-light: #1a1a1a; } body { font-family: 'Inter', sans-serif; background-color: var(--bg-dark); color: white; height: 100vh; overflow: hidden; margin: 0; font-size: 16px; } .tab-active { border-bottom: 2px solid var(--primary); color: var(--primary); } .message-me { background-color: var(--primary); color: black; } .message-other { background-color: var(--bg-light); } .editor-container { height: calc(100vh - 250px); } #output, #aiFeedback { max-height: 150px; overflow-y: auto; font-size: 1rem; padding: 0.5rem; border-radius: 0.375rem; } /* Chat messages bubbles */ #chatMessages div { padding: 0.75rem 1rem; border-radius: 0.75rem; font-size: 1rem; max-width: 90%; word-break: break-word; } /* Header title & icon */ header h1 { font-size: 1.75rem; } /* Tabs */ nav button { outline: none; transition: color 0.3s ease, border-bottom 0.3s ease; } /* Message controls */ .message-controls { display: flex; gap: 0.5rem; } .message-controls input, .message-controls button { font-size: 1rem; border-radius: 0.5rem; } /* Buttons */ button { cursor: pointer; user-select: none; transition: background-color 0.3s ease; } /* Responsive mobile adjustments */ @media (max-width: 768px) { body { font-size: 17px; } header h1 { font-size: 1.5rem; padding: 0 1rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; } nav { border-bottom-width: 1px; } /* Tabs bigger, more padding */ #chatTab, #codeTab { font-size: 1rem; padding: 1rem 0.75rem; } .tab-active { border-bottom-width: 3px; } /* Message controls stacked vertical with bigger targets */ .message-controls { flex-direction: column; gap: 1rem; padding: 0 0.5rem; } .message-controls input, .message-controls button { width: 100%; padding: 0.75rem 1rem; } /* Editor height gets more room on mobile */ .editor-container { height: calc(100vh - 280px); } #output, #aiFeedback { max-height: 200px; font-size: 1rem; border-radius: 0.5rem; } /* Chat message bubbles full width but max 95% */ #chatMessages div { max-width: 95%; font-size: 1.1rem; padding: 0.85rem 1.25rem; } /* Make inputs and buttons bigger and easier to tap */ input[type="text"], button { border-radius: 0.75rem; font-weight: 600; } } </style> </head> <body class="flex flex-col"> <!-- Header --> <header class="bg-black py-3 px-4 border-b border-gray-800 sticky top-0 z-10"> <h1 class="text-xl md:text-2xl font-bold text-center text-green-400"> <i data-feather="terminal" class="inline mr-2"></i>CodeChatter Pro </h1> </header> <!-- Tabs --> <nav class="flex border-b border-gray-800 bg-black sticky top-14 z-10"> <button id="chatTab" class="flex-1 py-3 font-medium tab-active" type="button"> <i data-feather="message-circle" class="mr-2"></i>Chat </button> <button id="codeTab" class="flex-1 py-3 font-medium text-gray-400" type="button"> <i data-feather="code" class="mr-2"></i>Code </button> </nav> <!-- Chat Screen --> <div id="chatScreen" class="flex-1 flex flex-col overflow-hidden"> <div id="chatMessages" class="flex-1 overflow-y-auto p-3 space-y-2"></div> <div class="p-3 bg-gray-900 border-t border-gray-800 message-controls"> <input id="username" type="text" value="Coder" class="hidden" /> <input id="message" type="text" placeholder="Type a message..." class="bg-gray-800 rounded px-3 py-2 focus:outline-none focus:ring-1 focus:ring-green-400" /> <button onclick="sendMessage()" class="bg-green-400 hover:bg-green-300 text-black font-medium rounded flex items-center justify-center"> <i data-feather="send" class="hidden md:block mr-1"></i>Send </button> </div> </div> <!-- Code Screen --> <div id="codeScreen" class="hidden flex-1 flex flex-col overflow-hidden"> <div class="editor-container"> <div id="editor" class="h-full"></div> </div> <div class="flex flex-col md:flex-row border-t border-gray-800 bg-gray-900 p-2 gap-2"> <button onclick="runCode()" class="flex-1 bg-green-400 hover:bg-green-300 text-black font-medium py-2 rounded flex items-center justify-center"> <i data-feather="play" class="mr-2"></i>Run </button> <button onclick="getGeminiFeedback()" class="flex-1 bg-blue-400 hover:bg-blue-300 text-black font-medium py-2 rounded flex items-center justify-center"> <i data-feather="cpu" class="mr-2"></i>AI Review </button> </div> <div id="output" class="bg-black p-3 font-mono text-sm"></div> <div id="aiFeedback" class="bg-gray-900 p-3 text-green-300 italic border-t border-gray-800 text-sm"></div> </div> <!-- Firebase --> <script type="module"> import { initializeApp } from "https://www.gstatic.com/firebasejs/10.12.2/firebase-app.js"; import { getDatabase, ref, push, onValue } from "https://www.gstatic.com/firebasejs/10.12.2/firebase-database.js"; const firebaseConfig = { apiKey: "AIzaSyAxj8tA8f6RkBQf38e7IQc1oGFoGB5RYfg", authDomain: "social-516f8.firebaseapp.com", databaseURL: "https://social-516f8-default-rtdb.firebaseio.com", projectId: "social-516f8", storageBucket: "social-516f8.appspot.com" }; const app = initializeApp(firebaseConfig); const db = getDatabase(app); const chatRef = ref(db, "chat"); window.sendMessage = function() { const user = "Coder"; // Hardcoded username const msg = document.getElementById("message").value.trim(); if (msg) { push(chatRef, { user, msg }); document.getElementById("message").value = ""; } }; onValue(chatRef, (snapshot) => { const chatBox = document.getElementById("chatMessages"); chatBox.innerHTML = ""; snapshot.forEach((child) => { const { user: u, msg } = child.val(); const div = document.createElement("div"); div.className = `rounded-lg px-3 py-1.5 max-w-xs md:max-w-md ${u === "Coder" ? 'message-me ml-auto' : 'message-other'}`; div.innerHTML = `<span class="font-bold">${u}:</span> ${msg}`; chatBox.appendChild(div); }); chatBox.scrollTop = chatBox.scrollHeight; }); </script> <!-- Monaco Editor --> <script src="https://cdn.jsdelivr.net/npm/requirejs@2.3.6/require.min.js"></script> <script> let editor; require.config({ paths: { vs: "https://cdn.jsdelivr.net/npm/monaco-editor@0.34.0/min/vs" }}); require(["vs/editor/editor.main"], function() { editor = monaco.editor.create(document.getElementById("editor"), { value: "# Welcome to CodeChatter Pro!\nprint('Type your Python code here')\n\n# Press Run to execute or AI Review for feedback", language: "python", theme: "vs-dark", automaticLayout: true, minimap: { enabled: false }, fontSize: 16 }); }); </script> <!-- Skulpt Runner --> <script src="https://cdn.jsdelivr.net/npm/skulpt@1.2.0/dist/skulpt.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/skulpt@1.2.0/dist/skulpt-stdlib.js"></script> <script> function outf(text) { document.getElementById("output").innerHTML += text; } function builtinRead(x) { if (!Sk.builtinFiles || !Sk.builtinFiles["files"][x]) throw "File not found: " + x; return Sk.builtinFiles["files"][x]; } function runCode() { const code = editor.getValue(); document.getElementById("output").innerHTML = ""; Sk.configure({ output: outf, read: builtinRead }); Sk.misceval.asyncToPromise(() => Sk.importMainWithBody("<stdin>", false, code, true)) .catch((err) => (document.getElementById("output").innerHTML = err.toString())); } </script> <!-- Gemini Feedback --> <script> async function getGeminiFeedback() { const code = editor.getValue(); const feedbackBox = document.getElementById("aiFeedback"); feedbackBox.innerHTML = '<i data-feather="loader" class="animate-spin mr-2"></i> AI is analyzing your code...'; feather.replace(); try { const response = await fetch( "https://generativelanguage.googleapis.com/v1/models/gemini-2.5-flash:generateContent?key=AIzaSyAiKDzGTukDHG95QcuuYL5n_ReLit-Dgr0", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ contents: [{ parts: [{ text: `Review this Python code in a fun, friendly way (max 3 lines). Point out 1 good thing, 1 improvement, and give a score/100 with an emoji:\n\n${code}` }] }] }) } ); if (!response.ok) { const errText = await response.text(); throw new Error(`API Error ${response.status}: ${errText}`); } const data = await response.json(); const feedback = data?.candidates?.[0]?.content?.parts?.[0]?.text || "⚠️ No feedback received."; feedbackBox.innerHTML = "πŸ’¬ " + feedback; } catch (err) { feedbackBox.innerHTML = "❌ Error: " + err.message; } finally { feather.replace(); } } // Tab switching logic document.getElementById('chatTab').addEventListener('click', () => { document.getElementById('chatScreen').classList.remove('hidden'); document.getElementById('codeScreen').classList.add('hidden'); document.getElementById('chatTab').classList.add('tab-active'); document.getElementById('codeTab').classList.remove('tab-active'); document.getElementById('chatTab').classList.remove('text-gray-400'); document.getElementById('codeTab').classList.add('text-gray-400'); document.getElementById('message').focus(); }); document.getElementById('codeTab').addEventListener('click', () => { document.getElementById('codeScreen').classList.remove('hidden'); document.getElementById('chatScreen').classList.add('hidden'); document.getElementById('codeTab').classList.add('tab-active'); document.getElementById('chatTab').classList.remove('tab-active'); document.getElementById('codeTab').classList.remove('text-gray-400'); document.getElementById('chatTab').classList.add('text-gray-400'); }); // Initialize feather icons document.addEventListener('DOMContentLoaded', () => { feather.replace(); document.getElementById('message').focus(); }); // Auto-submit on ENTER key document.getElementById('message').addEventListener('keypress', (e) => { if (e.key === 'Enter') { sendMessage(); } }); </script> </body> </html> make ui more stable for small screns and large also with smooth animation and effects I want the code in single file
8b59c20 verified