Move styles into code
This commit is contained in:
19
ts/document.ts
Normal file
19
ts/document.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
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];
|
||||
}
|
||||
Reference in New Issue
Block a user