1(function() { 2 'use strict'; 3 4 var config = window.cdpCookiesConfig || {}; 5 var cookieName = config.cookieName || 'cdp_cookie_consent'; 6 var maxAge = parseInt(config.maxAge || 31536000, 10); 7 var scriptRuns = {}; 8 9 function readConsent() { 10 var cookies = document.cookie ? document.cookie.split('; ') : []; 11 12 for (var i = 0; i < cookies.length; i++) { 13 var parts = cookies[i].split('='); 14 var name = decodeURIComponent(parts.shift()); 15 16 if (name !== cookieName) { 17 continue; 18 } 19 20 try { 21 return JSON.parse(decodeURIComponent(parts.join('='))); 22 } catch (error) { 23 return null; 24 } 25 } 26 27 return null; 28 } 29 30 function writeConsent(consent) { 31 consent.updatedAt = new Date().toISOString(); 32 document.cookie = encodeURIComponent(cookieName) + '=' + encodeURIComponent(JSON.stringify(consent)) + '; max-age=' + maxAge + '; path=/; SameSite=Lax'; 33 } 34 35 function buildConsent(accepted) { 36 var consent = { 37 necessary: true, 38 analytics: !!accepted, 39 marketing: !!accepted, 40 personalization: !!accepted 41 }; 42 43 return consent; 44 } 45 46 function syncPanel(consent) { 47 var current = consent || readConsent() || buildConsent(false); 48 49 document.querySelectorAll('[data-cdp-cookies-category]').forEach(function(input) { 50 var category = input.getAttribute('data-cdp-cookies-category'); 51 52 if (!category || category === 'necessary') { 53 input.checked = true; 54 return; 55 } 56 57 input.checked = !!current[category]; 58 }); 59 } 60 61 function executeScripts(consent) { 62 var scripts = config.scripts || {}; 63 64 Object.keys(scripts).forEach(function(category) { 65 if (!consent[category] || !scripts[category] || scriptRuns[category]) { 66 return; 67 } 68 69 scriptRuns[category] = true; 70 executeHtml(scripts[category]); 71 }); 72 73 applyProtectedEmbeds(consent); 74 } 75 76 function executeHtml(html) { 77 var template = document.createElement('template'); 78 template.innerHTML = html; 79 80 appendFragmentWithExecutableScripts(document.body, template.content); 81 } 82 83 function appendFragmentWithExecutableScripts(parent, fragment) { 84 var token = 'cdp' + String(Date.now()) + String(Math.random()).replace(/\D/g, ''); 85 86 Array.prototype.slice.call(fragment.querySelectorAll('script')).forEach(function(script) { 87 script.setAttribute('data-cdp-cookies-script-token', token); 88 }); 89 90 parent.appendChild(fragment); 91 activateScripts(parent, token); 92 } 93 94 function activateScripts(root, token) { 95 var selector = token ? 'script[data-cdp-cookies-script-token="' + token + '"]' : 'script'; 96 97 Array.prototype.slice.call(root.querySelectorAll(selector)).forEach(function(oldScript) { 98 var newScript = document.createElement('script'); 99 100 Array.prototype.slice.call(oldScript.attributes).forEach(function(attribute) { 101 if (attribute.name !== 'data-cdp-cookies-script-token') { 102 newScript.setAttribute(attribute.name, attribute.value); 103 } 104 }); 105 106 newScript.text = oldScript.text || oldScript.textContent || ''; 107 oldScript.parentNode.replaceChild(newScript, oldScript); 108 }); 109 } 110 111 function showBanner() { 112 var banner = document.querySelector('[data-cdp-cookies-banner]'); 113 var preferences = document.querySelector('[data-cdp-cookies-open-preferences]'); 114 115 if (banner) { 116 banner.hidden = false; 117 } 118 119 if (preferences) { 120 preferences.hidden = true; 121 } 122 123 syncPanel(readConsent()); 124 } 125 126 function hideBanner() { 127 var banner = document.querySelector('[data-cdp-cookies-banner]'); 128 var preferences = document.querySelector('[data-cdp-cookies-open-preferences]'); 129 130 if (banner) { 131 banner.hidden = true; 132 } 133 134 if (preferences) { 135 preferences.hidden = false; 136 } 137 } 138 139 function reloadPage() { 140 window.location.reload(); 141 } 142 143 function openPanel() { 144 var panel = document.querySelector('[data-cdp-cookies-panel]'); 145 syncPanel(readConsent()); 146 147 if (panel) { 148 panel.hidden = false; 149 } 150 } 151 152 function closePanel() { 153 var panel = document.querySelector('[data-cdp-cookies-panel]'); 154 if (panel) { 155 panel.hidden = true; 156 } 157 } 158 159 function saveCustomConsent() { 160 var consent = buildConsent(false); 161 162 document.querySelectorAll('[data-cdp-cookies-category]').forEach(function(input) { 163 consent[input.getAttribute('data-cdp-cookies-category')] = input.checked; 164 }); 165 166 writeConsent(consent); 167 executeScripts(consent); 168 hideBanner(); 169 syncPanel(consent); 170 } 171 172 function applyProtectedEmbeds(consent) { 173 document.querySelectorAll('[data-cdp-consent-embed]').forEach(function(wrapper) { 174 var category = wrapper.getAttribute('data-cdp-consent-category'); 175 176 if (!category || !consent || !consent[category] || wrapper.getAttribute('data-cdp-consent-loaded') === '1') { 177 return; 178 } 179 180 var template = wrapper.querySelector('[data-cdp-consent-template]'); 181 var placeholder = wrapper.querySelector('[data-cdp-consent-placeholder]'); 182 183 if (!template) { 184 return; 185 } 186 187 var content = template.content.cloneNode(true); 188 189 if (placeholder) { 190 placeholder.remove(); 191 } 192 193 appendFragmentWithExecutableScripts(wrapper, content); 194 wrapper.setAttribute('data-cdp-consent-loaded', '1'); 195 }); 196 } 197 198 function acceptEmbedCategory(category) { 199 var consent = readConsent() || buildConsent(false); 200 consent.necessary = true; 201 consent[category] = true; 202 writeConsent(consent); 203 executeScripts(consent); 204 hideBanner(); 205 } 206 207 document.addEventListener('click', function(event) { 208 var embedButton = event.target.closest('[data-cdp-consent-embed-accept]'); 209 var preferencesLink = event.target.closest('a[href]'); 210 var opensPreferences = preferencesLink && 211 preferencesLink.hash === '#cdp-cookies-preferences' && 212 preferencesLink.origin === window.location.origin; 213 214 if (embedButton) { 215 acceptEmbedCategory(embedButton.getAttribute('data-cdp-consent-embed-accept')); 216 return; 217 } 218 219 if (event.target.closest('[data-cdp-cookies-accept-all]')) { 220 var accepted = buildConsent(true); 221 writeConsent(accepted); 222 executeScripts(accepted); 223 hideBanner(); 224 syncPanel(accepted); 225 return; 226 } 227 228 if (event.target.closest('[data-cdp-cookies-reject]')) { 229 var rejected = buildConsent(false); 230 writeConsent(rejected); 231 hideBanner(); 232 syncPanel(rejected); 233 reloadPage(); 234 return; 235 } 236 237 if (event.target.closest('[data-cdp-cookies-configure]') || event.target.closest('[data-cdp-cookies-open-preferences]') || opensPreferences) { 238 event.preventDefault(); 239 showBanner();
240 openPanel(); 241 return; 242 } 243 244 if (event.target.closest('[data-cdp-cookies-close]')) { 245 closePanel(); 246 return; 247 } 248 249 if (event.target.closest('[data-cdp-cookies-save]')) { 250 saveCustomConsent(); 251 } 252 }); 253 254 document.addEventListener('DOMContentLoaded', function() { 255 var consent = readConsent(); 256 257 if (consent) { 258 hideBanner(); 259 syncPanel(consent); 260 executeScripts(consent); 261 } else { 262 showBanner(); 263 } 264 265 if (window.location.hash === '#cdp-cookies-preferences') { 266 showBanner(); 267 openPanel(); 268 } 269 270 runAudit(); 271 }); 272 273 function runAudit() { 274 var audit = window.cdpCookiesAudit || {}; 275 276 if (!audit.enabled || !audit.ajaxUrl || !audit.nonce) { 277 return; 278 } 279 280 sendAuditSnapshot(); 281 282 if (window.MutationObserver) { 283 var timeout = null; 284 var observer = new MutationObserver(function() { 285 clearTimeout(timeout); 286 timeout = setTimeout(sendAuditSnapshot, 800); 287 }); 288 289 observer.observe(document.documentElement, { 290 childList: true, 291 subtree: true, 292 attributes: true, 293 attributeFilter: ['src', 'href', 'data', 'srcset'] 294 }); 295 } 296 297 setTimeout(sendAuditSnapshot, 2500); 298 } 299 300 function sendAuditSnapshot() { 301 var audit = window.cdpCookiesAudit || {}; 302 var declared = Array.isArray(audit.declaredNames) ? audit.declaredNames : []; 303 var names = getVisibleCookieNames(declared, audit.consentCookie); 304 var resources = getExternalResources(audit.siteHost); 305 var signature = JSON.stringify({ 306 cookies: names, 307 resources: resources.map(function(resource) { 308 return resource.url + '|' + resource.type; 309 }) 310 }); 311 var throttleKey = 'cdpCookiesAudit:' + location.pathname + ':' + signature; 312 313 try { 314 if (sessionStorage.getItem(throttleKey)) { 315 return; 316 } 317 sessionStorage.setItem(throttleKey, '1'); 318 } catch (error) {} 319 320 if (!names.length && !resources.length) { 321 return; 322 } 323 324 var body = new FormData(); 325 body.append('action', 'cdp_cookies_audit_detected'); 326 body.append('nonce', audit.nonce); 327 body.append('url', location.href); 328 names.forEach(function(name) { 329 body.append('cookie_names[]', name); 330 }); 331 resources.forEach(function(resource, index) { 332 body.append('external_resources[' + index + '][url]', resource.url); 333 body.append('external_resources[' + index + '][type]', resource.type); 334 }); 335 336 fetch(audit.ajaxUrl, { 337 method: 'POST', 338 credentials: 'same-origin', 339 body: body 340 }).catch(function() {}); 341 } 342 343 function getVisibleCookieNames(declared, consentCookie) { 344 if (!document.cookie) { 345 return []; 346 } 347 348 return document.cookie.split(';').map(function(part) { 349 return decodeURIComponent(part.split('=')[0].trim()); 350 }).filter(function(name, index, all) { 351 return name && all.indexOf(name) === index && declared.indexOf(name) === -1 && name !== consentCookie; 352 }); 353 } 354 355 function getExternalResources(siteHost) { 356 var resources = []; 357 var seen = {}; 358 359 function add(url, type) { 360 var absolute = normalizeResourceUrl(url); 361 var host = getUrlHost(absolute); 362 var key = absolute + '|' + type; 363 364 if (!absolute || !host || isSameHost(host, siteHost) || seen[key]) { 365 return; 366 } 367 368 seen[key] = true; 369 resources.push({ 370 url: absolute, 371 type: type || 'resource' 372 }); 373 } 374 375 document.querySelectorAll('script[src], iframe[src], img[src], link[href], embed[src], object[data], video[src], audio[src], source[src]').forEach(function(element) { 376 var url = element.getAttribute('src') || element.getAttribute('href') || element.getAttribute('data'); 377 add(url, element.tagName.toLowerCase()); 378 }); 379 380 if (window.performance && typeof window.performance.getEntriesByType === 'function') { 381 window.performance.getEntriesByType('resource').forEach(function(entry) { 382 add(entry.name, entry.initiatorType || 'resource'); 383 }); 384 } 385 386 return resources.slice(0, 150); 387 } 388 389 function normalizeResourceUrl(url) { 390 if (!url || typeof url !== 'string') { 391 return ''; 392 } 393 394 try { 395 return new URL(url, location.href).href; 396 } catch (error) { 397 return ''; 398 } 399 } 400 401 function getUrlHost(url) { 402 try { 403 return new URL(url).host.toLowerCase(); 404 } catch (error) { 405 return ''; 406 } 407 } 408 409 function isSameHost(host, siteHost) { 410 var currentHost = location.host.toLowerCase(); 411 var configuredHost = siteHost ? String(siteHost).toLowerCase() : currentHost; 412 413 return host === currentHost || host === configuredHost; 414 } 415})();
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.