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

Function checkImageSelectors

src/inject/dynamic-theme/modify-css.ts:389–413  ·  view source on GitHub ↗
(node: Element | Document | ShadowRoot)

Source from the content-addressed store, hash-verified

387let classObserver: MutationObserver | null = null;
388
389export function checkImageSelectors(node: Element | Document | ShadowRoot): void {
390 for (const [selector, callbacks] of imageSelectorQueue) {
391 if (node.querySelector(selector) || (node instanceof Element && node.matches(selector))) {
392 imageSelectorQueue.delete(selector);
393 callbacks.forEach((cb) => cb());
394 }
395 }
396 if (!classObserver) {
397 classObserver = new MutationObserver((mutations) => {
398 mutations.forEach((mutation) => {
399 imageSelectorNodeQueue.add(mutation.target as Element);
400 if (!imageSelectorQueueFrameId) {
401 imageSelectorQueueFrameId = requestAnimationFrame(() => {
402 imageSelectorNodeQueue.forEach((element) => {
403 checkImageSelectors(element);
404 });
405 imageSelectorNodeQueue.clear();
406 imageSelectorQueueFrameId = null;
407 });
408 }
409 });
410 });
411 classObserver.observe(document.documentElement, {attributes: true, attributeFilter: ['class'], subtree: true});
412 }
413}
414
415export function getBgImageModifier(
416 value: string,

Callers 2

handleMinorTreeMutationsFunction · 0.90
handleHugeTreeMutationsFunction · 0.90

Calls 2

addMethod · 0.80
clearMethod · 0.45

Tested by

no test coverage detected