Classic chat: left-aligned messages with per-user name colors

This commit is contained in:
Clay 2026-12-02 23:04:32 -05:00
parent 23ccd6d03c
commit a525f25437
3 changed files with 23 additions and 7 deletions

View file

@ -4,7 +4,7 @@
<meta charset="utf-8"> <meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="viewport" content="width=device-width, initial-scale=1">
<title>Web OSCAR Chat</title> <title>Web OSCAR Chat</title>
<link rel="stylesheet" href="/style.css?v=12"> <link rel="stylesheet" href="/style.css?v=13">
</head> </head>
<body> <body>
<div id="app"> <div id="app">
@ -87,6 +87,6 @@
</main> </main>
</div> </div>
<script type="module" src="/app.js?v=12"></script> <script type="module" src="/app.js?v=13"></script>
</body> </body>
</html> </html>

View file

@ -20,6 +20,14 @@ export function getMessageStyle() {
const v = localStorage.getItem(MSG_STYLE_KEY); const v = localStorage.getItem(MSG_STYLE_KEY);
return v === 'classic' ? 'classic' : 'bubbles'; 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) { export function setMessageStyle(style) {
const v = style === 'classic' ? 'classic' : 'bubbles'; const v = style === 'classic' ? 'classic' : 'bubbles';
localStorage.setItem(MSG_STYLE_KEY, v); localStorage.setItem(MSG_STYLE_KEY, v);
@ -99,9 +107,17 @@ export function renderMessages(state) {
meta.className = 'meta'; meta.className = 'meta';
const when = msg.time ? new Date(msg.time).toLocaleTimeString() : ''; const when = msg.time ? new Date(msg.time).toLocaleTimeString() : '';
const from = msg.from || 'unknown'; const from = msg.from || 'unknown';
meta.textContent = getMessageStyle() === 'classic' const style = getMessageStyle();
? `[${when || ''}] <${from}>` if (style === 'classic') {
: `${from}${when ? ' · ' + when : ''}`; 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'); const body = document.createElement('div');
body.className = 'body'; body.className = 'body';

View file

@ -192,8 +192,8 @@ main { padding: 1rem; max-width: 1600px; margin: 0 auto; }
font-family: var(--mono); font-family: var(--mono);
font-size: 0.93rem; font-size: 0.93rem;
} }
.messages.style-classic .msg.me .meta, .messages.style-classic .msg.me .meta { color: var(--muted); }
.messages.style-classic .msg.me .body { color: #8ec5ff; } .messages.style-classic .msg.me .body { color: var(--text); }
/* Bubble style */ /* Bubble style */
.messages.style-bubbles .msg { .messages.style-bubbles .msg {