MCPcopy Create free account
hub / github.com/DustinBrett/daedalOS / loadStyle

Function loadStyle

utils/functions.ts:352–375  ·  view source on GitHub ↗
(
  href: string,
  contentWindow = window as Window
)

Source from the content-addressed store, hash-verified

350 });
351
352const loadStyle = (
353 href: string,
354 contentWindow = window as Window
355): Promise<Event> =>
356 new Promise((resolve, reject) => {
357 const loadedStyles = [
358 ...contentWindow.document.querySelectorAll("link[rel=stylesheet]"),
359 ] as HTMLLinkElement[];
360
361 if (loadedStyles.some((loadedStyle) => loadedStyle.href.endsWith(href))) {
362 resolve(new Event("Already loaded."));
363 return;
364 }
365
366 const link = contentWindow.document.createElement("link");
367
368 link.rel = "stylesheet";
369 link.fetchPriority = "high";
370 link.href = href;
371 link.addEventListener("error", reject, ONE_TIME_PASSIVE_EVENT);
372 link.addEventListener("load", resolve, ONE_TIME_PASSIVE_EVENT);
373
374 contentWindow.document.head.append(link);
375 });
376
377export const loadFiles = async (
378 files?: string[],

Callers 1

loadFilesFunction · 0.70

Calls 5

createElementMethod · 0.80
resolveFunction · 0.50
someMethod · 0.45
addEventListenerMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected