const link = doc.createElement('link');
link.rel = 'stylesheet';
link.href = '/fly/fly/bundles/cbsnewscontent/css/cmp-banner.min.css?v=296763317a51cab90faa73f1bb146d5c';
doc.head.appendChild(link);
doc.body.innerHTML = CONSENT_MESSAGE;
} else {
el.insertAdjacentHTML('afterend', CONSENT_MESSAGE);
}
});
}
function hidePrivacyMessage() {
// Remove from the main document
document.querySelectorAll(`.${CONSENT_MESSAGE_CLASS}`).forEach(el => el.remove());
// Remove from inside any iframes
document.querySelectorAll('iframe').forEach(iframe => {
const doc = iframe.contentDocument || iframe.contentWindow.document;
doc.querySelectorAll(`.${CONSENT_MESSAGE_CLASS}`).forEach(el => el.remove());
});
}
function activateGatedScripts() {
// Handle both new format (cmp-gated-script) and old OneTrust/Ketch format (optanon-category-4)
const gatedScripts = Array.from(document.querySelectorAll('script.cmp-gated-script, script.optanon-category-4'));
// Activate scripts sequentially with a small delay to avoid timing issues
let delay = 0;
gatedScripts.forEach(function(placeholder, index) {
setTimeout(function() {
// Skip if already processed
if (placeholder.hasAttribute('data-cmp-processed')) {
return;
}
placeholder.setAttribute('data-cmp-processed', 'true');
const newScript = document.createElement('script');
newScript.type = 'text/javascript';
// Try new format first (data-cmp-src), then fall back to old format (data-src)
const src = placeholder.getAttribute('data-cmp-src') || placeholder.getAttribute('data-src');
if (src) {
newScript.src = src;
} else if (placeholder.textContent) {
// Inline script - just copy the content
newScript.textContent = placeholder.textContent;
}
// Handle new format attributes (data-cmp-attrs) - for both inline and external scripts
const attrs = placeholder.getAttribute('data-cmp-attrs');
if (attrs) {
const tempDiv = document.createElement('div');
tempDiv.innerHTML = '
<\/div>';
const tempAttrs = tempDiv.firstChild.attributes;
for (let i = 0; i < tempAttrs.length; i++) {
// For external scripts, allow defer/async. For inline scripts, skip them (not valid)
if (src || (tempAttrs[i].name !== 'async' && tempAttrs[i].name !== 'defer')) {
newScript.setAttribute(tempAttrs[i].name, tempAttrs[i].value);
}
}
}
// Copy other attributes from old OneTrust format
for (let i = 0; i < placeholder.attributes.length; i++) {
const attr = placeholder.attributes[i];
// Skip attributes we've already handled or don't want to copy
if (!['class', 'data-src', 'data-type', 'data-cmp-src', 'data-cmp-attrs', 'data-cmp-processed', 'type', 'async', 'defer', 'src'].includes(attr.name)) {
newScript.setAttribute(attr.name, attr.value);
}
}
placeholder.parentNode.replaceChild(newScript, placeholder);
// If external script, manually trigger window.onload handlers after it loads
// This handles widgets that use window.onload for initialization
if (src) {
newScript.addEventListener('load', function() {
// If page already loaded and script set a new onload handler, trigger it
if (document.readyState === 'complete' && window.onload) {
const originalOnload = window.onload;
window.onload = null; // Clear temporarily to prevent loops
originalOnload(); // Execute the handler
}
});
}
}, delay);
delay += 500; // 500ms delay between each script to allow full loading
});
}
cbsoptanon.onScriptsReady(function(cmp) {
cmp.ot.targetingAllowed(function(allowed) {
if (!allowed) {
showPrivacyMessage();
} else {
activateGatedScripts();
}
});
cmp.ot.awaitInitialConsent(function(consent_model) {
cmp.ot.addOnConsentChangedHandler(function() {
cmp.ot.targetingAllowed(function(allowed) {
if (allowed) {
hidePrivacyMessage();
activateGatedScripts();
} else {
showPrivacyMessage();
}
});
});
});
});