| /** | |
| * utils/dom.js | |
| * ============ | |
| * Safe DOM querying, HTML string escaping, and UI feedback utilities. | |
| */ | |
| /** | |
| * Escapes unsafe characters for direct innerHTML insertion to prevent XSS. | |
| * @param {string|null|undefined} str - Raw string | |
| * @returns {string} Sanitized string | |
| */ | |
| export function escapeHtml(str) { | |
| if (!str) return ''; | |
| return String(str) | |
| .replace(/&/g, '&') | |
| .replace(/</g, '<') | |
| .replace(/>/g, '>') | |
| .replace(/"/g, '"'); | |
| } | |
| /** | |
| * Safely finds an element by ID, returning null without throwing. | |
| * @param {string} id - Element DOM ID | |
| * @returns {HTMLElement|null} | |
| */ | |
| export function safeGetElement(id) { | |
| return document.getElementById(id); | |
| } | |
| /** | |
| * Displays a transient floating toast notification. | |
| * @param {string} message - Text or emoji message | |
| * @param {number} durationMs - Milliseconds before auto-removal | |
| */ | |
| export function showToast(message, durationMs = 2500) { | |
| const toast = document.createElement('div'); | |
| toast.className = 'permalink-copied'; | |
| toast.textContent = message; | |
| document.body.appendChild(toast); | |
| setTimeout(() => toast.remove(), durationMs); | |
| } | |
Xet Storage Details
- Size:
- 1.17 kB
- Xet hash:
- 5214e573f11ca2223c9d8a0eac890f8d88f71605b1b41ee9d001bcaf013730a1
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.