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

Function createDynamicStyleOverrides

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

Source from the content-addressed store, hash-verified

333}
334
335function createDynamicStyleOverrides() {
336 cancelRendering();
337
338 const allStyles = getManageableStyles(document);
339
340 const newManagers = allStyles
341 .filter((style) => !styleManagers.has(style))
342 .map((style) => createManager(style));
343 newManagers
344 .map((manager) => manager.details({secondRound: false}))
345 .filter((detail) => detail && detail.rules.length > 0)
346 .forEach((detail) => {
347 variablesStore.addRulesForMatching(detail!.rules);
348 });
349
350 variablesStore.matchVariablesAndDependents();
351 variablesStore.setOnRootVariableChange(() => {
352 const rootVarsStyle = createOrUpdateStyle('darkreader--root-vars');
353 variablesStore.putRootVars(rootVarsStyle, theme!);
354 });
355 const rootVarsStyle = createOrUpdateStyle('darkreader--root-vars');
356 variablesStore.putRootVars(rootVarsStyle, theme!);
357
358 styleManagers.forEach((manager) => manager.render(theme!, ignoredImageAnalysisSelectors!));
359 if (loadingStyles.size === 0) {
360 cleanFallbackStyle();
361 }
362 newManagers.forEach((manager) => manager.watch());
363
364 const inlineStyleElements = toArray(document.querySelectorAll(INLINE_STYLE_SELECTOR)) as HTMLElement[];
365 iterateShadowHosts(document.documentElement, (host) => {
366 createShadowStaticStyleOverrides(host.shadowRoot!);
367 const elements = host.shadowRoot!.querySelectorAll(INLINE_STYLE_SELECTOR);
368 if (elements.length > 0) {
369 push(inlineStyleElements, elements);
370 }
371 });
372 inlineStyleElements.forEach((el: HTMLElement) => overrideInlineStyle(el, theme!, ignoredInlineSelectors, ignoredImageAnalysisSelectors));
373 handleAdoptedStyleSheets(document);
374 variablesStore.matchVariablesAndDependents();
375
376 tryInvertChromePDF();
377}
378
379let loadingStylesCounter = 0;
380const loadingStyles = new Set<number>();

Callers 1

runDynamicStyleFunction · 0.85

Calls 15

getManageableStylesFunction · 0.90
toArrayFunction · 0.90
iterateShadowHostsFunction · 0.90
pushFunction · 0.90
overrideInlineStyleFunction · 0.90
cancelRenderingFunction · 0.85
createManagerFunction · 0.85
cleanFallbackStyleFunction · 0.85
handleAdoptedStyleSheetsFunction · 0.85
tryInvertChromePDFFunction · 0.85
detailsMethod · 0.80

Tested by

no test coverage detected