diff options
| author | Paul Buetow <paul@buetow.org> | 2026-05-07 00:23:45 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-05-07 00:23:45 +0300 |
| commit | a0603095a35473a6479beb612bc2ed7b33298260 (patch) | |
| tree | a4fe50996e1007f74290ff8cb922dc1daa7b77b0 /web/js/utils.js | |
| parent | d87bcee585883f22b2ca0b42db67bf815cc7c1fc (diff) | |
Task 61 extract frontend utilities
Diffstat (limited to 'web/js/utils.js')
| -rw-r--r-- | web/js/utils.js | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/web/js/utils.js b/web/js/utils.js new file mode 100644 index 0000000..2851211 --- /dev/null +++ b/web/js/utils.js @@ -0,0 +1,21 @@ +export function fmtDur(s) { + if (!s || s < 0) return '0:00'; + const h = Math.floor(s / 3600); + const m = Math.floor((s % 3600) / 60); + const sec = Math.floor(s % 60); + const mm = String(m).padStart(2, '0'); + const ss = String(sec).padStart(2, '0'); + return h > 0 ? `${h}:${mm}:${ss}` : `${mm}:${ss}`; +} + +export function escapeHtml(s) { + return (s ?? '').replace(/[&<>"']/g, (c) => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' }[c])); +} + +export function toast(msg, type = 'info') { + const t = document.getElementById('toast'); + if (!t) return; + t.textContent = msg; + t.className = 'toast show ' + type; + setTimeout(() => t.classList.remove('show'), 2800); +} |
