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

Function createManager

src/inject/dynamic-theme/index.ts:382–423  ·  view source on GitHub ↗
(element: StyleElement)

Source from the content-addressed store, hash-verified

380const loadingStyles = new Set<number>();
381
382function createManager(element: StyleElement) {
383 const loadingStyleId = ++loadingStylesCounter;
384 logInfo(`New manager for element, with loadingStyleID ${loadingStyleId}`, element);
385 function loadingStart() {
386 if (!isDOMReady() || !documentIsVisible()) {
387 loadingStyles.add(loadingStyleId);
388 logInfo(`Current amount of styles loading: ${loadingStyles.size}`);
389
390 const fallbackStyle = createOrUpdateStyle('darkreader--fallback');
391 if (!fallbackStyle.textContent) {
392 fallbackStyle.textContent = getModifiedFallbackStyle(theme!, {strict: false});
393 }
394 }
395 }
396
397 function loadingEnd() {
398 loadingStyles.delete(loadingStyleId);
399 logInfo(`Removed loadingStyle ${loadingStyleId}, now awaiting: ${loadingStyles.size}`);
400 logInfo(`To-do to be loaded`, loadingStyles);
401 if (loadingStyles.size === 0 && isDOMReady()) {
402 cleanFallbackStyle();
403 }
404 }
405
406 function update() {
407 const details = manager.details({secondRound: true});
408 if (!details) {
409 return;
410 }
411 variablesStore.addRulesForMatching(details.rules);
412 variablesStore.matchVariablesAndDependents();
413 manager.render(theme!, ignoredImageAnalysisSelectors);
414 if (__TEST__) {
415 document.dispatchEvent(new CustomEvent('__darkreader__test__dynamicUpdateComplete'));
416 }
417 }
418
419 const manager = manageStyle(element, {update, loadingStart, loadingEnd});
420 styleManagers.set(element, manager);
421
422 return manager;
423}
424
425function removeManager(element: StyleElement) {
426 const manager = styleManagers.get(element);

Callers 2

watchForUpdatesFunction · 0.85

Calls 3

logInfoFunction · 0.90
manageStyleFunction · 0.90
setMethod · 0.65

Tested by

no test coverage detected