sheets.ts
617 B · typescript · 19 lines
1declare const SHEETS: string;23const map = JSON.parse(SHEETS) as Record<string, string[]>;45const worn = () => new Set([...document.querySelectorAll("link[rel=stylesheet]")].map((one) => one.getAttribute("href")));67const pull = (href: string) =>8 new Promise<void>((done) => {9 const link = document.createElement("link");10 link.rel = "stylesheet";11 link.href = href;12 link.onload = link.onerror = () => done();13 document.head.append(link);14 });1516export async function wear(kind: string) {17 const have = worn();18 await Promise.all((map[kind] ?? []).filter((href) => !have.has(href)).map(pull));19}