import { ipcRenderer } from 'electron' ; import { DOMMonitor , IBackgroundCallback , IMessageFromBackground } from '@cliqz/adblocker-content' ; function getCosmeticsFilters ( data ) { setTimeout ( ( ) => { ipcRenderer . send ( 'get-cosmetic-filters' , window . location . href , data ) ; } , 1 ) ; } if ( window === window . top && window . location . href . startsWith ( 'devtools://' ) === false ) { ( ( ) => { const enableMutationObserver = ipcRenderer . sendSync ( 'is-mutation-observer-enabled' ) ; let ACTIVE = true ; let DOM_MONITOR = null ; const unload = ( ) => { if ( DOM_MONITOR !== null ) { DOM_MONITOR . stop ( ) ; DOM_MONITOR = null ; } } ; ipcRenderer . on ( 'get-cosmetic-filters-response' , ( _ , { active } ) => { if ( active === false ) { ACTIVE = false ; unload ( ) ; return ; } ACTIVE = true ; } ) ; getCosmeticsFilters ( { lifecycle : 'start' , ids : [ ] , classes : [ ] , hrefs : [ ] } ) ; window . addEventListener ( 'DOMContentLoaded' , ( ) => { DOM_MONITOR = new DOMMonitor ( ( update ) => { if ( update . type === 'features' ) { getCosmeticsFilters ( { ... update , lifecycle : 'dom-update' , } ) ; } } ) ; DOM_MONITOR . queryAll ( window ) ; if ( ACTIVE && enableMutationObserver ) { DOM_MONITOR . start ( window ) ; } } , { once : true , passive : true } ) ; window . addEventListener ( 'unload' , unload , { once : true , passive : true } ) ; } ) ( ) ; } export type { IBackgroundCallback , IMessageFromBackground } from '@cliqz/adblocker-content' ;