mirror of
https://github.com/yusufipk/YTChatHub.git
synced 2026-09-11 10:56:17 +00:00
Backend: one SSE stream for messages, selection, poll and connection status; reconnect with backoff; no on-disk Innertube session cache; mock only with MOCK_CHAT=1; binds to 127.0.0.1; serves client/out so production runs on one port. Full URLs for links YouTube truncates in chat. Client: components split out, Lucide icons, stream title and status, on-air strip, search, pause, keyboard shortcuts, overlay settings dialog. Overlay themes, position, size, animation and auto-hide via URL, sized for 1080p and scaled with the source. New blueprint theme for the brand background. Removed Tailwind, better-sqlite3, zod, the timezone helpers, Cline memory bank and AGENTS.md. Added ESLint, node:test tests and CI.
28 lines
1.0 KiB
TypeScript
28 lines
1.0 KiB
TypeScript
export function formatTime(iso: string): string {
|
|
const date = new Date(iso);
|
|
if (Number.isNaN(date.getTime())) return '';
|
|
return date.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' });
|
|
}
|
|
|
|
const URL_PATTERN = /(https?:\/\/[^\s<>"']+)/gi;
|
|
|
|
export type TextPart = { type: 'text' | 'link'; content: string };
|
|
|
|
/** Splits plain text into text and link parts. Used only for runs YouTube did not mark as links. */
|
|
export function splitLinks(text: string): TextPart[] {
|
|
const parts: TextPart[] = [];
|
|
let last = 0;
|
|
for (const match of text.matchAll(URL_PATTERN)) {
|
|
const index = match.index ?? 0;
|
|
if (index > last) parts.push({ type: 'text', content: text.slice(last, index) });
|
|
parts.push({ type: 'link', content: match[0] });
|
|
last = index + match[0].length;
|
|
}
|
|
if (last < text.length) parts.push({ type: 'text', content: text.slice(last) });
|
|
return parts;
|
|
}
|
|
|
|
export function formatAmount(amount: string, currency: string): string {
|
|
return currency ? `${currency} ${amount}` : amount;
|
|
}
|