blob: 13b6cc919c99611881af1ceb7b8c737c855dc205 [file] [log] [blame]
Adrià Vilanova Martínezfe694782024-11-09 20:40:43 +01001import CssSelectorNodeWatcherHandler from '../../../../infrastructure/presentation/nodeWatcher/handlers/CssSelectorHandler.adapter';
2import { NodeMutation } from '../../../../presentation/nodeWatcher/NodeWatcherHandler';
3import { OptionsProviderPort } from '../../../../services/options/OptionsProvider';
4import { isDarkThemeOn } from '../../core/logic/darkTheme';
5import { unifiedProfilesFix } from '../../core/logic/unifiedProfiles';
6
7/**
8 * Redirect unified profile iframe to dark version if applicable
9 */
10export default class CCDarkThemeUnifiedProfilesIframeHandler extends CssSelectorNodeWatcherHandler {
11 cssSelector = 'iframe';
12
13 constructor(private optionsProvider: OptionsProviderPort) {
14 super();
15 }
16
17 async onMutatedNode(mutation: NodeMutation) {
18 const optionsValues = await this.optionsProvider.getOptionsValues();
19
20 if (
21 isDarkThemeOn(optionsValues) &&
22 unifiedProfilesFix.checkIframe(mutation.node)
23 ) {
24 unifiedProfilesFix.fixIframe(mutation.node);
25 }
26 }
27}