Files
t/ts/document.ts

20 lines
498 B
TypeScript
Raw Normal View History

2024-12-22 16:52:01 -08:00
export function whenLoaded(callback: () => void) {
if (document.readyState === "loading") {
document.addEventListener("DOMContentLoaded", callback);
} else {
callback();
}
}
export function addStyle(style: string) {
whenLoaded(() => {
addStyleNow(style);
});
}
export function addStyleNow(style: string) {
const sheet = new CSSStyleSheet();
sheet.replaceSync(style);
document.adoptedStyleSheets = [...document.adoptedStyleSheets, sheet];
}