MCPcopy
hub / github.com/darkreader/darkreader / createStaticStyleOverrides

Function createStaticStyleOverrides

src/inject/dynamic-theme/index.ts:201–260  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

199}
200
201function createStaticStyleOverrides() {
202 const fallbackStyle = createOrUpdateStyle('darkreader--fallback', document);
203 fallbackStyle.textContent = getModifiedFallbackStyle(theme!, {strict: true});
204 injectStaticStyle(fallbackStyle, null, 'fallback');
205
206 const userAgentStyle = createOrUpdateStyle('darkreader--user-agent');
207 userAgentStyle.textContent = getModifiedUserAgentStyle(theme!, isIFrame!, theme!.styleSystemControls);
208 injectStaticStyle(userAgentStyle, fallbackStyle, 'user-agent');
209
210 const textStyle = createOrUpdateStyle('darkreader--text');
211 if (theme!.useFont || theme!.textStroke > 0) {
212 textStyle.textContent = createTextStyle(theme!);
213 } else {
214 textStyle.textContent = '';
215 }
216 injectStaticStyle(textStyle, userAgentStyle, 'text');
217
218 const invertStyle = createOrUpdateStyle('darkreader--invert');
219 setInversionStyleValue(invertStyle);
220 injectStaticStyle(invertStyle, textStyle, 'invert');
221
222 const inlineStyle = createOrUpdateStyle('darkreader--inline');
223 inlineStyle.textContent = getInlineOverrideStyle();
224 injectStaticStyle(inlineStyle, invertStyle, 'inline');
225
226 const variableStyle = createOrUpdateStyle('darkreader--variables');
227 const selectionColors = theme?.selectionColor ? getSelectionColor(theme) : null;
228 const neutralBackgroundColor = modifyBackgroundColor(parseColorWithCache('#ffffff')!, theme!);
229 const neutralTextColor = modifyForegroundColor(parseColorWithCache('#000000')!, theme!);
230 variableStyle.textContent = [
231 `:root {`,
232 ` --darkreader-neutral-background: ${neutralBackgroundColor};`,
233 ` --darkreader-neutral-text: ${neutralTextColor};`,
234 ` --darkreader-selection-background: ${selectionColors?.backgroundColorSelection ?? 'initial'};`,
235 ` --darkreader-selection-text: ${selectionColors?.foregroundColorSelection ?? 'initial'};`,
236 `}`,
237 ].join('\n');
238 injectStaticStyle(variableStyle, inlineStyle, 'variables', () => registerVariablesSheet(variableStyle.sheet!));
239 registerVariablesSheet(variableStyle.sheet!);
240
241 const rootVarsStyle = createOrUpdateStyle('darkreader--root-vars');
242 injectStaticStyle(rootVarsStyle, variableStyle, 'root-vars');
243
244 const enableStyleSheetsProxy = !(fixes && fixes.disableStyleSheetsProxy);
245 const enableCustomElementRegistryProxy = !(fixes && fixes.disableCustomElementRegistryProxy);
246 document.dispatchEvent(new CustomEvent('__darkreader__cleanUp'));
247 if (__CHROMIUM_MV3__) {
248 // Notify the dedicated injector of the data.
249 document.dispatchEvent(new CustomEvent('__darkreader__stylesheetProxy__arg', {detail: {enableStyleSheetsProxy, enableCustomElementRegistryProxy}}));
250 } else {
251 const proxyScript = createOrUpdateScript('darkreader--proxy');
252 proxyScript.append(`(${injectProxy})(${enableStyleSheetsProxy}, ${enableCustomElementRegistryProxy})`);
253 document.head.insertBefore(proxyScript, rootVarsStyle.nextSibling);
254 proxyScript.remove();
255 }
256
257 const overrideStyle = createOrUpdateStyle('darkreader--override');
258 overrideStyle.textContent = fixes && fixes.css ? replaceCSSTemplates(fixes.css) : '';

Callers 1

Calls 15

getModifiedFallbackStyleFunction · 0.90
createTextStyleFunction · 0.90
getInlineOverrideStyleFunction · 0.90
getSelectionColorFunction · 0.90
modifyBackgroundColorFunction · 0.90
parseColorWithCacheFunction · 0.90
modifyForegroundColorFunction · 0.90
registerVariablesSheetFunction · 0.90
injectStaticStyleFunction · 0.85
setInversionStyleValueFunction · 0.85
createOrUpdateScriptFunction · 0.85

Tested by

no test coverage detected