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

Function collectCSS

src/inject/dynamic-theme/css-collection.ts:42–77  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

40`;
41
42export async function collectCSS(): Promise<string> {
43 const css = [banner];
44
45 function addStaticCSS(selector: string, comment: string) {
46 const staticStyle = document.querySelector(selector);
47 if (staticStyle && staticStyle.textContent) {
48 css.push(`/* ${comment} */`);
49 css.push(staticStyle.textContent);
50 css.push('');
51 }
52 }
53
54 addStaticCSS('.darkreader--fallback', 'Fallback Style');
55 addStaticCSS('.darkreader--user-agent', 'User-Agent Style');
56 addStaticCSS('.darkreader--text', 'Text Style');
57 addStaticCSS('.darkreader--invert', 'Invert Style');
58 addStaticCSS('.darkreader--variables', 'Variables Style');
59
60 const modifiedCSS: string[] = [];
61 (document.querySelectorAll('.darkreader--sync') as NodeListOf<HTMLStyleElement>).forEach((element) => {
62 forEach(element.sheet!.cssRules, (rule) => {
63 rule && rule.cssText && modifiedCSS.push(rule.cssText);
64 });
65 });
66
67 if (modifiedCSS.length) {
68 const formattedCSS = formatCSS(modifiedCSS.join('\n'));
69 css.push('/* Modified CSS */');
70 css.push(await replaceBlobs(formattedCSS));
71 css.push('');
72 }
73
74 addStaticCSS('.darkreader--override', 'Override Style');
75
76 return css.join('\n');
77}

Callers 2

onMessageFunction · 0.90
exportGeneratedCSSFunction · 0.90

Calls 4

forEachFunction · 0.90
formatCSSFunction · 0.90
addStaticCSSFunction · 0.85
replaceBlobsFunction · 0.85

Tested by

no test coverage detected