()
| 40 | `; |
| 41 | |
| 42 | export 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 | } |
no test coverage detected