From a525f254374cc80fb184500bdd1a2e744ef31a4a Mon Sep 17 00:00:00 2001 From: Clay Date: Wed, 2 Dec 2026 23:04:32 -0500 Subject: [PATCH] Classic chat: left-aligned messages with per-user name colors --- public/index.html | 4 ++-- public/js/ui.js | 22 +++++++++++++++++++--- public/style.css | 4 ++-- 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/public/index.html b/public/index.html index 1307277..5716b07 100644 --- a/public/index.html +++ b/public/index.html @@ -4,7 +4,7 @@ Web OSCAR Chat - +
@@ -87,6 +87,6 @@
- + diff --git a/public/js/ui.js b/public/js/ui.js index 44f1ddb..cec99d4 100644 --- a/public/js/ui.js +++ b/public/js/ui.js @@ -20,6 +20,14 @@ export function getMessageStyle() { const v = localStorage.getItem(MSG_STYLE_KEY); return v === 'classic' ? 'classic' : 'bubbles'; } + +function nameColor(name) { + let hash = 0; + const s = String(name || 'unknown'); + for (let i = 0; i < s.length; i++) hash = ((hash << 5) - hash) + s.charCodeAt(i); + const hue = Math.abs(hash) % 360; + return `hsl(${hue} 70% 70%)`; +} export function setMessageStyle(style) { const v = style === 'classic' ? 'classic' : 'bubbles'; localStorage.setItem(MSG_STYLE_KEY, v); @@ -99,9 +107,17 @@ export function renderMessages(state) { meta.className = 'meta'; const when = msg.time ? new Date(msg.time).toLocaleTimeString() : ''; const from = msg.from || 'unknown'; - meta.textContent = getMessageStyle() === 'classic' - ? `[${when || ''}] <${from}>` - : `${from}${when ? ' · ' + when : ''}`; + const style = getMessageStyle(); + if (style === 'classic') { + const timeSpan = document.createElement('span'); + timeSpan.textContent = `[${when || ''}] `; + const nameSpan = document.createElement('span'); + nameSpan.textContent = `<${from}>`; + nameSpan.style.color = nameColor(from); + meta.append(timeSpan, nameSpan, document.createTextNode(' ')); + } else { + meta.textContent = `${from}${when ? ' · ' + when : ''}`; + } const body = document.createElement('div'); body.className = 'body'; diff --git a/public/style.css b/public/style.css index 02ff189..d28a109 100644 --- a/public/style.css +++ b/public/style.css @@ -192,8 +192,8 @@ main { padding: 1rem; max-width: 1600px; margin: 0 auto; } font-family: var(--mono); font-size: 0.93rem; } -.messages.style-classic .msg.me .meta, -.messages.style-classic .msg.me .body { color: #8ec5ff; } +.messages.style-classic .msg.me .meta { color: var(--muted); } +.messages.style-classic .msg.me .body { color: var(--text); } /* Bubble style */ .messages.style-bubbles .msg {