From a62ebeb861a74c46a9339187e2a9dca686bd829f Mon Sep 17 00:00:00 2001 From: Atlaskor Date: Thu, 13 Nov 2025 15:34:39 +0000 Subject: [PATCH] Add server/static/ui_chat.js --- server/static/ui_chat.js | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 server/static/ui_chat.js diff --git a/server/static/ui_chat.js b/server/static/ui_chat.js new file mode 100644 index 0000000..aa2d9c4 --- /dev/null +++ b/server/static/ui_chat.js @@ -0,0 +1,36 @@ +export function setupChat(root, socket) { + root.innerHTML = ` + + `; + const panel = root.firstElementChild; + const log = panel.querySelector('#chat-log'); + const input = panel.querySelector('#chat-input'); + + function addLine(t) { + const div = document.createElement('div'); + div.textContent = t; + log.appendChild(div); + log.scrollTop = log.scrollHeight; + } + + panel.querySelector('#chat-send').onclick = () => { + const t = input.value.trim(); + if (!t) return; + socket.emit('chat:send', { t }); + input.value = ''; + }; + + input.addEventListener('keydown', e => { + if (e.key === 'Enter') panel.querySelector('#chat-send').click(); + }); + + socket.on('chat:push', m => addLine(m)); + + window.addChatLine = addLine; +}