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

Function loadText

src/inject/dynamic-theme/style-manager.ts:585–606  ·  view source on GitHub ↗
(url: string)

Source from the content-addressed store, hash-verified

583}
584
585async function loadText(url: string) {
586 if (url.startsWith('data:')) {
587 return await (await fetch(url)).text();
588 }
589
590 const cache = readCSSFetchCache(url);
591 if (cache) {
592 return cache;
593 }
594
595 const parsedURL = new URL(url);
596 let text: string;
597 if (parsedURL.origin === location.origin) {
598 text = await loadAsText(url, 'text/css', location.origin);
599 } else {
600 text = await bgFetch({url, responseType: 'text', mimeType: 'text/css', origin: location.origin});
601 }
602 if (parsedURL.origin === location.origin) {
603 writeCSSFetchCache(url, text);
604 }
605 return text;
606}
607
608async function replaceCSSImports(cssText: string, basePath: string, cache = new Map<string, string>()) {
609 cssText = removeCSSComments(cssText);

Callers 2

getRulesAsyncFunction · 0.85
replaceCSSImportsFunction · 0.85

Calls 4

readCSSFetchCacheFunction · 0.90
loadAsTextFunction · 0.90
bgFetchFunction · 0.90
writeCSSFetchCacheFunction · 0.90

Tested by

no test coverage detected