Mercurial
view mrjunejune/src/talk/index.html @ 189:14cc84ba35a0
[BenchMark] Updated results
| author | MrJuneJune <me@mrjunejune.com> |
|---|---|
| date | Sat, 24 Jan 2026 06:37:43 -0800 |
| parents | c1eab8c0b0f9 |
| children |
line wrap: on
line source
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Talk!</title> {{/parts/base_head.html}} <style> body { font-family: sans-serif; padding: 20px; } #messages { height: 200px; border: 1px solid #ccc; overflow-y: scroll; margin-bottom: 10px; padding: 10px; } #chat { display: flex; gap: 10px; } input { flex-grow: 1; } </style> </head> <body> {{/parts/header.html}} <main> <h1>Talk with strangers xDDD</h1> <div id="messages"></div> <div id="chat"> <input type="text" id="messageInput" placeholder="Type a message..."> <button id="sendBtn">Send</button> </div> </main> {{/parts/footer.html}} <script> const host = window.location.hostname; const port = '6969'; const url = host === "mrjunejune.com" ? `wss://${host}/echo` : `ws://${host}:${port}/echo`; const ws = new WebSocket(url); const messagesDiv = document.getElementById('messages'); ws.onopen = () => { console.log('Connected!'); appendMessage('System: Connected to server'); }; ws.onmessage = (event) => { console.log('Received:', event.data); appendMessage('Server: ' + event.data); }; // Function to send message sendBtn.onclick = () => { const message = messageInput.value; if (message) { ws.send(message); appendMessage('You: ' + message); messageInput.value = ''; // Clear input } }; // Helper to show messages on screen function appendMessage(text) { const msg = document.createElement('p'); msg.textContent = text; messagesDiv.appendChild(msg); messagesDiv.scrollTop = messagesDiv.scrollHeight; } messageInput.addEventListener('keydown', (event) => { if (event.key === 'Enter' && !event.shiftKey) { event.preventDefault(); sendBtn.click(); } }); </script> </body> </html>