1(function (window, document) { 2 'use strict'; 3 4 var TCF_VERSION = 2; 5 6 var cwVendorServiceMap = [ 7 { id: '5e542b3a4cd8884eb41b5a72', name: 'Google_Analytics' }, 8 ]; 9 10 var cwConsentManager = { 11 hasConsent: function (serviceId, givenConsents) { 12 var consentMatches = givenConsents.filter(function (consent) { 13 return consent._id === serviceId; 14 }); 15 16 return consentMatches.length > 0; 17 }, 18 19 applyConsent: function (serviceName) { 20 console.log('[cwConsentManager] applyConsent ' + serviceName ); 21 var elements = document.querySelectorAll( 22 "[data-cw-consent-manager='" + serviceName + "']" 23 ); 24 25 elements.forEach(function (element) { 26 if (element.src) { 27 console.log('[cwConsentManager] forEach 1' + serviceName ); 28 methods.applyScriptFile(element); 29 } else { 30 console.log('[cwConsentManager] forEach 2' + serviceName ); 31 methods.applyScript(element); 32 } 33 }); 34 35 console.log('[cwConsentManager] Service ' + serviceName + ' applied!'); 36 }, 37 }; 38 39 var methods = { 40 applyScriptFile: function (element) { 41 var newElement = document.createElement('script'); 42 console.log('[cwConsentManager] forEach 1' + newElement ); 43 newElement.src = element.src; 44 if (element.onload) { 45 newElement.onload = element.onload; 46 } 47 console.log('[cwConsentManager] placeScript 1' + newElement ); 48 methods.placeScript(element, newElement); 49 }, 50 51 applyScript: function (element) { 52 var oldScript = element.innerHTML; 53 var newElement = document.createElement('script'); 54 console.log('[cwConsentManager] forEach 2' + newElement ); 55 newElement.innerHTML = oldScript; 56 console.log('[cwConsentManager] placeScript 2' + newElement ); 57 methods.placeScript(element, newElement); 58 }, 59 60 placeScript: function (oldElement, newElement) { 61 console.log('[cwConsentManager] placeScript 3' + oldElement + newElement ); 62 oldElement.parentNode.insertBefore(newElement, oldElement.nextSibling); 63 oldElement.parentNode.removeChild(oldElement); 64 }, 65 }; 66 67 window.addEventListener('spconsent', function () { 68 if (typeof __tcfapi === undefined) { 69 return; 70 } 71 72 __tcfapi('getCustomVendorConsents', TCF_VERSION, function (data, success) { 73 if (success) { 74 cwVendorServiceMap.forEach(function (service) { 75 if (cwConsentManager.hasConsent(service.id, data.consentedVendors)) { 76 cwConsentManager.applyConsent(service.name); 77 } 78 }); 79 } 80 }); 81 }); 82})(window, document);
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.