()
| 333 | } |
| 334 | |
| 335 | function 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 | |
| 379 | let loadingStylesCounter = 0; |
| 380 | const loadingStyles = new Set<number>(); |
no test coverage detected