function cookieBlocker() { return { isCookieNameMatch: function (cookieName, regexp) { let regExpCookieName = regexp; if (regExpCookieName instanceof RegExp) { regExpCookieName = regexp.toString(); regExpCookieName = regExpCookieName.slice(1, regExpCookieName.lastIndexOf('/')); if (regExpCookieName.startsWith('^')) { regExpCookieName = regExpCookieName.slice(1); } if (regExpCookieName.endsWith('$')) { regExpCookieName = regExpCookieName.slice(0, -1); } } let regExp = new RegExp(regExpCookieName, 'g'); return regExp.test(cookieName); }, isDomainAllowed: function (domain) { if (this.checkAcceptAll()) { return true; } if (!window.domains_whitelist.includes(document.domain)) { window.domains_whitelist.push(document.domain); } if (!window.domains_whitelist.includes('cdn.doofinder.com')) { window.domains_whitelist.push('cdn.doofinder.com'); } if (!window.domains_whitelist.includes('googletagmanager.com')) { window.domains_whitelist.push('googletagmanager.com'); } if (!window.domains_whitelist.includes('www.google.com/recaptcha')) { window.domains_whitelist.push('www.google.com/recaptcha'); } if (!window.domains_whitelist.includes('www.gstatic.com/recaptcha')) { window.domains_whitelist.push('www.gstatic.com/recaptcha'); } let whitelist = window.domains_whitelist ?? []; if (whitelist.length) { for (let allowedDomain of whitelist) { if (domain.includes(allowedDomain)) { return true; } } } return false; }, getCookieDescriptor: function (referenceWindow = null) { let referenceObject = referenceWindow ? referenceWindow.Object : Object; let cookieDescriptor = referenceObject.getOwnPropertyDescriptor(document, 'cookie') || referenceObject.getOwnPropertyDescriptor(HTMLDocument.prototype, 'cookie'); if (!cookieDescriptor) { cookieDescriptor = {}; cookieDescriptor.get = HTMLDocument.prototype.__lookupGetter__('cookie'); cookieDescriptor.set = HTMLDocument.prototype.__lookupSetter__('cookie'); } return cookieDescriptor; }, shouldBypass: function () { const bypassGetParameters = {"1":"_storyblok","2":"preview_token"}, bypassUserAgents = {"1":"rocket-cypress"}; const urlParams = new URLSearchParams(window.location.search); for (const parameter in bypassGetParameters) { if (urlParams.has(bypassGetParameters[parameter])) { return true; } } const currentUserAgent = window.navigator.userAgent; for (const userAgent in bypassUserAgents) { if (currentUserAgent == bypassUserAgents[userAgent]) { return true; } } return this.checkAcceptAll(); }, checkAcceptAll() { let result = false; try { let cookieValue = document.cookie.match('(^|;) ?' + 'cookie-consent' + '=([^;]*)(;|$)'); cookieValue = cookieValue ? cookieValue[2] : null; cookieValue = cookieValue ? JSON.parse(decodeURIComponent(cookieValue)) : false; result = (cookieValue && Object.values(cookieValue.consents).every(item => item)) ? true : false; } catch (error) { console.log(error); result = false; } return result; }, setDefaultDomain: function () { window.domains_whitelist = [document.domain]; }, init: function (referenceWindow = null) { window.bypass_cookie_consent = this.shouldBypass(); if (window.bypass_cookie_consent) { return; } if (typeof window.domains_whitelist === 'undefined' || window.domains_whitelist.length === 0) { this.setDefaultDomain(); } const self = this; let cookieDescriptor = self.getCookieDescriptor(referenceWindow); let referenceObject = referenceWindow ? referenceWindow.Object : Object; let cookies_whitelist = [{"regexp":"\/_sp_.+\/","path":"\/","domain":null},{"regexp":"CONSENT","path":"\/","domain":null},{"regexp":"\/.?NID\/","path":"\/","domain":null},{"regexp":"\/__Secure\\-\/","path":"\/","domain":null},{"regexp":"\/__Secure\\-\/","path":"\/","domain":null},{"regexp":"\/.*SID\/","path":"\/","domain":null},{"regexp":"_GRECAPTCHA","path":"\/","domain":null},{"regexp":"Geo","path":"\/","domain":null},{"regexp":"geoip_store","path":"\/","domain":null},{"regexp":"cookie-consent","path":"\/","domain":null},{"regexp":"PHPSESSID","path":"\/","domain":null},{"regexp":"frontend","path":"\/","domain":null},{"regexp":"cookienotice","path":"\/","domain":null},{"regexp":"form_key","path":"\/","domain":null},{"regexp":"\/mage-.+\/","path":"\/","domain":null},{"regexp":"\/recently_.+\/","path":"\/","domain":null},{"regexp":"product_data_storage","path":"\/","domain":null},{"regexp":"add_to_cart","path":"\/","domain":null},{"regexp":"remove_from_cart","path":"\/","domain":null},{"regexp":"guest-view","path":"\/","domain":null},{"regexp":"login_redirect","path":"\/","domain":null},{"regexp":"stf","path":"\/","domain":null},{"regexp":"X-Magento-Vary","path":"\/","domain":null},{"regexp":"private_content_version","path":"\/","domain":null},{"regexp":"section_data_ids","path":"\/","domain":null},{"regexp":"store","path":"\/","domain":null},{"regexp":"user_allowed_save_cookie","path":"\/","domain":null},{"regexp":"OGPC","path":"\/","domain":null},{"regexp":"CGIC","path":"\/","domain":null},{"regexp":"SIDCC","path":"\/","domain":null},{"regexp":"DV","path":"\/","domain":null},{"regexp":"outdated_browser_popup","path":"\/","domain":null}] referenceObject.defineProperty(document, 'cookie', { configurable: true, get: function () { return cookieDescriptor.get.apply(document); }, set: function () { let whitelist = window.cookies_whitelist ?? cookies_whitelist; let cookieSetArguments = arguments; if (whitelist.length) { let cookieName = arguments[0].split('=')[0]; Array.prototype.forEach.call(whitelist, function (whitelistItem) { if (self.isCookieNameMatch(cookieName, whitelistItem.regexp)) { cookieDescriptor.set.apply(document, cookieSetArguments); } }); } } }); let originalAppendChild = Element.prototype.appendChild; Element.prototype.appendChild = function() { return processInjectingTag.call(this, originalAppendChild, ...arguments); }; let originalInsertBefore = Element.prototype.insertBefore; Element.prototype.insertBefore = function () { return processInjectingTag.call(this, originalInsertBefore, ...arguments); }; function processInjectingTag(method, ...args) { const injectingTag = args[0]; if (!injectingTag) { return; } const {nodeName, src} = injectingTag; const isScript = nodeName === 'SCRIPT'; if (!src || !isScript || (isScript && self.isDomainAllowed(src))) { return method.apply(this, args); } handleRejectedScript(src); } function handleRejectedScript(src) { console.log('Script is not allowed: ' + src); window.scripts_rejected = window.scripts_rejected || []; if (!window.scripts_rejected.includes(src)) { window.scripts_rejected.push(src); } } } } } cookieBlocker().init();//catches cookies set before DOM loaded document.addEventListener('DOMContentLoaded', function () {//catches cookies set after DOM loaded cookieBlocker().init(window); }, false);