blob: 28b97537ab15eecc3ec6f0ab2db9bedb550713c4 [file] [log] [blame]
Adrià Vilanova Martínez6ecaa0d2024-10-26 17:04:32 +02001import CssSelectorNodeWatcherHandler from '../../../infrastructure/presentation/nodeWatcher/handlers/CssSelectorHandler.adapter';
Adrià Vilanova Martínez43c75202024-10-19 15:55:15 +02002import { NodeMutation } from '../../../presentation/nodeWatcher/NodeWatcherHandler';
Adrià Vilanova Martínez6ecaa0d2024-10-26 17:04:32 +02003import { OptionsProviderPort } from '../../../services/options/OptionsProvider';
Adrià Vilanova Martínez917797e2024-05-25 22:41:25 +02004import { isDarkThemeOn } from '../core/logic/darkTheme';
5import { unifiedProfilesFix } from '../core/logic/unifiedProfiles';
Adrià Vilanova Martínez917797e2024-05-25 22:41:25 +02006
7/**
8 * Redirect unified profile iframe to dark version if applicable
9 */
Adrià Vilanova Martínez6ecaa0d2024-10-26 17:04:32 +020010export default class CCDarkThemeUnifiedProfilesIframeHandler extends CssSelectorNodeWatcherHandler {
Adrià Vilanova Martínez917797e2024-05-25 22:41:25 +020011 cssSelector = 'iframe';
12
Adrià Vilanova Martínez6ecaa0d2024-10-26 17:04:32 +020013 constructor(private optionsProvider: OptionsProviderPort) {
14 super();
15 }
16
Adrià Vilanova Martínez917797e2024-05-25 22:41:25 +020017 async onMutatedNode(mutation: NodeMutation) {
Adrià Vilanova Martínez6ecaa0d2024-10-26 17:04:32 +020018 const optionsValues = await this.optionsProvider.getOptionsValues();
Adrià Vilanova Martínez917797e2024-05-25 22:41:25 +020019
20 if (
21 isDarkThemeOn(optionsValues) &&
22 unifiedProfilesFix.checkIframe(mutation.node)
23 ) {
24 unifiedProfilesFix.fixIframe(mutation.node);
25 }
26 }
27}