MCPcopy Index your code
hub / github.com/darkreader/darkreader / linkLoading

Function linkLoading

src/inject/dynamic-theme/style-manager.ts:548–577  ·  view source on GitHub ↗
(link: HTMLLinkElement, loadingId: number)

Source from the content-addressed store, hash-verified

546}
547
548async function linkLoading(link: HTMLLinkElement, loadingId: number) {
549 return new Promise<void>((resolve, reject) => {
550 const cleanUp = () => {
551 link.removeEventListener('load', onLoad);
552 link.removeEventListener('error', onError);
553 rejectorsForLoadingLinks.delete(loadingId);
554 };
555
556 const onLoad = () => {
557 cleanUp();
558 logInfo(`Linkelement ${loadingId} has been loaded`);
559 resolve();
560 };
561
562 const onError = () => {
563 cleanUp();
564 reject(`Linkelement ${loadingId} couldn't be loaded. ${link.href}`);
565 };
566
567 rejectorsForLoadingLinks.set(loadingId, () => {
568 cleanUp();
569 reject();
570 });
571 link.addEventListener('load', onLoad, {passive: true});
572 link.addEventListener('error', onError, {passive: true});
573 if (!link.href) {
574 onError();
575 }
576 });
577}
578
579function getCSSImportURL(importDeclaration: string) {
580 // substring(7) is used to remove `@import` from the string.

Callers 1

getRulesAsyncFunction · 0.85

Calls 3

onErrorFunction · 0.85
cleanUpFunction · 0.70
setMethod · 0.65

Tested by

no test coverage detected