export function generateId(length) { const arr = new Uint8Array(length / 2); crypto.getRandomValues(arr); return Array.from(arr, dec2hex).join(""); } function dec2hex(dec) { return dec.toString(16).padStart(2, "0"); } export function injectCss(href) { if (document.querySelector(`link[href^="${href}"]`)) { return Promise.resolve(); } return new Promise((resolve) => { const link = document.createElement("link"); link.setAttribute("rel", "stylesheet"); link.setAttribute("type", "text/css"); const timeout = setTimeout(resolve, 1000); link.addEventListener("load", (e) => { clearInterval(timeout); resolve(); }); link.href = href; document.head.appendChild(link); }); }