feat: restructure client-side code
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
import { badgeColorForYear } from './utils/colors.js';
|
||||
|
||||
let ws;
|
||||
let reconnectAttempts = 0;
|
||||
let reconnectTimer = null;
|
||||
@@ -233,17 +235,7 @@ function shortName(id) {
|
||||
|
||||
function escapeHtml(s) { return String(s).replace(/[&<>"']/g, c => ({'&':'&','<':'<','>':'>','"':'"',"'":'''}[c])); }
|
||||
|
||||
// Stable distinct color per year for the year badge
|
||||
function badgeColorForYear(y) {
|
||||
const val = (y === undefined || y === null) ? '?' : y;
|
||||
if (val === '?' || Number.isNaN(Number(val))) {
|
||||
// Neutral slate for unknown years
|
||||
return 'background-color: hsl(215 16% 34%);';
|
||||
}
|
||||
const n = Number(val);
|
||||
const hue = ((n * 23) % 360 + 360) % 360; // spread hues deterministically
|
||||
return `background-color: hsl(${hue} 70% 42%);`;
|
||||
}
|
||||
// color helper imported from utils/colors.js
|
||||
|
||||
function handleMessage(ev) {
|
||||
const msg = JSON.parse(ev.data);
|
||||
|
||||
Reference in New Issue
Block a user