@duckduckgo/autoconsent 5.0.0 → 5.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1,2032 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});function t(){return crypto&&void 0!==crypto.randomUUID?crypto.randomUUID():Math.random().toString()}class e{constructor(t,e=1e3){this.id=t,this.promise=new Promise(((t,e)=>{this.resolve=t,this.reject=e})),this.timer=window.setTimeout((()=>{this.reject(new Error("timeout"))}),e)}}const n={pending:new Map,sendContentMessage:null};function o(t="autoconsent-css-rules"){const e=`style#${t}`,n=document.querySelector(e);if(n&&n instanceof HTMLStyleElement)return n;{const e=document.head||document.getElementsByTagName("head")[0]||document.documentElement,n=document.createElement("style");return n.id=t,e.appendChild(n),n}}function i(t,e,n="display"){const o="opacity"===n?"opacity: 0":"display: none",i=`${e.join(",")} { ${o} !important; z-index: -1 !important; pointer-events: none !important; } `;return t instanceof HTMLStyleElement&&(t.innerText+=i,e.length>0)}async function s(t,e,n){const o=await t();return!o&&e>0?new Promise((o=>{setTimeout((async()=>{o(s(t,e-1,n))}),n)})):Promise.resolve(o)}function r(t){if(!t)return!1;if(null!==t.offsetParent)return!0;{const e=window.getComputedStyle(t);if("fixed"===e.position&&"none"!==e.display)return!0}return!1}function c(o){return function(o){const i=t();n.sendContentMessage({type:"eval",id:i,code:o});const s=new e(i);return n.pending.set(s.id,s),s.promise}(o).catch((t=>!1))}function a(t,e=!1){const n=f(t);return n.length>0&&(e?n.forEach((t=>t.click())):n[0].click()),n.length>0}function u(t){return f(t).length>0}function l(t,e){const n=f(t),o=new Array(n.length);return n.forEach(((t,e)=>{o[e]=r(t)})),"none"===e?o.every((t=>!t)):0!==o.length&&("any"===e?o.some((t=>t)):o.every((t=>t)))}function p(t,e=1e4){return s((()=>f(t).length>0),Math.ceil(e/200),200)}async function d(t,e=1e4,n=!1){return await p(t,e),a(t,n)}function h(t){return new Promise((e=>{setTimeout((()=>{e(!0)}),t)}))}function m(t,e=document){if(t.startsWith("aria/"))return[];if(t.startsWith("xpath/")){const n=t.slice(6),o=document.evaluate(n,e,null,XPathResult.ANY_TYPE,null);let i=null;const s=[];for(;i=o.iterateNext();)s.push(i);return s}return t.startsWith("text/")||t.startsWith("pierce/")?[]:e.shadowRoot?Array.from(e.shadowRoot.querySelectorAll(t)):Array.from(e.querySelectorAll(t))}function f(t){return"string"==typeof t?m(t):function(t){let e,n=document;for(const o of t){if(e=m(o,n),0===e.length)return[];n=e[0]}return e}(t)}const y={main:!0,frame:!1,urlPattern:""};class w{constructor(t){this.runContext=y,this.name=t}get hasSelfTest(){throw new Error("Not Implemented")}get isIntermediate(){throw new Error("Not Implemented")}get isCosmetic(){throw new Error("Not Implemented")}checkRunContext(){const t={...y,...this.runContext},e=window.top===window;return!(e&&!t.main)&&(!(!e&&!t.frame)&&!(t.urlPattern&&!window.location.href.match(t.urlPattern)))}detectCmp(){throw new Error("Not Implemented")}async detectPopup(){return!1}optOut(){throw new Error("Not Implemented")}optIn(){throw new Error("Not Implemented")}openCmp(){throw new Error("Not Implemented")}async test(){return Promise.resolve(!0)}}async function g(t){const e=[];if(t.exists&&e.push(u(t.exists)),t.visible&&e.push(l(t.visible,t.check)),t.eval){const n=c(t.eval);e.push(n)}var n,r;if(t.waitFor&&e.push(p(t.waitFor,t.timeout)),t.waitForVisible&&e.push(function(t,e=1e4,n="any"){return s((()=>l(t,n)),Math.ceil(e/200),200)}(t.waitForVisible,t.timeout,t.check)),t.click&&e.push(a(t.click,t.all)),t.waitForThenClick&&e.push(d(t.waitForThenClick,t.timeout,t.all)),t.wait&&e.push(h(t.wait)),t.hide&&e.push((n=t.hide,r=t.method,i(o(),n,r))),t.if){if(!t.if.exists&&!t.if.visible)return console.error("invalid conditional rule",t.if),!1;await g(t.if)?e.push(C(t.then)):t.else&&e.push(C(t.else))}if(t.any){for(const e of t.any)if(await g(e))return!0;return!1}if(0===e.length)return!1;return(await Promise.all(e)).reduce(((t,e)=>t&&e),!0)}async function C(t){for(const e of t){if(!await g(e)&&!e.optional)return!1}return!0}class b extends w{constructor(t){super(t.name),this.config=t,this.runContext=t.runContext||y}get hasSelfTest(){return!!this.config.test}get isIntermediate(){return!!this.config.intermediate}get isCosmetic(){return!!this.config.cosmetic}get prehideSelectors(){return this.config.prehideSelectors}async detectCmp(){return!!this.config.detectCmp&&async function(t){const e=t.map((t=>g(t)));return(await Promise.all(e)).every((t=>!!t))}(this.config.detectCmp)}async detectPopup(){return!!this.config.detectPopup&&C(this.config.detectPopup)}async optOut(){return!!this.config.optOut&&C(this.config.optOut)}async optIn(){return!!this.config.optIn&&C(this.config.optIn)}async openCmp(){return!!this.config.openCmp&&C(this.config.openCmp)}async test(){return this.hasSelfTest?C(this.config.test):super.test()}}function k(t){return new b(t)}const v=[new class extends w{constructor(){super("TrustArc-top"),this.prehideSelectors=[".trustarc-banner-container",".truste_popframe,.truste_overlay,.truste_box_overlay,#truste-consent-track"],this.runContext={main:!0,frame:!1},this._shortcutButton=null,this._optInDone=!1}get hasSelfTest(){return!1}get isIntermediate(){return!this._optInDone&&!this._shortcutButton}get isCosmetic(){return!1}async detectCmp(){const t=u("#truste-show-consent,#truste-consent-track");return t&&(this._shortcutButton=document.querySelector("#truste-consent-required")),t}async detectPopup(){return l("#truste-consent-content,#trustarc-banner-overlay,#truste-consent-track","all")}openFrame(){a("#truste-show-consent")}async optOut(){return this._shortcutButton?(this._shortcutButton.click(),!0):(i(o(),[".truste_popframe",".truste_overlay",".truste_box_overlay","#truste-consent-track"]),a("#truste-show-consent"),setTimeout((()=>{o().remove()}),1e4),!0)}async optIn(){return this._optInDone=!0,a("#truste-consent-button")}async openCmp(){return!0}async test(){return await c("window && window.truste && window.truste.eu.bindMap.prefCookie === '0'")}},new class extends w{constructor(){super("TrustArc-frame"),this.runContext={main:!1,frame:!0,urlPattern:"^https://consent-pref\\.trustarc\\.com/\\?"}}get hasSelfTest(){return!1}get isIntermediate(){return!1}get isCosmetic(){return!1}async detectCmp(){return!0}async detectPopup(){return l("#defaultpreferencemanager","any")&&l(".mainContent","any")}async navigateToSettings(){return await s((async()=>u(".shp")||l(".advance","any")||u(".switch span:first-child")),10,500),u(".shp")&&a(".shp"),await p(".prefPanel",5e3),l(".advance","any")&&a(".advance"),await s((()=>l(".switch span:first-child","any")),5,1e3)}async optOut(){return await s((()=>"complete"===document.readyState),20,100),await p(".mainContent[aria-hidden=false]",5e3),!!a(".rejectAll")||(u(".prefPanel")&&await p('.prefPanel[style="visibility: visible;"]',3e3),a("#catDetails0")?(a(".submit"),!0):(a(".required")||(await this.navigateToSettings(),a(".switch span:nth-child(1):not(.active)",!0),a(".submit"),p("#gwt-debug-close_id",3e5).then((()=>{a("#gwt-debug-close_id")}))),!0))}async optIn(){return a(".call")||(await this.navigateToSettings(),a(".switch span:nth-child(2)",!0),a(".submit"),p("#gwt-debug-close_id",3e5).then((()=>{a("#gwt-debug-close_id")}))),!0}},new class extends w{constructor(){super("Cybotcookiebot"),this.prehideSelectors=["#CybotCookiebotDialog,#dtcookie-container,#cookiebanner,#cb-cookieoverlay"]}get hasSelfTest(){return!0}get isIntermediate(){return!1}get isCosmetic(){return!1}async detectCmp(){return u("#CybotCookiebotDialogBodyLevelButtonPreferences")}async detectPopup(){return u("#CybotCookiebotDialog,#dtcookie-container,#cookiebanner,#cb-cookiebanner")}async optOut(){return a(".cookie-alert-extended-detail-link")?(await p(".cookie-alert-configuration",2e3),a(".cookie-alert-configuration-input:checked",!0),a(".cookie-alert-extended-button-secondary"),!0):u("#dtcookie-container")?a(".h-dtcookie-decline"):(a(".cookiebot__button--settings")||a("#CybotCookiebotDialogBodyButtonDecline")||(a(".cookiebanner__link--details"),a('.CybotCookiebotDialogBodyLevelButton:checked:enabled,input[id*="CybotCookiebotDialogBodyLevelButton"]:checked:enabled',!0),a("#CybotCookiebotDialogBodyButtonDecline"),a("input[id^=CybotCookiebotDialogBodyLevelButton]:checked",!0),u("#CybotCookiebotDialogBodyButtonAcceptSelected")?a("#CybotCookiebotDialogBodyButtonAcceptSelected"):a("#CybotCookiebotDialogBodyLevelButtonAccept,#CybotCookiebotDialogBodyButtonAccept,#CybotCookiebotDialogBodyLevelButtonLevelOptinAllowallSelection",!0),await c("window.CookieConsent.hasResponse !== true")&&(await c("window.Cookiebot.dialog.submitConsent()"),await h(500)),u("#cb-confirmedSettings")&&await c("endCookieProcess()")),!0)}async optIn(){return u("#dtcookie-container")?a(".h-dtcookie-accept"):(a(".CybotCookiebotDialogBodyLevelButton:not(:checked):enabled",!0),a("#CybotCookiebotDialogBodyLevelButtonAccept"),a("#CybotCookiebotDialogBodyButtonAccept"),!0)}async test(){return c("window.CookieConsent.declined === true")}},new class extends w{constructor(){super("Sourcepoint-frame"),this.prehideSelectors=["div[id^='sp_message_container_'],.message-overlay","#sp_privacy_manager_container"],this.ccpaNotice=!1,this.ccpaPopup=!1,this.runContext={main:!1,frame:!0}}get hasSelfTest(){return!1}get isIntermediate(){return!1}get isCosmetic(){return!1}async detectCmp(){const t=new URL(location.href);return t.searchParams.has("message_id")&&"ccpa-notice.sp-prod.net"===t.hostname?(this.ccpaNotice=!0,!0):"ccpa-pm.sp-prod.net"===t.hostname?(this.ccpaPopup=!0,!0):("/index.html"===t.pathname||"/privacy-manager/index.html"===t.pathname)&&(t.searchParams.has("message_id")||t.searchParams.has("requestUUID")||t.searchParams.has("consentUUID"))}async detectPopup(){return!!this.ccpaNotice||(this.ccpaPopup?await p(".priv-save-btn",2e3):(await p(".sp_choice_type_11,.sp_choice_type_12,.sp_choice_type_13,.sp_choice_type_ACCEPT_ALL",2e3),!u(".sp_choice_type_9")))}async optIn(){return await p(".sp_choice_type_11,.sp_choice_type_ACCEPT_ALL",2e3),!!a(".sp_choice_type_11")||!!a(".sp_choice_type_ACCEPT_ALL")}isManagerOpen(){return"/privacy-manager/index.html"===location.pathname}async optOut(){if(this.ccpaPopup){const t=document.querySelectorAll(".priv-purpose-container .sp-switch-arrow-block a.neutral.on .right");for(const e of t)e.click();const e=document.querySelectorAll(".priv-purpose-container .sp-switch-arrow-block a.switch-bg.on");for(const t of e)t.click();return a(".priv-save-btn")}if(!this.isManagerOpen()){if(!await p(".sp_choice_type_12,.sp_choice_type_13"))return!1;if(!u(".sp_choice_type_12"))return a(".sp_choice_type_13");a(".sp_choice_type_12"),await s((()=>this.isManagerOpen()),200,100)}await p(".type-modal",2e4);try{const t=".sp_choice_type_REJECT_ALL",e=".reject-toggle",n=await Promise.race([p(t,2e3).then((t=>t?0:-1)),p(e,2e3).then((t=>t?1:-1)),p(".pm-features",2e3).then((t=>t?2:-1))]);if(0===n)return await h(1e3),a(t);1===n?a(e):2===n&&(await p(".pm-features",1e4),a(".checked > span",!0),a(".chevron"))}catch(t){}return a(".sp_choice_type_SAVE_AND_EXIT")}},new class extends w{get hasSelfTest(){return this.apiAvailable}get isIntermediate(){return!1}get isCosmetic(){return!1}constructor(){super("consentmanager.net"),this.prehideSelectors=["#cmpbox,#cmpbox2"],this.apiAvailable=!1}async detectCmp(){return this.apiAvailable=await c('window.__cmp && typeof __cmp("getCMPData") === "object"'),!!this.apiAvailable||u("#cmpbox")}async detectPopup(){return this.apiAvailable?(await h(500),await c("!__cmp('consentStatus').userChoiceExists")):l("#cmpbox .cmpmore","any")}async optOut(){return await h(500),this.apiAvailable?await c("__cmp('setConsent', 0)"):!!a(".cmpboxbtnno")||(u(".cmpwelcomeprpsbtn")?(a(".cmpwelcomeprpsbtn > a[aria-checked=true]",!0),a(".cmpboxbtnsave"),!0):(a(".cmpboxbtncustom"),await p(".cmptblbox",2e3),a(".cmptdchoice > a[aria-checked=true]",!0),a(".cmpboxbtnyescustomchoices"),!0))}async optIn(){return this.apiAvailable?await c("__cmp('setConsent', 1)"):a(".cmpboxbtnyes")}async test(){if(this.apiAvailable)return await c("__cmp('consentStatus').userChoiceExists")}},new class extends w{constructor(){super("Evidon")}get hasSelfTest(){return!1}get isIntermediate(){return!1}get isCosmetic(){return!1}async detectCmp(){return u("#_evidon_banner")}async detectPopup(){return l("#_evidon_banner","any")}async optOut(){return a("#_evidon-decline-button")||(i(o(),["#evidon-prefdiag-overlay","#evidon-prefdiag-background"]),a("#_evidon-option-button"),await p("#evidon-prefdiag-overlay",5e3),a("#evidon-prefdiag-decline")),!0}async optIn(){return a("#_evidon-accept-button")}},new class extends w{constructor(){super("Onetrust"),this.prehideSelectors=["#onetrust-banner-sdk,#onetrust-consent-sdk,.onetrust-pc-dark-filter,.js-consent-banner"],this.runContext={urlPattern:"^(?!.*https://www\\.nba\\.com/)"}}get hasSelfTest(){return!0}get isIntermediate(){return!1}get isCosmetic(){return!1}async detectCmp(){return u("#onetrust-banner-sdk")}async detectPopup(){return l("#onetrust-banner-sdk","all")}async optOut(){return u("#onetrust-pc-btn-handler")?a("#onetrust-pc-btn-handler"):a(".ot-sdk-show-settings,button.js-cookie-settings"),await p("#onetrust-consent-sdk",2e3),await h(1e3),a("#onetrust-consent-sdk input.category-switch-handler:checked,.js-editor-toggle-state:checked",!0),await h(1e3),await p(".save-preference-btn-handler,.js-consent-save",2e3),a(".save-preference-btn-handler,.js-consent-save"),await s((()=>l("#onetrust-banner-sdk","none")),10,500),!0}async optIn(){return a("#onetrust-accept-btn-handler,.js-accept-cookies")}async test(){return await c("window.OnetrustActiveGroups.split(',').filter(s => s.length > 0).length <= 1")}},new class extends w{constructor(){super("Klaro"),this.prehideSelectors=[".klaro"],this.settingsOpen=!1}get hasSelfTest(){return!0}get isIntermediate(){return!1}get isCosmetic(){return!1}async detectCmp(){return u(".klaro > .cookie-modal")?(this.settingsOpen=!0,!0):u(".klaro > .cookie-notice")}async detectPopup(){return l(".klaro > .cookie-notice,.klaro > .cookie-modal","any")}async optOut(){return!!a(".klaro .cn-decline")||(this.settingsOpen||(a(".klaro .cn-learn-more"),await p(".klaro > .cookie-modal",2e3),this.settingsOpen=!0),!!a(".klaro .cn-decline")||(a(".cm-purpose:not(.cm-toggle-all) > input:not(.half-checked)",!0),a(".cm-btn-accept")))}async optIn(){return!!a(".klaro .cm-btn-accept-all")||(this.settingsOpen?(a(".cm-purpose:not(.cm-toggle-all) > input.half-checked",!0),a(".cm-btn-accept")):a(".klaro .cookie-notice .cm-btn-success"))}async test(){return await c("klaro.getManager().config.services.every(c => c.required || !klaro.getManager().consents[c.name])")}},new class extends w{constructor(){super("Uniconsent")}get prehideSelectors(){return[".unic",".modal:has(.unic)"]}get hasSelfTest(){return!0}get isIntermediate(){return!1}get isCosmetic(){return!1}async detectCmp(){return u(".unic .unic-box,.unic .unic-bar")}async detectPopup(){return l(".unic .unic-box,.unic .unic-bar","any")}async optOut(){if(await p(".unic button",1e3),document.querySelectorAll(".unic button").forEach((t=>{const e=t.textContent;(e.includes("Manage Options")||e.includes("Optionen verwalten"))&&t.click()})),await p(".unic input[type=checkbox]",1e3)){await p(".unic button",1e3),document.querySelectorAll(".unic input[type=checkbox]").forEach((t=>{t.checked&&t.click()}));for(const t of document.querySelectorAll(".unic button")){const e=t.textContent;for(const n of["Confirm Choices","Save Choices","Auswahl speichern"])if(e.includes(n))return t.click(),await h(500),!0}}return!1}async optIn(){return d(".unic #unic-agree")}async test(){await h(1e3);return!u(".unic .unic-box,.unic .unic-bar")}},new class extends w{constructor(){super("Conversant"),this.prehideSelectors=[".cmp-root"]}get hasSelfTest(){return!0}get isIntermediate(){return!1}get isCosmetic(){return!1}async detectCmp(){return u(".cmp-root .cmp-receptacle")}async detectPopup(){return l(".cmp-root .cmp-receptacle","any")}async optOut(){if(!await d(".cmp-main-button:not(.cmp-main-button--primary)"))return!1;if(!await p(".cmp-view-tab-tabs"))return!1;await d(".cmp-view-tab-tabs > :first-child"),await d(".cmp-view-tab-tabs > .cmp-view-tab--active:first-child");for(const t of Array.from(document.querySelectorAll(".cmp-accordion-item"))){t.querySelector(".cmp-accordion-item-title").click(),await s((()=>!!t.querySelector(".cmp-accordion-item-content.cmp-active")),10,50);const e=t.querySelector(".cmp-accordion-item-content.cmp-active");e.querySelectorAll(".cmp-toggle-actions .cmp-toggle-deny:not(.cmp-toggle-deny--active)").forEach((t=>t.click())),e.querySelectorAll(".cmp-toggle-actions .cmp-toggle-checkbox:not(.cmp-toggle-checkbox--active)").forEach((t=>t.click()))}return await a(".cmp-main-button:not(.cmp-main-button--primary)"),!0}async optIn(){return d(".cmp-main-button.cmp-main-button--primary")}async test(){return document.cookie.includes("cmp-data=0")}},new class extends w{constructor(){super("tiktok.com"),this.runContext={urlPattern:"tiktok"}}get hasSelfTest(){return!0}get isIntermediate(){return!1}get isCosmetic(){return!1}getShadowRoot(){const t=document.querySelector("tiktok-cookie-banner");return t?t.shadowRoot:null}async detectCmp(){return u("tiktok-cookie-banner")}async detectPopup(){return r(this.getShadowRoot().querySelector(".tiktok-cookie-banner"))}async optOut(){const t=this.getShadowRoot().querySelector(".button-wrapper button:first-child");return!!t&&(t.click(),!0)}async optIn(){const t=this.getShadowRoot().querySelector(".button-wrapper button:last-child");return!!t&&(t.click(),!0)}async test(){const t=document.cookie.match(/cookie-consent=([^;]+)/);if(!t)return!1;const e=JSON.parse(decodeURIComponent(t[1]));return Object.values(e).every((t=>"boolean"!=typeof t||!1===t))}},new class extends w{constructor(){super("airbnb"),this.runContext={urlPattern:"^https://(www\\.)?airbnb\\.[^/]+/"},this.prehideSelectors=["div[data-testid=main-cookies-banner-container]",'div:has(> div:first-child):has(> div:last-child):has(> section [data-testid="strictly-necessary-cookies"])']}get hasSelfTest(){return!0}get isIntermediate(){return!1}get isCosmetic(){return!1}async detectCmp(){return u("div[data-testid=main-cookies-banner-container]")}async detectPopup(){return l("div[data-testid=main-cookies-banner-container","any")}async optOut(){let t;for(await d("div[data-testid=main-cookies-banner-container] button._snbhip0");t=document.querySelector("[data-testid=modal-container] button[aria-checked=true]:not([disabled])");)t.click();return d("button[data-testid=save-btn]")}async optIn(){return d("div[data-testid=main-cookies-banner-container] button._148dgdpk")}async test(){return await s((()=>!!document.cookie.match("OptanonAlertBoxClosed")),20,200)}}];class _{static setBase(t){_.base=t}static findElement(t,e=null,n=!1){let o=null;return o=null!=e?Array.from(e.querySelectorAll(t.selector)):null!=_.base?Array.from(_.base.querySelectorAll(t.selector)):Array.from(document.querySelectorAll(t.selector)),null!=t.textFilter&&(o=o.filter((e=>{const n=e.textContent.toLowerCase();if(Array.isArray(t.textFilter)){let e=!1;for(const o of t.textFilter)if(-1!==n.indexOf(o.toLowerCase())){e=!0;break}return e}if(null!=t.textFilter)return-1!==n.indexOf(t.textFilter.toLowerCase())}))),null!=t.styleFilters&&(o=o.filter((e=>{const n=window.getComputedStyle(e);let o=!0;for(const e of t.styleFilters){const t=n[e.option];o=e.negated?o&&t!==e.value:o&&t===e.value}return o}))),null!=t.displayFilter&&(o=o.filter((e=>t.displayFilter?0!==e.offsetHeight:0===e.offsetHeight))),null!=t.iframeFilter&&(o=o.filter((()=>t.iframeFilter?window.location!==window.parent.location:window.location===window.parent.location))),null!=t.childFilter&&(o=o.filter((e=>{const n=_.base;_.setBase(e);const o=_.find(t.childFilter);return _.setBase(n),null!=o.target}))),n?o:(o.length>1&&console.warn("Multiple possible targets: ",o,t,e),o[0])}static find(t,e=!1){const n=[];if(null!=t.parent){const o=_.findElement(t.parent,null,e);if(null!=o){if(o instanceof Array)return o.forEach((o=>{const i=_.findElement(t.target,o,e);i instanceof Array?i.forEach((t=>{n.push({parent:o,target:t})})):n.push({parent:o,target:i})})),n;{const i=_.findElement(t.target,o,e);i instanceof Array?i.forEach((t=>{n.push({parent:o,target:t})})):n.push({parent:o,target:i})}}}else{const o=_.findElement(t.target,null,e);o instanceof Array?o.forEach((t=>{n.push({parent:null,target:t})})):n.push({parent:null,target:o})}return 0===n.length&&n.push({parent:null,target:null}),e?n:(1!==n.length&&console.warn("Multiple results found, even though multiple false",n),n[0])}}function S(t){const e=_.find(t);return"css"===t.type?!!e.target:"checkbox"===t.type?!!e.target&&e.target.checked:void 0}async function P(t,e){switch(t.type){case"click":return async function(t){const e=_.find(t);null!=e.target&&e.target.click();return x(0)}(t);case"list":return async function(t,e){for(const n of t.actions)await P(n,e)}(t,e);case"consent":return async function(t,e){for(const n of t.consents){const t=-1!==e.indexOf(n.type);if(n.matcher&&n.toggleAction){S(n.matcher)!==t&&await P(n.toggleAction)}else t?await P(n.trueAction):await P(n.falseAction)}}(t,e);case"ifcss":return async function(t,e){_.find(t).target?t.falseAction&&await P(t.falseAction,e):t.trueAction&&await P(t.trueAction,e)}(t,e);case"waitcss":return async function(t){await new Promise((e=>{let n=t.retries||10;const o=t.waitTime||250,i=()=>{const s=_.find(t);(t.negated&&s.target||!t.negated&&!s.target)&&n>0?(n-=1,setTimeout(i,o)):e()};i()}))}(t);case"foreach":return async function(t,e){const n=_.find(t,!0),o=_.base;for(const o of n)o.target&&(_.setBase(o.target),await P(t.action,e));_.setBase(o)}(t,e);case"hide":return async function(t){const e=_.find(t);e.target&&e.target.classList.add("Autoconsent-Hidden")}(t);case"slide":return async function(t){const e=_.find(t),n=_.find(t.dragTarget);if(e.target){const t=e.target.getBoundingClientRect(),o=n.target.getBoundingClientRect();let i=o.top-t.top,s=o.left-t.left;"y"===this.config.axis.toLowerCase()&&(s=0),"x"===this.config.axis.toLowerCase()&&(i=0);const r=window.screenX+t.left+t.width/2,c=window.screenY+t.top+t.height/2,a=t.left+t.width/2,u=t.top+t.height/2,l=document.createEvent("MouseEvents");l.initMouseEvent("mousedown",!0,!0,window,0,r,c,a,u,!1,!1,!1,!1,0,e.target);const p=document.createEvent("MouseEvents");p.initMouseEvent("mousemove",!0,!0,window,0,r+s,c+i,a+s,u+i,!1,!1,!1,!1,0,e.target);const d=document.createEvent("MouseEvents");d.initMouseEvent("mouseup",!0,!0,window,0,r+s,c+i,a+s,u+i,!1,!1,!1,!1,0,e.target),e.target.dispatchEvent(l),await this.waitTimeout(10),e.target.dispatchEvent(p),await this.waitTimeout(10),e.target.dispatchEvent(d)}}(t);case"close":return async function(){window.close()}();case"wait":return async function(t){await x(t.waitTime)}(t);case"eval":return async function(t){return console.log("eval!",t.code),new Promise((e=>{try{t.async?(window.eval(t.code),setTimeout((()=>{e(window.eval("window.__consentCheckResult"))}),t.timeout||250)):e(window.eval(t.code))}catch(n){console.warn("eval error",n,t.code),e(!1)}}))}(t);default:throw"Unknown action type: "+t.type}}_.base=null;function x(t){return new Promise((e=>{setTimeout((()=>{e()}),t)}))}class A{constructor(t,e){this.name=t,this.config=e,this.methods=new Map,this.runContext=y,this.isCosmetic=!1,e.methods.forEach((t=>{t.action&&this.methods.set(t.name,t.action)})),this.hasSelfTest=!1}get isIntermediate(){return!1}checkRunContext(){return!0}async detectCmp(){return this.config.detectors.map((t=>S(t.presentMatcher))).some((t=>!!t))}async detectPopup(){return this.config.detectors.map((t=>S(t.showingMatcher))).some((t=>!!t))}async executeAction(t,e){return!this.methods.has(t)||P(this.methods.get(t),e)}async optOut(){return await this.executeAction("HIDE_CMP"),await this.executeAction("OPEN_OPTIONS"),await this.executeAction("HIDE_CMP"),await this.executeAction("DO_CONSENT",[]),await this.executeAction("SAVE_CONSENT"),!0}async optIn(){return await this.executeAction("HIDE_CMP"),await this.executeAction("OPEN_OPTIONS"),await this.executeAction("HIDE_CMP"),await this.executeAction("DO_CONSENT",["D","A","B","E","F","X"]),await this.executeAction("SAVE_CONSENT"),!0}async openCmp(){return await this.executeAction("HIDE_CMP"),await this.executeAction("OPEN_OPTIONS"),!0}async test(){return!0}}exports.createAutoCMP=k,exports.default=class{constructor(e,o=null,i=null){if(this.id=t(),this.rules=[],this.foundCmp=null,this.state={lifecycle:"loading",prehideOn:!1,findCmpAttempts:0,detectedCmps:[],detectedPopups:[],selfTest:null},n.sendContentMessage=e,this.sendContentMessage=e,this.rules=[...v],this.updateState({lifecycle:"loading"}),o)this.initialize(o,i);else{i&&this.parseRules(i);e({type:"init",url:window.location.href}),this.updateState({lifecycle:"waitingForInitResponse"})}}initialize(t,e){if(this.config=t,t.enabled){if(e&&this.parseRules(e),this.rules=function(t,e){return t.filter((t=>(!e.disabledCmps||!e.disabledCmps.includes(t.name))&&(e.enableCosmeticRules||!t.isCosmetic)))}(this.rules,t),t.enablePrehide)if(document.documentElement)this.prehideElements();else{const t=()=>{window.removeEventListener("DOMContentLoaded",t),this.prehideElements()};window.addEventListener("DOMContentLoaded",t)}if("loading"===document.readyState){const t=()=>{window.removeEventListener("DOMContentLoaded",t),this.start()};window.addEventListener("DOMContentLoaded",t)}else this.start();this.updateState({lifecycle:"initialized"})}}parseRules(t){Object.keys(t.consentomatic).forEach((e=>{this.addConsentomaticCMP(e,t.consentomatic[e])})),t.autoconsent.forEach((t=>{this.addCMP(t)}))}addCMP(t){this.rules.push(k(t))}addConsentomaticCMP(t,e){this.rules.push(new A(`com_${t}`,e))}start(){window.requestIdleCallback?window.requestIdleCallback((()=>this._start()),{timeout:500}):this._start()}async _start(){this.updateState({lifecycle:"started"});const t=await this.findCmp(this.config.detectRetries);if(this.updateState({detectedCmps:t.map((t=>t.name))}),0===t.length)return this.config.enablePrehide&&this.undoPrehide(),this.updateState({lifecycle:"nothingDetected"}),!1;this.updateState({lifecycle:"cmpDetected"});let e=await this.detectPopups(t.filter((t=>!t.isCosmetic)));if(0===e.length&&(e=await this.detectPopups(t.filter((t=>t.isCosmetic)))),0===e.length)return this.config.enablePrehide&&this.undoPrehide(),!1;if(this.updateState({lifecycle:"openPopupDetected"}),e.length>1){const t={msg:"Found multiple CMPs, check the detection rules.",cmps:e.map((t=>t.name))};this.sendContentMessage({type:"autoconsentError",details:t})}return this.foundCmp=e[0],"optOut"===this.config.autoAction?await this.doOptOut():"optIn"!==this.config.autoAction||await this.doOptIn()}async findCmp(t){this.updateState({findCmpAttempts:this.state.findCmpAttempts+1});const e=[];for(const t of this.rules)try{if(!t.checkRunContext())continue;await t.detectCmp()&&(this.sendContentMessage({type:"cmpDetected",url:location.href,cmp:t.name}),e.push(t))}catch(t){}return 0===e.length&&t>0?(await h(500),this.findCmp(t-1)):e}async detectPopups(t){const e=[],n=t.map((t=>this.waitForPopup(t).then((n=>{n&&(this.updateState({detectedPopups:this.state.detectedPopups.concat([t.name])}),this.sendContentMessage({type:"popupFound",cmp:t.name,url:location.href}),e.push(t))})).catch((()=>null))));return await Promise.all(n),e}async doOptOut(){let t;return this.updateState({lifecycle:"runningOptOut"}),t=!!this.foundCmp&&await this.foundCmp.optOut(),this.config.enablePrehide&&this.undoPrehide(),this.sendContentMessage({type:"optOutResult",cmp:this.foundCmp?this.foundCmp.name:"none",result:t,scheduleSelfTest:this.foundCmp&&this.foundCmp.hasSelfTest,url:location.href}),t&&!this.foundCmp.isIntermediate?(this.sendContentMessage({type:"autoconsentDone",cmp:this.foundCmp.name,isCosmetic:this.foundCmp.isCosmetic,url:location.href}),this.updateState({lifecycle:"done"})):this.updateState({lifecycle:t?"optOutSucceeded":"optOutFailed"}),t}async doOptIn(){let t;return this.updateState({lifecycle:"runningOptIn"}),t=!!this.foundCmp&&await this.foundCmp.optIn(),this.config.enablePrehide&&this.undoPrehide(),this.sendContentMessage({type:"optInResult",cmp:this.foundCmp?this.foundCmp.name:"none",result:t,scheduleSelfTest:!1,url:location.href}),t&&!this.foundCmp.isIntermediate?(this.sendContentMessage({type:"autoconsentDone",cmp:this.foundCmp.name,isCosmetic:this.foundCmp.isCosmetic,url:location.href}),this.updateState({lifecycle:"done"})):this.updateState({lifecycle:t?"optInSucceeded":"optInFailed"}),t}async doSelfTest(){let t;return t=!!this.foundCmp&&await this.foundCmp.test(),this.sendContentMessage({type:"selfTestResult",cmp:this.foundCmp?this.foundCmp.name:"none",result:t,url:location.href}),this.updateState({selfTest:t}),t}async waitForPopup(t,e=5,n=500){const o=await t.detectPopup();return!o&&e>0?(await h(n),this.waitForPopup(t,e-1,n)):o}prehideElements(){const t=this.rules.reduce(((t,e)=>e.prehideSelectors?[...t,...e.prehideSelectors]:t),["#didomi-popup,.didomi-popup-container,.didomi-popup-notice,.didomi-consent-popup-preferences,#didomi-notice,.didomi-popup-backdrop,.didomi-screen-medium"]);return this.updateState({prehideOn:!0}),setTimeout((()=>{this.config.enablePrehide&&this.state.prehideOn&&!["runningOptOut","runningOptIn"].includes(this.state.lifecycle)&&this.undoPrehide()}),this.config.prehideTimeout||2e3),function(t){return i(o("autoconsent-prehide"),t,"opacity")}(t)}undoPrehide(){return this.updateState({prehideOn:!1}),function(){const t=o("autoconsent-prehide");return t&&t.remove(),!!t}()}updateState(t){Object.assign(this.state,t),this.sendContentMessage({type:"report",instanceId:this.id,url:window.location.href,mainFrame:window.top===window.self,state:this.state})}async receiveMessageCallback(t){switch(t.type){case"initResp":this.initialize(t.config,t.rules);break;case"optIn":await this.doOptIn();break;case"optOut":await this.doOptOut();break;case"selfTest":await this.doSelfTest();break;case"evalResp":!function(t,e){const o=n.pending.get(t);o?(n.pending.delete(t),o.timer&&window.clearTimeout(o.timer),o.resolve(e)):console.warn("no eval #",t)}(t.id,t.result)}}},exports.rules=v;
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // lib/web.ts
20
+ var web_exports = {};
21
+ __export(web_exports, {
22
+ createAutoCMP: () => createAutoCMP,
23
+ default: () => AutoConsent,
24
+ rules: () => rules2
25
+ });
26
+ module.exports = __toCommonJS(web_exports);
27
+
28
+ // lib/config.ts
29
+ var enableLogs = false;
30
+
31
+ // lib/random.ts
32
+ function getRandomID() {
33
+ if (crypto && typeof crypto.randomUUID !== "undefined") {
34
+ return crypto.randomUUID();
35
+ }
36
+ return Math.random().toString();
37
+ }
38
+
39
+ // lib/eval-handler.ts
40
+ var Deferred = class {
41
+ constructor(id, timeout = 1e3) {
42
+ this.id = id;
43
+ this.promise = new Promise((resolve, reject) => {
44
+ this.resolve = resolve;
45
+ this.reject = reject;
46
+ });
47
+ this.timer = window.setTimeout(() => {
48
+ this.reject(new Error("timeout"));
49
+ }, timeout);
50
+ }
51
+ };
52
+ var evalState = {
53
+ pending: /* @__PURE__ */ new Map(),
54
+ sendContentMessage: null
55
+ };
56
+ function requestEval(code) {
57
+ const id = getRandomID();
58
+ evalState.sendContentMessage({
59
+ type: "eval",
60
+ id,
61
+ code
62
+ });
63
+ const deferred = new Deferred(id);
64
+ evalState.pending.set(deferred.id, deferred);
65
+ return deferred.promise;
66
+ }
67
+ function resolveEval(id, value) {
68
+ const deferred = evalState.pending.get(id);
69
+ if (deferred) {
70
+ evalState.pending.delete(id);
71
+ deferred.timer && window.clearTimeout(deferred.timer);
72
+ deferred.resolve(value);
73
+ } else {
74
+ console.warn("no eval #", id);
75
+ }
76
+ }
77
+
78
+ // lib/utils.ts
79
+ function getStyleElement(styleOverrideElementId = "autoconsent-css-rules") {
80
+ const styleSelector = `style#${styleOverrideElementId}`;
81
+ const existingElement = document.querySelector(styleSelector);
82
+ if (existingElement && existingElement instanceof HTMLStyleElement) {
83
+ return existingElement;
84
+ } else {
85
+ const parent = document.head || document.getElementsByTagName("head")[0] || document.documentElement;
86
+ const css = document.createElement("style");
87
+ css.id = styleOverrideElementId;
88
+ parent.appendChild(css);
89
+ return css;
90
+ }
91
+ }
92
+ function hideElements(styleEl, selectors, method = "display") {
93
+ const hidingSnippet = method === "opacity" ? `opacity: 0` : `display: none`;
94
+ const rule = `${selectors.join(
95
+ ","
96
+ )} { ${hidingSnippet} !important; z-index: -1 !important; pointer-events: none !important; } `;
97
+ if (styleEl instanceof HTMLStyleElement) {
98
+ styleEl.innerText += rule;
99
+ return selectors.length > 0;
100
+ }
101
+ return false;
102
+ }
103
+ async function waitFor(predicate, maxTimes, interval) {
104
+ const result = await predicate();
105
+ if (!result && maxTimes > 0) {
106
+ return new Promise((resolve) => {
107
+ setTimeout(async () => {
108
+ resolve(waitFor(predicate, maxTimes - 1, interval));
109
+ }, interval);
110
+ });
111
+ }
112
+ return Promise.resolve(result);
113
+ }
114
+ function isElementVisible(elem) {
115
+ if (!elem) {
116
+ return false;
117
+ }
118
+ if (elem.offsetParent !== null) {
119
+ return true;
120
+ } else {
121
+ const css = window.getComputedStyle(elem);
122
+ if (css.position === "fixed" && css.display !== "none") {
123
+ return true;
124
+ }
125
+ }
126
+ return false;
127
+ }
128
+
129
+ // lib/rule-executors.ts
130
+ function doEval(expr) {
131
+ return requestEval(expr).catch((e) => {
132
+ enableLogs && console.error("error evaluating rule", expr, e);
133
+ return false;
134
+ });
135
+ }
136
+ function click(selector, all = false) {
137
+ const elem = elementSelector(selector);
138
+ enableLogs && console.log("[click]", selector, all, elem);
139
+ if (elem.length > 0) {
140
+ if (all) {
141
+ elem.forEach((e) => e.click());
142
+ } else {
143
+ elem[0].click();
144
+ }
145
+ }
146
+ return elem.length > 0;
147
+ }
148
+ function elementExists(selector) {
149
+ const exists = elementSelector(selector).length > 0;
150
+ return exists;
151
+ }
152
+ function elementVisible(selector, check) {
153
+ const elem = elementSelector(selector);
154
+ const results = new Array(elem.length);
155
+ elem.forEach((e, i) => {
156
+ results[i] = isElementVisible(e);
157
+ });
158
+ if (check === "none") {
159
+ return results.every((r) => !r);
160
+ } else if (results.length === 0) {
161
+ return false;
162
+ } else if (check === "any") {
163
+ return results.some((r) => r);
164
+ }
165
+ return results.every((r) => r);
166
+ }
167
+ function waitForElement(selector, timeout = 1e4) {
168
+ const interval = 200;
169
+ const times = Math.ceil(timeout / interval);
170
+ return waitFor(
171
+ () => elementSelector(selector).length > 0,
172
+ times,
173
+ interval
174
+ );
175
+ }
176
+ function waitForVisible(selector, timeout = 1e4, check = "any") {
177
+ const interval = 200;
178
+ const times = Math.ceil(timeout / interval);
179
+ return waitFor(
180
+ () => elementVisible(selector, check),
181
+ times,
182
+ interval
183
+ );
184
+ }
185
+ async function waitForThenClick(selector, timeout = 1e4, all = false) {
186
+ await waitForElement(selector, timeout);
187
+ return click(selector, all);
188
+ }
189
+ function wait(ms) {
190
+ return new Promise((resolve) => {
191
+ setTimeout(() => {
192
+ resolve(true);
193
+ }, ms);
194
+ });
195
+ }
196
+ function hide(selectors, method) {
197
+ const styleEl = getStyleElement();
198
+ return hideElements(styleEl, selectors, method);
199
+ }
200
+ function prehide(selectors) {
201
+ const styleEl = getStyleElement("autoconsent-prehide");
202
+ enableLogs && console.log("[prehide]", styleEl, location.href);
203
+ return hideElements(styleEl, selectors, "opacity");
204
+ }
205
+ function undoPrehide() {
206
+ const existingElement = getStyleElement("autoconsent-prehide");
207
+ enableLogs && console.log("[undoprehide]", existingElement, location.href);
208
+ if (existingElement) {
209
+ existingElement.remove();
210
+ }
211
+ return !!existingElement;
212
+ }
213
+ function querySingleReplySelector(selector, parent = document) {
214
+ if (selector.startsWith("aria/")) {
215
+ return [];
216
+ }
217
+ if (selector.startsWith("xpath/")) {
218
+ const xpath = selector.slice(6);
219
+ const result = document.evaluate(xpath, parent, null, XPathResult.ANY_TYPE, null);
220
+ let node = null;
221
+ const elements = [];
222
+ while (node = result.iterateNext()) {
223
+ elements.push(node);
224
+ }
225
+ return elements;
226
+ }
227
+ if (selector.startsWith("text/")) {
228
+ return [];
229
+ }
230
+ if (selector.startsWith("pierce/")) {
231
+ return [];
232
+ }
233
+ if (parent.shadowRoot) {
234
+ return Array.from(parent.shadowRoot.querySelectorAll(selector));
235
+ }
236
+ return Array.from(parent.querySelectorAll(selector));
237
+ }
238
+ function querySelectorChain(selectors) {
239
+ let parent = document;
240
+ let matches2;
241
+ for (const selector of selectors) {
242
+ matches2 = querySingleReplySelector(selector, parent);
243
+ if (matches2.length === 0) {
244
+ return [];
245
+ }
246
+ parent = matches2[0];
247
+ }
248
+ return matches2;
249
+ }
250
+ function elementSelector(selector) {
251
+ if (typeof selector === "string") {
252
+ return querySingleReplySelector(selector);
253
+ }
254
+ return querySelectorChain(selector);
255
+ }
256
+
257
+ // lib/cmps/base.ts
258
+ var defaultRunContext = {
259
+ main: true,
260
+ frame: false,
261
+ urlPattern: ""
262
+ };
263
+ var AutoConsentCMPBase = class {
264
+ constructor(name) {
265
+ this.runContext = defaultRunContext;
266
+ this.name = name;
267
+ }
268
+ get hasSelfTest() {
269
+ throw new Error("Not Implemented");
270
+ }
271
+ get isIntermediate() {
272
+ throw new Error("Not Implemented");
273
+ }
274
+ get isCosmetic() {
275
+ throw new Error("Not Implemented");
276
+ }
277
+ checkRunContext() {
278
+ const runCtx = {
279
+ ...defaultRunContext,
280
+ ...this.runContext
281
+ };
282
+ const isTop = window.top === window;
283
+ if (isTop && !runCtx.main) {
284
+ return false;
285
+ }
286
+ if (!isTop && !runCtx.frame) {
287
+ return false;
288
+ }
289
+ if (runCtx.urlPattern && !window.location.href.match(runCtx.urlPattern)) {
290
+ return false;
291
+ }
292
+ return true;
293
+ }
294
+ detectCmp() {
295
+ throw new Error("Not Implemented");
296
+ }
297
+ async detectPopup() {
298
+ return false;
299
+ }
300
+ optOut() {
301
+ throw new Error("Not Implemented");
302
+ }
303
+ optIn() {
304
+ throw new Error("Not Implemented");
305
+ }
306
+ openCmp() {
307
+ throw new Error("Not Implemented");
308
+ }
309
+ async test() {
310
+ return Promise.resolve(true);
311
+ }
312
+ };
313
+ async function evaluateRuleStep(rule) {
314
+ const results = [];
315
+ if (rule.exists) {
316
+ results.push(elementExists(rule.exists));
317
+ }
318
+ if (rule.visible) {
319
+ results.push(elementVisible(rule.visible, rule.check));
320
+ }
321
+ if (rule.eval) {
322
+ const res = doEval(rule.eval);
323
+ results.push(res);
324
+ }
325
+ if (rule.waitFor) {
326
+ results.push(waitForElement(rule.waitFor, rule.timeout));
327
+ }
328
+ if (rule.waitForVisible) {
329
+ results.push(waitForVisible(rule.waitForVisible, rule.timeout, rule.check));
330
+ }
331
+ if (rule.click) {
332
+ results.push(click(rule.click, rule.all));
333
+ }
334
+ if (rule.waitForThenClick) {
335
+ results.push(waitForThenClick(rule.waitForThenClick, rule.timeout, rule.all));
336
+ }
337
+ if (rule.wait) {
338
+ results.push(wait(rule.wait));
339
+ }
340
+ if (rule.hide) {
341
+ results.push(hide(rule.hide, rule.method));
342
+ }
343
+ if (rule.if) {
344
+ if (!rule.if.exists && !rule.if.visible) {
345
+ console.error("invalid conditional rule", rule.if);
346
+ return false;
347
+ }
348
+ const condition = await evaluateRuleStep(rule.if);
349
+ enableLogs && console.log("Condition is", condition);
350
+ if (condition) {
351
+ results.push(_runRulesSequentially(rule.then));
352
+ } else if (rule.else) {
353
+ results.push(_runRulesSequentially(rule.else));
354
+ }
355
+ }
356
+ if (rule.any) {
357
+ for (const step of rule.any) {
358
+ if (await evaluateRuleStep(step)) {
359
+ return true;
360
+ }
361
+ }
362
+ return false;
363
+ }
364
+ if (results.length === 0) {
365
+ enableLogs && console.warn("Unrecognized rule", rule);
366
+ return false;
367
+ }
368
+ const all = await Promise.all(results);
369
+ return all.reduce((a, b) => a && b, true);
370
+ }
371
+ async function _runRulesParallel(rules3) {
372
+ const results = rules3.map((rule) => evaluateRuleStep(rule));
373
+ const detections = await Promise.all(results);
374
+ return detections.every((r) => !!r);
375
+ }
376
+ async function _runRulesSequentially(rules3) {
377
+ for (const rule of rules3) {
378
+ enableLogs && console.log("Running rule...", rule);
379
+ const result = await evaluateRuleStep(rule);
380
+ enableLogs && console.log("...rule result", result);
381
+ if (!result && !rule.optional) {
382
+ return false;
383
+ }
384
+ }
385
+ return true;
386
+ }
387
+ var AutoConsentCMP = class extends AutoConsentCMPBase {
388
+ constructor(config) {
389
+ super(config.name);
390
+ this.config = config;
391
+ this.runContext = config.runContext || defaultRunContext;
392
+ }
393
+ get hasSelfTest() {
394
+ return !!this.config.test;
395
+ }
396
+ get isIntermediate() {
397
+ return !!this.config.intermediate;
398
+ }
399
+ get isCosmetic() {
400
+ return !!this.config.cosmetic;
401
+ }
402
+ get prehideSelectors() {
403
+ return this.config.prehideSelectors;
404
+ }
405
+ async detectCmp() {
406
+ if (this.config.detectCmp) {
407
+ return _runRulesParallel(this.config.detectCmp);
408
+ }
409
+ return false;
410
+ }
411
+ async detectPopup() {
412
+ if (this.config.detectPopup) {
413
+ return _runRulesSequentially(this.config.detectPopup);
414
+ }
415
+ return false;
416
+ }
417
+ async optOut() {
418
+ if (this.config.optOut) {
419
+ enableLogs && console.log("Initiated optOut()", this.config.optOut);
420
+ return _runRulesSequentially(this.config.optOut);
421
+ }
422
+ return false;
423
+ }
424
+ async optIn() {
425
+ if (this.config.optIn) {
426
+ enableLogs && console.log("Initiated optIn()", this.config.optIn);
427
+ return _runRulesSequentially(this.config.optIn);
428
+ }
429
+ return false;
430
+ }
431
+ async openCmp() {
432
+ if (this.config.openCmp) {
433
+ return _runRulesSequentially(this.config.openCmp);
434
+ }
435
+ return false;
436
+ }
437
+ async test() {
438
+ if (this.hasSelfTest) {
439
+ return _runRulesSequentially(this.config.test);
440
+ }
441
+ return super.test();
442
+ }
443
+ };
444
+
445
+ // lib/cmps/trustarc-top.ts
446
+ var cookieSettingsButton = "#truste-show-consent";
447
+ var shortcutOptOut = "#truste-consent-required";
448
+ var shortcutOptIn = "#truste-consent-button";
449
+ var popupContent = "#truste-consent-content";
450
+ var bannerOverlay = "#trustarc-banner-overlay";
451
+ var bannerContainer = "#truste-consent-track";
452
+ var TrustArcTop = class extends AutoConsentCMPBase {
453
+ constructor() {
454
+ super("TrustArc-top");
455
+ this.prehideSelectors = [
456
+ ".trustarc-banner-container",
457
+ `.truste_popframe,.truste_overlay,.truste_box_overlay,${bannerContainer}`
458
+ ];
459
+ this.runContext = {
460
+ main: true,
461
+ frame: false
462
+ };
463
+ this._shortcutButton = null;
464
+ this._optInDone = false;
465
+ }
466
+ get hasSelfTest() {
467
+ return false;
468
+ }
469
+ get isIntermediate() {
470
+ if (this._optInDone) {
471
+ return false;
472
+ }
473
+ return !this._shortcutButton;
474
+ }
475
+ get isCosmetic() {
476
+ return false;
477
+ }
478
+ async detectCmp() {
479
+ const result = elementExists(`${cookieSettingsButton},${bannerContainer}`);
480
+ if (result) {
481
+ this._shortcutButton = document.querySelector(shortcutOptOut);
482
+ }
483
+ return result;
484
+ }
485
+ async detectPopup() {
486
+ return elementVisible(`${popupContent},${bannerOverlay},${bannerContainer}`, "all");
487
+ }
488
+ openFrame() {
489
+ click(cookieSettingsButton);
490
+ }
491
+ async optOut() {
492
+ if (this._shortcutButton) {
493
+ this._shortcutButton.click();
494
+ return true;
495
+ }
496
+ hideElements(
497
+ getStyleElement(),
498
+ [".truste_popframe", ".truste_overlay", ".truste_box_overlay", bannerContainer]
499
+ );
500
+ click(cookieSettingsButton);
501
+ setTimeout(() => {
502
+ getStyleElement().remove();
503
+ }, 1e4);
504
+ return true;
505
+ }
506
+ async optIn() {
507
+ this._optInDone = true;
508
+ return click(shortcutOptIn);
509
+ }
510
+ async openCmp() {
511
+ return true;
512
+ }
513
+ async test() {
514
+ return await doEval("window && window.truste && window.truste.eu.bindMap.prefCookie === '0'");
515
+ }
516
+ };
517
+
518
+ // lib/cmps/trustarc-frame.ts
519
+ var TrustArcFrame = class extends AutoConsentCMPBase {
520
+ constructor() {
521
+ super("TrustArc-frame");
522
+ this.runContext = {
523
+ main: false,
524
+ frame: true,
525
+ urlPattern: "^https://consent-pref\\.trustarc\\.com/\\?"
526
+ };
527
+ }
528
+ get hasSelfTest() {
529
+ return false;
530
+ }
531
+ get isIntermediate() {
532
+ return false;
533
+ }
534
+ get isCosmetic() {
535
+ return false;
536
+ }
537
+ async detectCmp() {
538
+ return true;
539
+ }
540
+ async detectPopup() {
541
+ return elementVisible("#defaultpreferencemanager", "any") && elementVisible(".mainContent", "any");
542
+ }
543
+ async navigateToSettings() {
544
+ await waitFor(
545
+ async () => {
546
+ return elementExists(".shp") || elementVisible(".advance", "any") || elementExists(".switch span:first-child");
547
+ },
548
+ 10,
549
+ 500
550
+ );
551
+ if (elementExists(".shp")) {
552
+ click(".shp");
553
+ }
554
+ await waitForElement(".prefPanel", 5e3);
555
+ if (elementVisible(".advance", "any")) {
556
+ click(".advance");
557
+ }
558
+ return await waitFor(
559
+ () => elementVisible(".switch span:first-child", "any"),
560
+ 5,
561
+ 1e3
562
+ );
563
+ }
564
+ async optOut() {
565
+ await waitFor(() => document.readyState === "complete", 20, 100);
566
+ await waitForElement(".mainContent[aria-hidden=false]", 5e3);
567
+ if (click(".rejectAll")) {
568
+ return true;
569
+ }
570
+ if (elementExists(".prefPanel")) {
571
+ await waitForElement('.prefPanel[style="visibility: visible;"]', 3e3);
572
+ }
573
+ if (click("#catDetails0")) {
574
+ click(".submit");
575
+ return true;
576
+ }
577
+ if (click(".required")) {
578
+ return true;
579
+ }
580
+ await this.navigateToSettings();
581
+ click(".switch span:nth-child(1):not(.active)", true);
582
+ click(".submit");
583
+ waitForElement("#gwt-debug-close_id", 3e5).then(() => {
584
+ click("#gwt-debug-close_id");
585
+ });
586
+ return true;
587
+ }
588
+ async optIn() {
589
+ if (click(".call")) {
590
+ return true;
591
+ }
592
+ await this.navigateToSettings();
593
+ click(".switch span:nth-child(2)", true);
594
+ click(".submit");
595
+ waitForElement("#gwt-debug-close_id", 3e5).then(() => {
596
+ click("#gwt-debug-close_id");
597
+ });
598
+ return true;
599
+ }
600
+ };
601
+
602
+ // lib/cmps/cookiebot.ts
603
+ var Cookiebot = class extends AutoConsentCMPBase {
604
+ constructor() {
605
+ super("Cybotcookiebot");
606
+ this.prehideSelectors = ["#CybotCookiebotDialog,#dtcookie-container,#cookiebanner,#cb-cookieoverlay"];
607
+ }
608
+ get hasSelfTest() {
609
+ return true;
610
+ }
611
+ get isIntermediate() {
612
+ return false;
613
+ }
614
+ get isCosmetic() {
615
+ return false;
616
+ }
617
+ async detectCmp() {
618
+ return elementExists("#CybotCookiebotDialogBodyLevelButtonPreferences");
619
+ }
620
+ async detectPopup() {
621
+ return elementExists("#CybotCookiebotDialog,#dtcookie-container,#cookiebanner,#cb-cookiebanner");
622
+ }
623
+ async optOut() {
624
+ if (click(".cookie-alert-extended-detail-link")) {
625
+ await waitForElement(".cookie-alert-configuration", 2e3);
626
+ click(".cookie-alert-configuration-input:checked", true);
627
+ click(".cookie-alert-extended-button-secondary");
628
+ return true;
629
+ }
630
+ if (elementExists("#dtcookie-container")) {
631
+ return click(".h-dtcookie-decline");
632
+ }
633
+ if (click(".cookiebot__button--settings")) {
634
+ return true;
635
+ }
636
+ if (click("#CybotCookiebotDialogBodyButtonDecline")) {
637
+ return true;
638
+ }
639
+ click(".cookiebanner__link--details");
640
+ click('.CybotCookiebotDialogBodyLevelButton:checked:enabled,input[id*="CybotCookiebotDialogBodyLevelButton"]:checked:enabled', true);
641
+ click("#CybotCookiebotDialogBodyButtonDecline");
642
+ click("input[id^=CybotCookiebotDialogBodyLevelButton]:checked", true);
643
+ if (elementExists("#CybotCookiebotDialogBodyButtonAcceptSelected")) {
644
+ click("#CybotCookiebotDialogBodyButtonAcceptSelected");
645
+ } else {
646
+ click("#CybotCookiebotDialogBodyLevelButtonAccept,#CybotCookiebotDialogBodyButtonAccept,#CybotCookiebotDialogBodyLevelButtonLevelOptinAllowallSelection", true);
647
+ }
648
+ if (await doEval("window.CookieConsent.hasResponse !== true")) {
649
+ await doEval("window.Cookiebot.dialog.submitConsent()");
650
+ await wait(500);
651
+ }
652
+ if (elementExists("#cb-confirmedSettings")) {
653
+ await doEval("endCookieProcess()");
654
+ }
655
+ return true;
656
+ }
657
+ async optIn() {
658
+ if (elementExists("#dtcookie-container")) {
659
+ return click(".h-dtcookie-accept");
660
+ }
661
+ click(".CybotCookiebotDialogBodyLevelButton:not(:checked):enabled", true);
662
+ click("#CybotCookiebotDialogBodyLevelButtonAccept");
663
+ click("#CybotCookiebotDialogBodyButtonAccept");
664
+ return true;
665
+ }
666
+ async test() {
667
+ return doEval("window.CookieConsent.declined === true");
668
+ }
669
+ };
670
+
671
+ // lib/cmps/sourcepoint-frame.ts
672
+ var SourcePoint = class extends AutoConsentCMPBase {
673
+ constructor() {
674
+ super("Sourcepoint-frame");
675
+ this.prehideSelectors = ["div[id^='sp_message_container_'],.message-overlay", "#sp_privacy_manager_container"];
676
+ this.ccpaNotice = false;
677
+ this.ccpaPopup = false;
678
+ this.runContext = {
679
+ main: false,
680
+ frame: true
681
+ };
682
+ }
683
+ get hasSelfTest() {
684
+ return false;
685
+ }
686
+ get isIntermediate() {
687
+ return false;
688
+ }
689
+ get isCosmetic() {
690
+ return false;
691
+ }
692
+ async detectCmp() {
693
+ const url = new URL(location.href);
694
+ if (url.searchParams.has("message_id") && url.hostname === "ccpa-notice.sp-prod.net") {
695
+ this.ccpaNotice = true;
696
+ return true;
697
+ }
698
+ if (url.hostname === "ccpa-pm.sp-prod.net") {
699
+ this.ccpaPopup = true;
700
+ return true;
701
+ }
702
+ return (url.pathname === "/index.html" || url.pathname === "/privacy-manager/index.html") && (url.searchParams.has("message_id") || url.searchParams.has("requestUUID") || url.searchParams.has("consentUUID"));
703
+ }
704
+ async detectPopup() {
705
+ if (this.ccpaNotice) {
706
+ return true;
707
+ }
708
+ if (this.ccpaPopup) {
709
+ return await waitForElement(".priv-save-btn", 2e3);
710
+ }
711
+ await waitForElement(".sp_choice_type_11,.sp_choice_type_12,.sp_choice_type_13,.sp_choice_type_ACCEPT_ALL", 2e3);
712
+ return !elementExists(".sp_choice_type_9");
713
+ }
714
+ async optIn() {
715
+ await waitForElement(".sp_choice_type_11,.sp_choice_type_ACCEPT_ALL", 2e3);
716
+ if (click(".sp_choice_type_11")) {
717
+ return true;
718
+ }
719
+ if (click(".sp_choice_type_ACCEPT_ALL")) {
720
+ return true;
721
+ }
722
+ return false;
723
+ }
724
+ isManagerOpen() {
725
+ return location.pathname === "/privacy-manager/index.html";
726
+ }
727
+ async optOut() {
728
+ if (this.ccpaPopup) {
729
+ const toggles = document.querySelectorAll(".priv-purpose-container .sp-switch-arrow-block a.neutral.on .right");
730
+ for (const t of toggles) {
731
+ t.click();
732
+ }
733
+ const switches = document.querySelectorAll(".priv-purpose-container .sp-switch-arrow-block a.switch-bg.on");
734
+ for (const t of switches) {
735
+ t.click();
736
+ }
737
+ return click(".priv-save-btn");
738
+ }
739
+ if (!this.isManagerOpen()) {
740
+ const actionable = await waitForElement(".sp_choice_type_12,.sp_choice_type_13");
741
+ if (!actionable) {
742
+ return false;
743
+ }
744
+ if (!elementExists(".sp_choice_type_12")) {
745
+ return click(".sp_choice_type_13");
746
+ }
747
+ click(".sp_choice_type_12");
748
+ await waitFor(
749
+ () => this.isManagerOpen(),
750
+ 200,
751
+ 100
752
+ );
753
+ }
754
+ await waitForElement(".type-modal", 2e4);
755
+ try {
756
+ const rejectSelector1 = ".sp_choice_type_REJECT_ALL";
757
+ const rejectSelector2 = ".reject-toggle";
758
+ const path = await Promise.race([
759
+ waitForElement(rejectSelector1, 2e3).then((success) => success ? 0 : -1),
760
+ waitForElement(rejectSelector2, 2e3).then((success) => success ? 1 : -1),
761
+ waitForElement(".pm-features", 2e3).then((success) => success ? 2 : -1)
762
+ ]);
763
+ if (path === 0) {
764
+ await wait(1e3);
765
+ return click(rejectSelector1);
766
+ } else if (path === 1) {
767
+ click(rejectSelector2);
768
+ } else if (path === 2) {
769
+ await waitForElement(".pm-features", 1e4);
770
+ click(".checked > span", true);
771
+ click(".chevron");
772
+ }
773
+ } catch (e) {
774
+ enableLogs && console.warn(e);
775
+ }
776
+ return click(".sp_choice_type_SAVE_AND_EXIT");
777
+ }
778
+ };
779
+
780
+ // lib/cmps/consentmanager.ts
781
+ var ConsentManager = class extends AutoConsentCMPBase {
782
+ constructor() {
783
+ super("consentmanager.net");
784
+ this.prehideSelectors = ["#cmpbox,#cmpbox2"];
785
+ this.apiAvailable = false;
786
+ }
787
+ get hasSelfTest() {
788
+ return this.apiAvailable;
789
+ }
790
+ get isIntermediate() {
791
+ return false;
792
+ }
793
+ get isCosmetic() {
794
+ return false;
795
+ }
796
+ async detectCmp() {
797
+ this.apiAvailable = await doEval('window.__cmp && typeof __cmp("getCMPData") === "object"');
798
+ if (!this.apiAvailable) {
799
+ return elementExists("#cmpbox");
800
+ } else {
801
+ return true;
802
+ }
803
+ }
804
+ async detectPopup() {
805
+ if (this.apiAvailable) {
806
+ await wait(500);
807
+ return await doEval("!__cmp('consentStatus').userChoiceExists");
808
+ }
809
+ return elementVisible("#cmpbox .cmpmore", "any");
810
+ }
811
+ async optOut() {
812
+ await wait(500);
813
+ if (this.apiAvailable) {
814
+ return await doEval("__cmp('setConsent', 0)");
815
+ }
816
+ if (click(".cmpboxbtnno")) {
817
+ return true;
818
+ }
819
+ if (elementExists(".cmpwelcomeprpsbtn")) {
820
+ click(".cmpwelcomeprpsbtn > a[aria-checked=true]", true);
821
+ click(".cmpboxbtnsave");
822
+ return true;
823
+ }
824
+ click(".cmpboxbtncustom");
825
+ await waitForElement(".cmptblbox", 2e3);
826
+ click(".cmptdchoice > a[aria-checked=true]", true);
827
+ click(".cmpboxbtnyescustomchoices");
828
+ return true;
829
+ }
830
+ async optIn() {
831
+ if (this.apiAvailable) {
832
+ return await doEval("__cmp('setConsent', 1)");
833
+ }
834
+ return click(".cmpboxbtnyes");
835
+ }
836
+ async test() {
837
+ if (this.apiAvailable) {
838
+ return await doEval("__cmp('consentStatus').userChoiceExists");
839
+ }
840
+ }
841
+ };
842
+
843
+ // lib/cmps/evidon.ts
844
+ var Evidon = class extends AutoConsentCMPBase {
845
+ constructor() {
846
+ super("Evidon");
847
+ }
848
+ get hasSelfTest() {
849
+ return false;
850
+ }
851
+ get isIntermediate() {
852
+ return false;
853
+ }
854
+ get isCosmetic() {
855
+ return false;
856
+ }
857
+ async detectCmp() {
858
+ return elementExists("#_evidon_banner");
859
+ }
860
+ async detectPopup() {
861
+ return elementVisible("#_evidon_banner", "any");
862
+ }
863
+ async optOut() {
864
+ if (click("#_evidon-decline-button")) {
865
+ return true;
866
+ }
867
+ hideElements(getStyleElement(), ["#evidon-prefdiag-overlay", "#evidon-prefdiag-background"]);
868
+ click("#_evidon-option-button");
869
+ await waitForElement("#evidon-prefdiag-overlay", 5e3);
870
+ click("#evidon-prefdiag-decline");
871
+ return true;
872
+ }
873
+ async optIn() {
874
+ return click("#_evidon-accept-button");
875
+ }
876
+ };
877
+
878
+ // lib/cmps/onetrust.ts
879
+ var Onetrust = class extends AutoConsentCMPBase {
880
+ constructor() {
881
+ super("Onetrust");
882
+ this.prehideSelectors = ["#onetrust-banner-sdk,#onetrust-consent-sdk,.onetrust-pc-dark-filter,.js-consent-banner"];
883
+ this.runContext = {
884
+ urlPattern: "^(?!.*https://www\\.nba\\.com/)"
885
+ };
886
+ }
887
+ get hasSelfTest() {
888
+ return true;
889
+ }
890
+ get isIntermediate() {
891
+ return false;
892
+ }
893
+ get isCosmetic() {
894
+ return false;
895
+ }
896
+ async detectCmp() {
897
+ return elementExists("#onetrust-banner-sdk");
898
+ }
899
+ async detectPopup() {
900
+ return elementVisible("#onetrust-banner-sdk", "all");
901
+ }
902
+ async optOut() {
903
+ if (elementExists("#onetrust-pc-btn-handler")) {
904
+ click("#onetrust-pc-btn-handler");
905
+ } else {
906
+ click(".ot-sdk-show-settings,button.js-cookie-settings");
907
+ }
908
+ await waitForElement("#onetrust-consent-sdk", 2e3);
909
+ await wait(1e3);
910
+ click("#onetrust-consent-sdk input.category-switch-handler:checked,.js-editor-toggle-state:checked", true);
911
+ await wait(1e3);
912
+ await waitForElement(".save-preference-btn-handler,.js-consent-save", 2e3);
913
+ click(".save-preference-btn-handler,.js-consent-save");
914
+ await waitFor(
915
+ () => elementVisible("#onetrust-banner-sdk", "none"),
916
+ 10,
917
+ 500
918
+ );
919
+ return true;
920
+ }
921
+ async optIn() {
922
+ return click("#onetrust-accept-btn-handler,.js-accept-cookies");
923
+ }
924
+ async test() {
925
+ return await doEval("window.OnetrustActiveGroups.split(',').filter(s => s.length > 0).length <= 1");
926
+ }
927
+ };
928
+
929
+ // lib/cmps/klaro.ts
930
+ var Klaro = class extends AutoConsentCMPBase {
931
+ constructor() {
932
+ super("Klaro");
933
+ this.prehideSelectors = [".klaro"];
934
+ this.settingsOpen = false;
935
+ }
936
+ get hasSelfTest() {
937
+ return true;
938
+ }
939
+ get isIntermediate() {
940
+ return false;
941
+ }
942
+ get isCosmetic() {
943
+ return false;
944
+ }
945
+ async detectCmp() {
946
+ if (elementExists(".klaro > .cookie-modal")) {
947
+ this.settingsOpen = true;
948
+ return true;
949
+ }
950
+ return elementExists(".klaro > .cookie-notice");
951
+ }
952
+ async detectPopup() {
953
+ return elementVisible(".klaro > .cookie-notice,.klaro > .cookie-modal", "any");
954
+ }
955
+ async optOut() {
956
+ if (click(".klaro .cn-decline")) {
957
+ return true;
958
+ }
959
+ if (!this.settingsOpen) {
960
+ click(".klaro .cn-learn-more");
961
+ await waitForElement(".klaro > .cookie-modal", 2e3);
962
+ this.settingsOpen = true;
963
+ }
964
+ if (click(".klaro .cn-decline")) {
965
+ return true;
966
+ }
967
+ click(".cm-purpose:not(.cm-toggle-all) > input:not(.half-checked)", true);
968
+ return click(".cm-btn-accept");
969
+ }
970
+ async optIn() {
971
+ if (click(".klaro .cm-btn-accept-all")) {
972
+ return true;
973
+ }
974
+ if (this.settingsOpen) {
975
+ click(".cm-purpose:not(.cm-toggle-all) > input.half-checked", true);
976
+ return click(".cm-btn-accept");
977
+ }
978
+ return click(".klaro .cookie-notice .cm-btn-success");
979
+ }
980
+ async test() {
981
+ return await doEval("klaro.getManager().config.services.every(c => c.required || !klaro.getManager().consents[c.name])");
982
+ }
983
+ };
984
+
985
+ // lib/cmps/uniconsent.ts
986
+ var Uniconsent = class extends AutoConsentCMPBase {
987
+ constructor() {
988
+ super("Uniconsent");
989
+ }
990
+ get prehideSelectors() {
991
+ return [".unic", ".modal:has(.unic)"];
992
+ }
993
+ get hasSelfTest() {
994
+ return true;
995
+ }
996
+ get isIntermediate() {
997
+ return false;
998
+ }
999
+ get isCosmetic() {
1000
+ return false;
1001
+ }
1002
+ async detectCmp() {
1003
+ return elementExists(".unic .unic-box,.unic .unic-bar");
1004
+ }
1005
+ async detectPopup() {
1006
+ return elementVisible(".unic .unic-box,.unic .unic-bar", "any");
1007
+ }
1008
+ async optOut() {
1009
+ await waitForElement(".unic button", 1e3);
1010
+ document.querySelectorAll(".unic button").forEach((button) => {
1011
+ const text = button.textContent;
1012
+ if (text.includes("Manage Options") || text.includes("Optionen verwalten")) {
1013
+ button.click();
1014
+ }
1015
+ });
1016
+ if (await waitForElement(".unic input[type=checkbox]", 1e3)) {
1017
+ await waitForElement(".unic button", 1e3);
1018
+ document.querySelectorAll(".unic input[type=checkbox]").forEach((c) => {
1019
+ if (c.checked) {
1020
+ c.click();
1021
+ }
1022
+ });
1023
+ for (const b of document.querySelectorAll(".unic button")) {
1024
+ const text = b.textContent;
1025
+ for (const pattern of ["Confirm Choices", "Save Choices", "Auswahl speichern"]) {
1026
+ if (text.includes(pattern)) {
1027
+ b.click();
1028
+ await wait(500);
1029
+ return true;
1030
+ }
1031
+ }
1032
+ }
1033
+ }
1034
+ return false;
1035
+ }
1036
+ async optIn() {
1037
+ return waitForThenClick(".unic #unic-agree");
1038
+ }
1039
+ async test() {
1040
+ await wait(1e3);
1041
+ const res = elementExists(".unic .unic-box,.unic .unic-bar");
1042
+ return !res;
1043
+ }
1044
+ };
1045
+
1046
+ // lib/cmps/conversant.ts
1047
+ var Conversant = class extends AutoConsentCMPBase {
1048
+ constructor() {
1049
+ super("Conversant");
1050
+ this.prehideSelectors = [".cmp-root"];
1051
+ }
1052
+ get hasSelfTest() {
1053
+ return true;
1054
+ }
1055
+ get isIntermediate() {
1056
+ return false;
1057
+ }
1058
+ get isCosmetic() {
1059
+ return false;
1060
+ }
1061
+ async detectCmp() {
1062
+ return elementExists(".cmp-root .cmp-receptacle");
1063
+ }
1064
+ async detectPopup() {
1065
+ return elementVisible(".cmp-root .cmp-receptacle", "any");
1066
+ }
1067
+ async optOut() {
1068
+ if (!await waitForThenClick(".cmp-main-button:not(.cmp-main-button--primary)")) {
1069
+ return false;
1070
+ }
1071
+ if (!await waitForElement(".cmp-view-tab-tabs")) {
1072
+ return false;
1073
+ }
1074
+ await waitForThenClick(".cmp-view-tab-tabs > :first-child");
1075
+ await waitForThenClick(".cmp-view-tab-tabs > .cmp-view-tab--active:first-child");
1076
+ for (const item of Array.from(document.querySelectorAll(".cmp-accordion-item"))) {
1077
+ item.querySelector(".cmp-accordion-item-title").click();
1078
+ await waitFor(() => !!item.querySelector(".cmp-accordion-item-content.cmp-active"), 10, 50);
1079
+ const content = item.querySelector(".cmp-accordion-item-content.cmp-active");
1080
+ content.querySelectorAll(".cmp-toggle-actions .cmp-toggle-deny:not(.cmp-toggle-deny--active)").forEach((e) => e.click());
1081
+ content.querySelectorAll(".cmp-toggle-actions .cmp-toggle-checkbox:not(.cmp-toggle-checkbox--active)").forEach((e) => e.click());
1082
+ }
1083
+ await click(".cmp-main-button:not(.cmp-main-button--primary)");
1084
+ return true;
1085
+ }
1086
+ async optIn() {
1087
+ return waitForThenClick(".cmp-main-button.cmp-main-button--primary");
1088
+ }
1089
+ async test() {
1090
+ return document.cookie.includes("cmp-data=0");
1091
+ }
1092
+ };
1093
+
1094
+ // lib/cmps/tiktok.ts
1095
+ var Tiktok = class extends AutoConsentCMPBase {
1096
+ constructor() {
1097
+ super("tiktok.com");
1098
+ this.runContext = {
1099
+ urlPattern: "tiktok"
1100
+ };
1101
+ }
1102
+ get hasSelfTest() {
1103
+ return true;
1104
+ }
1105
+ get isIntermediate() {
1106
+ return false;
1107
+ }
1108
+ get isCosmetic() {
1109
+ return false;
1110
+ }
1111
+ getShadowRoot() {
1112
+ const container = document.querySelector("tiktok-cookie-banner");
1113
+ if (!container) {
1114
+ return null;
1115
+ }
1116
+ return container.shadowRoot;
1117
+ }
1118
+ async detectCmp() {
1119
+ return elementExists("tiktok-cookie-banner");
1120
+ }
1121
+ async detectPopup() {
1122
+ const banner = this.getShadowRoot().querySelector(".tiktok-cookie-banner");
1123
+ return isElementVisible(banner);
1124
+ }
1125
+ async optOut() {
1126
+ const declineButton = this.getShadowRoot().querySelector(".button-wrapper button:first-child");
1127
+ if (declineButton) {
1128
+ enableLogs && console.log("[clicking]", declineButton);
1129
+ declineButton.click();
1130
+ return true;
1131
+ } else {
1132
+ enableLogs && console.log("no decline button found");
1133
+ return false;
1134
+ }
1135
+ }
1136
+ async optIn() {
1137
+ const acceptButton = this.getShadowRoot().querySelector(".button-wrapper button:last-child");
1138
+ if (acceptButton) {
1139
+ enableLogs && console.log("[clicking]", acceptButton);
1140
+ acceptButton.click();
1141
+ return true;
1142
+ } else {
1143
+ enableLogs && console.log("no accept button found");
1144
+ return false;
1145
+ }
1146
+ }
1147
+ async test() {
1148
+ const match = document.cookie.match(/cookie-consent=([^;]+)/);
1149
+ if (!match) {
1150
+ return false;
1151
+ }
1152
+ const value = JSON.parse(decodeURIComponent(match[1]));
1153
+ return Object.values(value).every((x) => typeof x !== "boolean" || x === false);
1154
+ }
1155
+ };
1156
+
1157
+ // lib/cmps/airbnb.ts
1158
+ var Airbnb = class extends AutoConsentCMPBase {
1159
+ constructor() {
1160
+ super("airbnb");
1161
+ this.runContext = {
1162
+ urlPattern: "^https://(www\\.)?airbnb\\.[^/]+/"
1163
+ };
1164
+ this.prehideSelectors = [
1165
+ "div[data-testid=main-cookies-banner-container]",
1166
+ 'div:has(> div:first-child):has(> div:last-child):has(> section [data-testid="strictly-necessary-cookies"])'
1167
+ ];
1168
+ }
1169
+ get hasSelfTest() {
1170
+ return true;
1171
+ }
1172
+ get isIntermediate() {
1173
+ return false;
1174
+ }
1175
+ get isCosmetic() {
1176
+ return false;
1177
+ }
1178
+ async detectCmp() {
1179
+ return elementExists("div[data-testid=main-cookies-banner-container]");
1180
+ }
1181
+ async detectPopup() {
1182
+ return elementVisible("div[data-testid=main-cookies-banner-container", "any");
1183
+ }
1184
+ async optOut() {
1185
+ await waitForThenClick("div[data-testid=main-cookies-banner-container] button._snbhip0");
1186
+ let check;
1187
+ while (check = document.querySelector("[data-testid=modal-container] button[aria-checked=true]:not([disabled])")) {
1188
+ check.click();
1189
+ }
1190
+ return waitForThenClick("button[data-testid=save-btn]");
1191
+ }
1192
+ async optIn() {
1193
+ return waitForThenClick("div[data-testid=main-cookies-banner-container] button._148dgdpk");
1194
+ }
1195
+ async test() {
1196
+ return await waitFor(
1197
+ () => !!document.cookie.match("OptanonAlertBoxClosed"),
1198
+ 20,
1199
+ 200
1200
+ );
1201
+ }
1202
+ };
1203
+
1204
+ // lib/cmps/all.ts
1205
+ var rules = [
1206
+ new TrustArcTop(),
1207
+ new TrustArcFrame(),
1208
+ new Cookiebot(),
1209
+ new SourcePoint(),
1210
+ new ConsentManager(),
1211
+ new Evidon(),
1212
+ new Onetrust(),
1213
+ new Klaro(),
1214
+ new Uniconsent(),
1215
+ new Conversant(),
1216
+ new Tiktok(),
1217
+ new Airbnb()
1218
+ ];
1219
+ function createAutoCMP(config) {
1220
+ return new AutoConsentCMP(config);
1221
+ }
1222
+ var all_default = rules;
1223
+
1224
+ // lib/index.ts
1225
+ var rules2 = all_default;
1226
+
1227
+ // lib/consentomatic/tools.ts
1228
+ var Tools = class _Tools {
1229
+ static {
1230
+ this.base = null;
1231
+ }
1232
+ static setBase(base) {
1233
+ _Tools.base = base;
1234
+ }
1235
+ static findElement(options, parent = null, multiple = false) {
1236
+ let possibleTargets = null;
1237
+ if (parent != null) {
1238
+ possibleTargets = Array.from(parent.querySelectorAll(options.selector));
1239
+ } else {
1240
+ if (_Tools.base != null) {
1241
+ possibleTargets = Array.from(
1242
+ _Tools.base.querySelectorAll(options.selector)
1243
+ );
1244
+ } else {
1245
+ possibleTargets = Array.from(
1246
+ document.querySelectorAll(options.selector)
1247
+ );
1248
+ }
1249
+ }
1250
+ if (options.textFilter != null) {
1251
+ possibleTargets = possibleTargets.filter((possibleTarget) => {
1252
+ const textContent = possibleTarget.textContent.toLowerCase();
1253
+ if (Array.isArray(options.textFilter)) {
1254
+ let foundText = false;
1255
+ for (const text of options.textFilter) {
1256
+ if (textContent.indexOf(text.toLowerCase()) !== -1) {
1257
+ foundText = true;
1258
+ break;
1259
+ }
1260
+ }
1261
+ return foundText;
1262
+ } else if (options.textFilter != null) {
1263
+ return textContent.indexOf(options.textFilter.toLowerCase()) !== -1;
1264
+ }
1265
+ });
1266
+ }
1267
+ if (options.styleFilters != null) {
1268
+ possibleTargets = possibleTargets.filter((possibleTarget) => {
1269
+ const styles = window.getComputedStyle(possibleTarget);
1270
+ let keep = true;
1271
+ for (const styleFilter of options.styleFilters) {
1272
+ const option = styles[styleFilter.option];
1273
+ if (styleFilter.negated) {
1274
+ keep = keep && option !== styleFilter.value;
1275
+ } else {
1276
+ keep = keep && option === styleFilter.value;
1277
+ }
1278
+ }
1279
+ return keep;
1280
+ });
1281
+ }
1282
+ if (options.displayFilter != null) {
1283
+ possibleTargets = possibleTargets.filter((possibleTarget) => {
1284
+ if (options.displayFilter) {
1285
+ return possibleTarget.offsetHeight !== 0;
1286
+ } else {
1287
+ return possibleTarget.offsetHeight === 0;
1288
+ }
1289
+ });
1290
+ }
1291
+ if (options.iframeFilter != null) {
1292
+ possibleTargets = possibleTargets.filter(() => {
1293
+ if (options.iframeFilter) {
1294
+ return window.location !== window.parent.location;
1295
+ } else {
1296
+ return window.location === window.parent.location;
1297
+ }
1298
+ });
1299
+ }
1300
+ if (options.childFilter != null) {
1301
+ possibleTargets = possibleTargets.filter((possibleTarget) => {
1302
+ const oldBase = _Tools.base;
1303
+ _Tools.setBase(possibleTarget);
1304
+ const childResults = _Tools.find(options.childFilter);
1305
+ _Tools.setBase(oldBase);
1306
+ return childResults.target != null;
1307
+ });
1308
+ }
1309
+ if (multiple) {
1310
+ return possibleTargets;
1311
+ } else {
1312
+ if (possibleTargets.length > 1) {
1313
+ console.warn(
1314
+ "Multiple possible targets: ",
1315
+ possibleTargets,
1316
+ options,
1317
+ parent
1318
+ );
1319
+ }
1320
+ return possibleTargets[0];
1321
+ }
1322
+ }
1323
+ static find(options, multiple = false) {
1324
+ const results = [];
1325
+ if (options.parent != null) {
1326
+ const parent = _Tools.findElement(options.parent, null, multiple);
1327
+ if (parent != null) {
1328
+ if (parent instanceof Array) {
1329
+ parent.forEach((p) => {
1330
+ const targets = _Tools.findElement(options.target, p, multiple);
1331
+ if (targets instanceof Array) {
1332
+ targets.forEach((target) => {
1333
+ results.push({
1334
+ parent: p,
1335
+ target
1336
+ });
1337
+ });
1338
+ } else {
1339
+ results.push({
1340
+ parent: p,
1341
+ target: targets
1342
+ });
1343
+ }
1344
+ });
1345
+ return results;
1346
+ } else {
1347
+ const targets = _Tools.findElement(options.target, parent, multiple);
1348
+ if (targets instanceof Array) {
1349
+ targets.forEach((target) => {
1350
+ results.push({
1351
+ parent,
1352
+ target
1353
+ });
1354
+ });
1355
+ } else {
1356
+ results.push({
1357
+ parent,
1358
+ target: targets
1359
+ });
1360
+ }
1361
+ }
1362
+ }
1363
+ } else {
1364
+ const targets = _Tools.findElement(options.target, null, multiple);
1365
+ if (targets instanceof Array) {
1366
+ targets.forEach((target) => {
1367
+ results.push({
1368
+ parent: null,
1369
+ target
1370
+ });
1371
+ });
1372
+ } else {
1373
+ results.push({
1374
+ parent: null,
1375
+ target: targets
1376
+ });
1377
+ }
1378
+ }
1379
+ if (results.length === 0) {
1380
+ results.push({
1381
+ parent: null,
1382
+ target: null
1383
+ });
1384
+ }
1385
+ if (multiple) {
1386
+ return results;
1387
+ } else {
1388
+ if (results.length !== 1) {
1389
+ console.warn(
1390
+ "Multiple results found, even though multiple false",
1391
+ results
1392
+ );
1393
+ }
1394
+ return results[0];
1395
+ }
1396
+ }
1397
+ };
1398
+
1399
+ // lib/consentomatic/index.ts
1400
+ function matches(config) {
1401
+ const result = Tools.find(config);
1402
+ if (config.type === "css") {
1403
+ return !!result.target;
1404
+ } else if (config.type === "checkbox") {
1405
+ return !!result.target && result.target.checked;
1406
+ }
1407
+ }
1408
+ async function executeAction(config, param) {
1409
+ switch (config.type) {
1410
+ case "click":
1411
+ return clickAction(config);
1412
+ case "list":
1413
+ return listAction(config, param);
1414
+ case "consent":
1415
+ return consentAction(config, param);
1416
+ case "ifcss":
1417
+ return ifCssAction(config, param);
1418
+ case "waitcss":
1419
+ return waitCssAction(config);
1420
+ case "foreach":
1421
+ return forEachAction(config, param);
1422
+ case "hide":
1423
+ return hideAction(config);
1424
+ case "slide":
1425
+ return slideAction(config);
1426
+ case "close":
1427
+ return closeAction();
1428
+ case "wait":
1429
+ return waitAction(config);
1430
+ case "eval":
1431
+ return evalAction(config);
1432
+ default:
1433
+ throw "Unknown action type: " + config.type;
1434
+ }
1435
+ }
1436
+ var STEP_TIMEOUT = 0;
1437
+ function waitTimeout(timeout) {
1438
+ return new Promise((resolve) => {
1439
+ setTimeout(() => {
1440
+ resolve();
1441
+ }, timeout);
1442
+ });
1443
+ }
1444
+ async function clickAction(config) {
1445
+ const result = Tools.find(config);
1446
+ if (result.target != null) {
1447
+ result.target.click();
1448
+ }
1449
+ return waitTimeout(STEP_TIMEOUT);
1450
+ }
1451
+ async function listAction(config, param) {
1452
+ for (const action of config.actions) {
1453
+ await executeAction(action, param);
1454
+ }
1455
+ }
1456
+ async function consentAction(config, consentTypes) {
1457
+ for (const consentConfig of config.consents) {
1458
+ const shouldEnable = consentTypes.indexOf(consentConfig.type) !== -1;
1459
+ if (consentConfig.matcher && consentConfig.toggleAction) {
1460
+ const isEnabled = matches(consentConfig.matcher);
1461
+ if (isEnabled !== shouldEnable) {
1462
+ await executeAction(consentConfig.toggleAction);
1463
+ }
1464
+ } else {
1465
+ if (shouldEnable) {
1466
+ await executeAction(consentConfig.trueAction);
1467
+ } else {
1468
+ await executeAction(consentConfig.falseAction);
1469
+ }
1470
+ }
1471
+ }
1472
+ }
1473
+ async function ifCssAction(config, param) {
1474
+ const result = Tools.find(config);
1475
+ if (!result.target) {
1476
+ if (config.trueAction) {
1477
+ await executeAction(config.trueAction, param);
1478
+ }
1479
+ } else {
1480
+ if (config.falseAction) {
1481
+ await executeAction(config.falseAction, param);
1482
+ }
1483
+ }
1484
+ }
1485
+ async function waitCssAction(config) {
1486
+ await new Promise((resolve) => {
1487
+ let numRetries = config.retries || 10;
1488
+ const waitTime = config.waitTime || 250;
1489
+ const checkCss = () => {
1490
+ const result = Tools.find(config);
1491
+ if (config.negated && result.target || !config.negated && !result.target) {
1492
+ if (numRetries > 0) {
1493
+ numRetries -= 1;
1494
+ setTimeout(checkCss, waitTime);
1495
+ } else {
1496
+ resolve();
1497
+ }
1498
+ } else {
1499
+ resolve();
1500
+ }
1501
+ };
1502
+ checkCss();
1503
+ });
1504
+ }
1505
+ async function forEachAction(config, param) {
1506
+ const results = Tools.find(config, true);
1507
+ const oldBase = Tools.base;
1508
+ for (const result of results) {
1509
+ if (result.target) {
1510
+ Tools.setBase(result.target);
1511
+ await executeAction(config.action, param);
1512
+ }
1513
+ }
1514
+ Tools.setBase(oldBase);
1515
+ }
1516
+ async function hideAction(config) {
1517
+ const result = Tools.find(config);
1518
+ if (result.target) {
1519
+ result.target.classList.add("Autoconsent-Hidden");
1520
+ }
1521
+ }
1522
+ async function slideAction(config) {
1523
+ const result = Tools.find(config);
1524
+ const dragResult = Tools.find(config.dragTarget);
1525
+ if (result.target) {
1526
+ const targetBounds = result.target.getBoundingClientRect();
1527
+ const dragTargetBounds = dragResult.target.getBoundingClientRect();
1528
+ let yDiff = dragTargetBounds.top - targetBounds.top;
1529
+ let xDiff = dragTargetBounds.left - targetBounds.left;
1530
+ if (this.config.axis.toLowerCase() === "y") {
1531
+ xDiff = 0;
1532
+ }
1533
+ if (this.config.axis.toLowerCase() === "x") {
1534
+ yDiff = 0;
1535
+ }
1536
+ const screenX = window.screenX + targetBounds.left + targetBounds.width / 2;
1537
+ const screenY = window.screenY + targetBounds.top + targetBounds.height / 2;
1538
+ const clientX = targetBounds.left + targetBounds.width / 2;
1539
+ const clientY = targetBounds.top + targetBounds.height / 2;
1540
+ const mouseDown = document.createEvent("MouseEvents");
1541
+ mouseDown.initMouseEvent(
1542
+ "mousedown",
1543
+ true,
1544
+ true,
1545
+ window,
1546
+ 0,
1547
+ screenX,
1548
+ screenY,
1549
+ clientX,
1550
+ clientY,
1551
+ false,
1552
+ false,
1553
+ false,
1554
+ false,
1555
+ 0,
1556
+ result.target
1557
+ );
1558
+ const mouseMove = document.createEvent("MouseEvents");
1559
+ mouseMove.initMouseEvent(
1560
+ "mousemove",
1561
+ true,
1562
+ true,
1563
+ window,
1564
+ 0,
1565
+ screenX + xDiff,
1566
+ screenY + yDiff,
1567
+ clientX + xDiff,
1568
+ clientY + yDiff,
1569
+ false,
1570
+ false,
1571
+ false,
1572
+ false,
1573
+ 0,
1574
+ result.target
1575
+ );
1576
+ const mouseUp = document.createEvent("MouseEvents");
1577
+ mouseUp.initMouseEvent(
1578
+ "mouseup",
1579
+ true,
1580
+ true,
1581
+ window,
1582
+ 0,
1583
+ screenX + xDiff,
1584
+ screenY + yDiff,
1585
+ clientX + xDiff,
1586
+ clientY + yDiff,
1587
+ false,
1588
+ false,
1589
+ false,
1590
+ false,
1591
+ 0,
1592
+ result.target
1593
+ );
1594
+ result.target.dispatchEvent(mouseDown);
1595
+ await this.waitTimeout(10);
1596
+ result.target.dispatchEvent(mouseMove);
1597
+ await this.waitTimeout(10);
1598
+ result.target.dispatchEvent(mouseUp);
1599
+ }
1600
+ }
1601
+ async function waitAction(config) {
1602
+ await waitTimeout(config.waitTime);
1603
+ }
1604
+ async function closeAction() {
1605
+ window.close();
1606
+ }
1607
+ async function evalAction(config) {
1608
+ console.log("eval!", config.code);
1609
+ return new Promise((resolve) => {
1610
+ try {
1611
+ if (config.async) {
1612
+ window.eval(config.code);
1613
+ setTimeout(() => {
1614
+ resolve(window.eval("window.__consentCheckResult"));
1615
+ }, config.timeout || 250);
1616
+ } else {
1617
+ resolve(window.eval(config.code));
1618
+ }
1619
+ } catch (e) {
1620
+ console.warn("eval error", e, config.code);
1621
+ resolve(false);
1622
+ }
1623
+ });
1624
+ }
1625
+
1626
+ // lib/cmps/consentomatic.ts
1627
+ var ConsentOMaticCMP = class {
1628
+ constructor(name, config) {
1629
+ this.name = name;
1630
+ this.config = config;
1631
+ this.methods = /* @__PURE__ */ new Map();
1632
+ this.runContext = defaultRunContext;
1633
+ this.isCosmetic = false;
1634
+ config.methods.forEach((methodConfig) => {
1635
+ if (methodConfig.action) {
1636
+ this.methods.set(methodConfig.name, methodConfig.action);
1637
+ }
1638
+ });
1639
+ this.hasSelfTest = false;
1640
+ }
1641
+ get isIntermediate() {
1642
+ return false;
1643
+ }
1644
+ checkRunContext() {
1645
+ return true;
1646
+ }
1647
+ async detectCmp() {
1648
+ const matchResults = this.config.detectors.map(
1649
+ (detectorConfig) => matches(detectorConfig.presentMatcher)
1650
+ );
1651
+ return matchResults.some((r) => !!r);
1652
+ }
1653
+ async detectPopup() {
1654
+ const matchResults = this.config.detectors.map(
1655
+ (detectorConfig) => matches(detectorConfig.showingMatcher)
1656
+ );
1657
+ return matchResults.some((r) => !!r);
1658
+ }
1659
+ async executeAction(method, param) {
1660
+ if (this.methods.has(method)) {
1661
+ return executeAction(this.methods.get(method), param);
1662
+ }
1663
+ return true;
1664
+ }
1665
+ async optOut() {
1666
+ await this.executeAction("HIDE_CMP");
1667
+ await this.executeAction("OPEN_OPTIONS");
1668
+ await this.executeAction("HIDE_CMP");
1669
+ await this.executeAction("DO_CONSENT", []);
1670
+ await this.executeAction("SAVE_CONSENT");
1671
+ return true;
1672
+ }
1673
+ async optIn() {
1674
+ await this.executeAction("HIDE_CMP");
1675
+ await this.executeAction("OPEN_OPTIONS");
1676
+ await this.executeAction("HIDE_CMP");
1677
+ await this.executeAction("DO_CONSENT", ["D", "A", "B", "E", "F", "X"]);
1678
+ await this.executeAction("SAVE_CONSENT");
1679
+ return true;
1680
+ }
1681
+ async openCmp() {
1682
+ await this.executeAction("HIDE_CMP");
1683
+ await this.executeAction("OPEN_OPTIONS");
1684
+ return true;
1685
+ }
1686
+ async test() {
1687
+ return true;
1688
+ }
1689
+ };
1690
+
1691
+ // lib/web.ts
1692
+ function filterCMPs(rules3, config) {
1693
+ return rules3.filter((cmp) => {
1694
+ return (!config.disabledCmps || !config.disabledCmps.includes(cmp.name)) && (config.enableCosmeticRules || !cmp.isCosmetic);
1695
+ });
1696
+ }
1697
+ var AutoConsent = class {
1698
+ constructor(sendContentMessage, config = null, declarativeRules = null) {
1699
+ this.id = getRandomID();
1700
+ this.rules = [];
1701
+ this.foundCmp = null;
1702
+ this.state = {
1703
+ lifecycle: "loading",
1704
+ prehideOn: false,
1705
+ findCmpAttempts: 0,
1706
+ detectedCmps: [],
1707
+ detectedPopups: [],
1708
+ selfTest: null
1709
+ };
1710
+ evalState.sendContentMessage = sendContentMessage;
1711
+ this.sendContentMessage = sendContentMessage;
1712
+ this.rules = [...rules2];
1713
+ enableLogs && console.log("autoconsent init", window.location.href);
1714
+ this.updateState({ lifecycle: "loading" });
1715
+ if (config) {
1716
+ this.initialize(config, declarativeRules);
1717
+ } else {
1718
+ if (declarativeRules) {
1719
+ this.parseRules(declarativeRules);
1720
+ }
1721
+ const initMsg = {
1722
+ type: "init",
1723
+ url: window.location.href
1724
+ };
1725
+ sendContentMessage(initMsg);
1726
+ this.updateState({ lifecycle: "waitingForInitResponse" });
1727
+ }
1728
+ }
1729
+ initialize(config, declarativeRules) {
1730
+ this.config = config;
1731
+ if (!config.enabled) {
1732
+ enableLogs && console.log("autoconsent is disabled");
1733
+ return;
1734
+ }
1735
+ if (declarativeRules) {
1736
+ this.parseRules(declarativeRules);
1737
+ }
1738
+ this.rules = filterCMPs(this.rules, config);
1739
+ if (config.enablePrehide) {
1740
+ if (document.documentElement) {
1741
+ this.prehideElements();
1742
+ } else {
1743
+ const delayedPrehide = () => {
1744
+ window.removeEventListener("DOMContentLoaded", delayedPrehide);
1745
+ this.prehideElements();
1746
+ };
1747
+ window.addEventListener("DOMContentLoaded", delayedPrehide);
1748
+ }
1749
+ }
1750
+ if (document.readyState === "loading") {
1751
+ const onReady = () => {
1752
+ window.removeEventListener("DOMContentLoaded", onReady);
1753
+ this.start();
1754
+ };
1755
+ window.addEventListener("DOMContentLoaded", onReady);
1756
+ } else {
1757
+ this.start();
1758
+ }
1759
+ this.updateState({ lifecycle: "initialized" });
1760
+ }
1761
+ parseRules(declarativeRules) {
1762
+ Object.keys(declarativeRules.consentomatic).forEach((name) => {
1763
+ this.addConsentomaticCMP(name, declarativeRules.consentomatic[name]);
1764
+ });
1765
+ declarativeRules.autoconsent.forEach((rule) => {
1766
+ this.addCMP(rule);
1767
+ });
1768
+ enableLogs && console.log("added rules", this.rules);
1769
+ }
1770
+ addCMP(config) {
1771
+ this.rules.push(createAutoCMP(config));
1772
+ }
1773
+ addConsentomaticCMP(name, config) {
1774
+ this.rules.push(new ConsentOMaticCMP(`com_${name}`, config));
1775
+ }
1776
+ // start the detection process, possibly with a delay
1777
+ start() {
1778
+ if (window.requestIdleCallback) {
1779
+ window.requestIdleCallback(() => this._start(), { timeout: 500 });
1780
+ } else {
1781
+ this._start();
1782
+ }
1783
+ }
1784
+ async _start() {
1785
+ enableLogs && console.log(`Detecting CMPs on ${window.location.href}`);
1786
+ this.updateState({ lifecycle: "started" });
1787
+ const foundCmps = await this.findCmp(this.config.detectRetries);
1788
+ this.updateState({ detectedCmps: foundCmps.map((c) => c.name) });
1789
+ if (foundCmps.length === 0) {
1790
+ enableLogs && console.log("no CMP found", location.href);
1791
+ if (this.config.enablePrehide) {
1792
+ this.undoPrehide();
1793
+ }
1794
+ this.updateState({ lifecycle: "nothingDetected" });
1795
+ return false;
1796
+ }
1797
+ this.updateState({ lifecycle: "cmpDetected" });
1798
+ let foundPopups = await this.detectPopups(foundCmps.filter((r) => !r.isCosmetic));
1799
+ if (foundPopups.length === 0) {
1800
+ foundPopups = await this.detectPopups(foundCmps.filter((r) => r.isCosmetic));
1801
+ }
1802
+ if (foundPopups.length === 0) {
1803
+ enableLogs && console.log("no popup found");
1804
+ if (this.config.enablePrehide) {
1805
+ this.undoPrehide();
1806
+ }
1807
+ return false;
1808
+ }
1809
+ this.updateState({ lifecycle: "openPopupDetected" });
1810
+ if (foundPopups.length > 1) {
1811
+ const errorDetails = {
1812
+ msg: `Found multiple CMPs, check the detection rules.`,
1813
+ cmps: foundPopups.map((cmp) => cmp.name)
1814
+ };
1815
+ enableLogs && console.warn(errorDetails.msg, errorDetails.cmps);
1816
+ this.sendContentMessage({
1817
+ type: "autoconsentError",
1818
+ details: errorDetails
1819
+ });
1820
+ }
1821
+ this.foundCmp = foundPopups[0];
1822
+ if (this.config.autoAction === "optOut") {
1823
+ return await this.doOptOut();
1824
+ } else if (this.config.autoAction === "optIn") {
1825
+ return await this.doOptIn();
1826
+ } else {
1827
+ enableLogs && console.log("waiting for opt-out signal...", location.href);
1828
+ return true;
1829
+ }
1830
+ }
1831
+ async findCmp(retries) {
1832
+ this.updateState({ findCmpAttempts: this.state.findCmpAttempts + 1 });
1833
+ const foundCMPs = [];
1834
+ for (const cmp of this.rules) {
1835
+ try {
1836
+ if (!cmp.checkRunContext()) {
1837
+ continue;
1838
+ }
1839
+ const result = await cmp.detectCmp();
1840
+ if (result) {
1841
+ enableLogs && console.log(`Found CMP: ${cmp.name} ${window.location.href}`);
1842
+ this.sendContentMessage({
1843
+ type: "cmpDetected",
1844
+ url: location.href,
1845
+ cmp: cmp.name
1846
+ });
1847
+ foundCMPs.push(cmp);
1848
+ }
1849
+ } catch (e) {
1850
+ enableLogs && console.warn(`error detecting ${cmp.name}`, e);
1851
+ }
1852
+ }
1853
+ if (foundCMPs.length === 0 && retries > 0) {
1854
+ await wait(500);
1855
+ return this.findCmp(retries - 1);
1856
+ }
1857
+ return foundCMPs;
1858
+ }
1859
+ async detectPopups(cmps) {
1860
+ const result = [];
1861
+ const popupLookups = cmps.map((cmp) => this.waitForPopup(cmp).then((isOpen) => {
1862
+ if (isOpen) {
1863
+ this.updateState({ detectedPopups: this.state.detectedPopups.concat([cmp.name]) });
1864
+ this.sendContentMessage({
1865
+ type: "popupFound",
1866
+ cmp: cmp.name,
1867
+ url: location.href
1868
+ });
1869
+ result.push(cmp);
1870
+ }
1871
+ }).catch(() => null));
1872
+ await Promise.all(popupLookups);
1873
+ return result;
1874
+ }
1875
+ async doOptOut() {
1876
+ this.updateState({ lifecycle: "runningOptOut" });
1877
+ let optOutResult;
1878
+ if (!this.foundCmp) {
1879
+ enableLogs && console.log("no CMP to opt out");
1880
+ optOutResult = false;
1881
+ } else {
1882
+ enableLogs && console.log(`CMP ${this.foundCmp.name}: opt out on ${window.location.href}`);
1883
+ optOutResult = await this.foundCmp.optOut();
1884
+ enableLogs && console.log(`${this.foundCmp.name}: opt out result ${optOutResult}`);
1885
+ }
1886
+ if (this.config.enablePrehide) {
1887
+ this.undoPrehide();
1888
+ }
1889
+ this.sendContentMessage({
1890
+ type: "optOutResult",
1891
+ cmp: this.foundCmp ? this.foundCmp.name : "none",
1892
+ result: optOutResult,
1893
+ scheduleSelfTest: this.foundCmp && this.foundCmp.hasSelfTest,
1894
+ url: location.href
1895
+ });
1896
+ if (optOutResult && !this.foundCmp.isIntermediate) {
1897
+ this.sendContentMessage({
1898
+ type: "autoconsentDone",
1899
+ cmp: this.foundCmp.name,
1900
+ isCosmetic: this.foundCmp.isCosmetic,
1901
+ url: location.href
1902
+ });
1903
+ this.updateState({ lifecycle: "done" });
1904
+ } else {
1905
+ this.updateState({ lifecycle: optOutResult ? "optOutSucceeded" : "optOutFailed" });
1906
+ }
1907
+ return optOutResult;
1908
+ }
1909
+ async doOptIn() {
1910
+ this.updateState({ lifecycle: "runningOptIn" });
1911
+ let optInResult;
1912
+ if (!this.foundCmp) {
1913
+ enableLogs && console.log("no CMP to opt in");
1914
+ optInResult = false;
1915
+ } else {
1916
+ enableLogs && console.log(`CMP ${this.foundCmp.name}: opt in on ${window.location.href}`);
1917
+ optInResult = await this.foundCmp.optIn();
1918
+ enableLogs && console.log(`${this.foundCmp.name}: opt in result ${optInResult}`);
1919
+ }
1920
+ if (this.config.enablePrehide) {
1921
+ this.undoPrehide();
1922
+ }
1923
+ this.sendContentMessage({
1924
+ type: "optInResult",
1925
+ cmp: this.foundCmp ? this.foundCmp.name : "none",
1926
+ result: optInResult,
1927
+ scheduleSelfTest: false,
1928
+ // self-tests are only for opt-out at the moment
1929
+ url: location.href
1930
+ });
1931
+ if (optInResult && !this.foundCmp.isIntermediate) {
1932
+ this.sendContentMessage({
1933
+ type: "autoconsentDone",
1934
+ cmp: this.foundCmp.name,
1935
+ isCosmetic: this.foundCmp.isCosmetic,
1936
+ url: location.href
1937
+ });
1938
+ this.updateState({ lifecycle: "done" });
1939
+ } else {
1940
+ this.updateState({ lifecycle: optInResult ? "optInSucceeded" : "optInFailed" });
1941
+ }
1942
+ return optInResult;
1943
+ }
1944
+ async doSelfTest() {
1945
+ let selfTestResult;
1946
+ if (!this.foundCmp) {
1947
+ enableLogs && console.log("no CMP to self test");
1948
+ selfTestResult = false;
1949
+ } else {
1950
+ enableLogs && console.log(`CMP ${this.foundCmp.name}: self-test on ${window.location.href}`);
1951
+ selfTestResult = await this.foundCmp.test();
1952
+ }
1953
+ this.sendContentMessage({
1954
+ type: "selfTestResult",
1955
+ cmp: this.foundCmp ? this.foundCmp.name : "none",
1956
+ result: selfTestResult,
1957
+ url: location.href
1958
+ });
1959
+ this.updateState({ selfTest: selfTestResult });
1960
+ return selfTestResult;
1961
+ }
1962
+ async waitForPopup(cmp, retries = 5, interval = 500) {
1963
+ enableLogs && console.log("checking if popup is open...", cmp.name);
1964
+ const isOpen = await cmp.detectPopup();
1965
+ if (!isOpen && retries > 0) {
1966
+ await wait(interval);
1967
+ return this.waitForPopup(cmp, retries - 1, interval);
1968
+ }
1969
+ enableLogs && console.log(cmp.name, `popup is ${isOpen ? "open" : "not open"}`);
1970
+ return isOpen;
1971
+ }
1972
+ prehideElements() {
1973
+ const globalHidden = [
1974
+ "#didomi-popup,.didomi-popup-container,.didomi-popup-notice,.didomi-consent-popup-preferences,#didomi-notice,.didomi-popup-backdrop,.didomi-screen-medium"
1975
+ ];
1976
+ const selectors = this.rules.reduce((selectorList, rule) => {
1977
+ if (rule.prehideSelectors) {
1978
+ return [...selectorList, ...rule.prehideSelectors];
1979
+ }
1980
+ return selectorList;
1981
+ }, globalHidden);
1982
+ this.updateState({ prehideOn: true });
1983
+ setTimeout(() => {
1984
+ if (this.config.enablePrehide && this.state.prehideOn && !["runningOptOut", "runningOptIn"].includes(this.state.lifecycle)) {
1985
+ enableLogs && console.log("Process is taking too long, unhiding elements");
1986
+ this.undoPrehide();
1987
+ }
1988
+ }, this.config.prehideTimeout || 2e3);
1989
+ return prehide(selectors);
1990
+ }
1991
+ undoPrehide() {
1992
+ this.updateState({ prehideOn: false });
1993
+ return undoPrehide();
1994
+ }
1995
+ updateState(change) {
1996
+ Object.assign(this.state, change);
1997
+ this.sendContentMessage({
1998
+ type: "report",
1999
+ instanceId: this.id,
2000
+ url: window.location.href,
2001
+ mainFrame: window.top === window.self,
2002
+ state: this.state
2003
+ });
2004
+ }
2005
+ async receiveMessageCallback(message) {
2006
+ if (enableLogs && ["evalResp", "report"].includes(message.type)) {
2007
+ console.log("received from background", message, window.location.href);
2008
+ }
2009
+ switch (message.type) {
2010
+ case "initResp":
2011
+ this.initialize(message.config, message.rules);
2012
+ break;
2013
+ case "optIn":
2014
+ await this.doOptIn();
2015
+ break;
2016
+ case "optOut":
2017
+ await this.doOptOut();
2018
+ break;
2019
+ case "selfTest":
2020
+ await this.doSelfTest();
2021
+ break;
2022
+ case "evalResp":
2023
+ resolveEval(message.id, message.result);
2024
+ break;
2025
+ }
2026
+ }
2027
+ };
2028
+ // Annotate the CommonJS export names for ESM import in node:
2029
+ 0 && (module.exports = {
2030
+ createAutoCMP,
2031
+ rules
2032
+ });