/** * Utility functions shared across pages. */ /** * Convert seconds to a human-readable duration string. * e.g., 3723 → "1h2m3s" */ function secondsToDuration(input) { input = parseInt(input, 10); if (isNaN(input)) return '0s'; var out = ''; var hours = Math.floor(input / 3600); if (hours > 0) out += hours + 'h'; var minutes = Math.floor((input % 3600) / 60); if (minutes > 0) out += minutes + 'm'; var seconds = input % 60; out += seconds + 's'; return out; } /** * Strip HTML tags from a string. */ function stripHtml(text) { return text ? String(text).replace(/<[^>]+>/gm, '') : ''; } /** * Format a number with locale-aware separators (fallback). */ function formatNumber(n) { n = parseInt(n, 10); if (isNaN(n)) return '0'; return n.toLocaleString ? n.toLocaleString() : String(n); } /** * Check if user is scrolled to the bottom of an element. */ function isScrolledToBottom(el) { return (el.scrollTop + el.clientHeight) >= (el.scrollHeight - 10); }