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

Function cssFilterStyleSheetTemplate

src/generators/css-filter.ts:52–114  ·  view source on GitHub ↗
(filterRoot: string, filterValue: string, reverseFilterValue: string, config: Theme, url: string, isTopFrame: boolean, fixes: string, index: SiteFixesIndex)

Source from the content-addressed store, hash-verified

50}
51
52export function cssFilterStyleSheetTemplate(filterRoot: string, filterValue: string, reverseFilterValue: string, config: Theme, url: string, isTopFrame: boolean, fixes: string, index: SiteFixesIndex): string {
53 const fix = getInversionFixesFor(url, fixes, index);
54
55 const lines: string[] = [];
56
57 lines.push('@media screen {');
58
59 // Add leading rule
60 if (filterValue && isTopFrame) {
61 lines.push('');
62 lines.push('/* Leading rule */');
63 lines.push(createLeadingRule(filterRoot, filterValue));
64 }
65
66 if (config.mode === FilterMode.dark) {
67 // Add reverse rule
68 lines.push('');
69 lines.push('/* Reverse rule */');
70 lines.push(createReverseRule(reverseFilterValue, fix));
71 }
72
73 if (config.useFont || config.textStroke > 0) {
74 // Add text rule
75 lines.push('');
76 lines.push('/* Font */');
77 lines.push(createTextStyle(config));
78 }
79
80 // Full screen fix
81 lines.push('');
82 lines.push('/* Full screen */');
83 [':-webkit-full-screen', ':-moz-full-screen', ':fullscreen'].forEach((fullScreen) => {
84 lines.push(`${fullScreen}, ${fullScreen} * {`);
85 lines.push(' -webkit-filter: none !important;');
86 lines.push(' filter: none !important;');
87 lines.push('}');
88 });
89
90 if (isTopFrame) {
91 const light: [number, number, number] = [255, 255, 255];
92 // If browser affected by Chromium Issue 501582, set dark background on html
93 // Or if browser is Firefox v102+
94 const bgColor = (!hasPatchForChromiumIssue501582() && !hasFirefoxNewRootBehavior()) && config.mode === FilterMode.dark ?
95 applyColorMatrix(light, createFilterMatrix(config)).map(Math.round) :
96 light;
97 lines.push('');
98 lines.push('/* Page background */');
99 lines.push('html {');
100 lines.push(` background: rgb(${bgColor.join(',')}) !important;`);
101 lines.push('}');
102 }
103
104 if (fix.css && fix.css.length > 0 && config.mode === FilterMode.dark) {
105 lines.push('');
106 lines.push('/* Custom rules */');
107 lines.push(fix.css);
108 }
109

Callers 2

Calls 8

createTextStyleFunction · 0.90
applyColorMatrixFunction · 0.90
createFilterMatrixFunction · 0.90
getInversionFixesForFunction · 0.85
createLeadingRuleFunction · 0.85
createReverseRuleFunction · 0.85

Tested by

no test coverage detected