Adrià Vilanova MartÃnez | fe69478 | 2024-11-09 20:40:43 +0100 | [diff] [blame^] | 1 | import CssSelectorNodeWatcherHandler from '../../../../infrastructure/presentation/nodeWatcher/handlers/CssSelectorHandler.adapter'; |
| 2 | import { NodeMutation } from '../../../../presentation/nodeWatcher/NodeWatcherHandler'; |
| 3 | import { OptionsProviderPort } from '../../../../services/options/OptionsProvider'; |
| 4 | import { isDarkThemeOn } from '../../core/logic/darkTheme'; |
| 5 | import { unifiedProfilesFix } from '../../core/logic/unifiedProfiles'; |
| 6 | |
| 7 | /** |
| 8 | * Redirect unified profile iframe to dark version if applicable |
| 9 | */ |
| 10 | export 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 | } |