(invertStyle: HTMLStyleElement)
| 120 | }); |
| 121 | |
| 122 | function setInversionStyleValue(invertStyle: HTMLStyleElement) { |
| 123 | if (!theme) { |
| 124 | return; |
| 125 | } |
| 126 | |
| 127 | const rules: string[] = []; |
| 128 | |
| 129 | const appendRule = (selectors: string[], filter: string | null) => { |
| 130 | if (!filter || selectors.length === 0) { |
| 131 | return; |
| 132 | } |
| 133 | rules.push([ |
| 134 | `${selectors.join(', ')} {`, |
| 135 | ` filter: ${filter} !important;`, |
| 136 | '}', |
| 137 | ].join('\n')); |
| 138 | }; |
| 139 | |
| 140 | const appendCounterInversion = (selectors: string[]) => { |
| 141 | if (theme!.mode === 0 || selectors.length === 0) { |
| 142 | return; |
| 143 | } |
| 144 | rules.push([ |
| 145 | `${selectors.join(', ')} {`, |
| 146 | ` color: black !important;`, |
| 147 | '}', |
| 148 | `${selectors.map((s) => `${s} > *`).join(', ')} {`, |
| 149 | ` filter: invert(100%) hue-rotate(180deg) !important;`, |
| 150 | '}', |
| 151 | ].join('\n')); |
| 152 | }; |
| 153 | |
| 154 | const appendInversionCancellation = (selectors: string[]) => { |
| 155 | if (theme!.mode === 0 || selectors.length === 0) { |
| 156 | return; |
| 157 | } |
| 158 | rules.push([ |
| 159 | `${selectors.join(', ')} {`, |
| 160 | ` filter: none !important;`, |
| 161 | ` color: var(--darkreader-neutral-text) !important;`, |
| 162 | '}', |
| 163 | `${selectors.map((s) => `${s} > *`).join(', ')} {`, |
| 164 | ` filter: none !important;`, |
| 165 | '}', |
| 166 | ].join('\n')); |
| 167 | }; |
| 168 | |
| 169 | if ((fixes && Array.isArray(fixes.invert) && fixes.invert.length > 0) || filterSelectors.invert.size > 0) { |
| 170 | const extraInversionSelectors = [...filterSelectors.invert] |
| 171 | const invertSelectors = [...(fixes?.invert ?? []), ...extraInversionSelectors]; |
| 172 | const invertFilter = getCSSFilterValue({ |
| 173 | ...theme, |
| 174 | contrast: theme.mode === 0 ? theme.contrast : clamp(theme.contrast - 10, 0, 100), |
| 175 | }); |
| 176 | appendRule(invertSelectors, invertFilter); |
| 177 | appendCounterInversion(extraInversionSelectors); |
| 178 | if (filterSelectors.none.size > 0) { |
| 179 | const noneSelectors = [...filterSelectors.none]; |
no test coverage detected