(() => { const blockedMarker = 'data-im-overlay-blocked'; const ownSurfaceIds = new Set([ 'im-cookie-banner', 'im-cookie-settings-modal', 'im-cookie-settings-launcher', ]); const knownExternalSelectors = [ '#ccm', '.ccm-root', '.ccm-widget', '#cookie-consent', '.cookie-consent', '.cookie-banner', '.cookie-notice', '#cookieNotice', '.eu-cookie-compliance-banner', ]; const normalize = (value) => String(value || '').replace(/\s+/g, ' ').trim().toLowerCase(); const looksLikeExternalCookieOverlay = (text) => { const normalized = normalize(text); if (normalized === '') { return false; } const hasCookieLanguage = normalized.includes('we use cookies') || normalized.includes('cookie settings') || normalized.includes('cookie policy'); if (!hasCookieLanguage) { return false; } const hasAgree = normalized.includes('agree'); const hasSettings = normalized.includes('cookie settings'); const hasPolicyFooter = normalized.includes('imprint') || normalized.includes('privacy policy'); const hasConsentWords = normalized.includes('consent') || normalized.includes('allow'); return (hasAgree && (hasSettings || hasPolicyFooter)) || (hasConsentWords && hasSettings); }; const elementArea = (node) => { if (!(node instanceof HTMLElement)) { return 0; } const rect = node.getBoundingClientRect(); return Math.max(0, rect.width) * Math.max(0, rect.height); }; const isViewportOverlay = (node, keywordMatch = false) => { if (!(node instanceof HTMLElement)) { return false; } if (ownSurfaceIds.has(node.id)) { return false; } const style = window.getComputedStyle(node); if (style.display === 'none' || style.visibility === 'hidden') { return false; } const position = style.position; if (!['fixed', 'absolute', 'sticky'].includes(position)) { return false; } const viewportArea = Math.max(window.innerWidth * window.innerHeight, 1); const coverage = elementArea(node) / viewportArea; const zIndex = Number.parseInt(style.zIndex || '0', 10); return coverage >= 0.25 || zIndex >= 900 || (keywordMatch && (coverage >= 0.1 || zIndex >= 100)); }; const markHidden = (node) => { if (!(node instanceof HTMLElement)) { return; } if (node.getAttribute(blockedMarker) === '1') { return; } node.setAttribute(blockedMarker, '1'); node.style.setProperty('display', 'none', 'important'); node.style.setProperty('visibility', 'hidden', 'important'); node.style.setProperty('pointer-events', 'none', 'important'); node.setAttribute('aria-hidden', 'true'); }; const findOverlayRoot = (node) => { if (!(node instanceof HTMLElement)) { return null; } let candidate = node; while (candidate.parentElement instanceof HTMLElement) { const keywordMatch = looksLikeExternalCookieOverlay(candidate.textContent || ''); if (isViewportOverlay(candidate, keywordMatch)) { return candidate; } candidate = candidate.parentElement; if (candidate === document.body || candidate === document.documentElement) { break; } } const keywordMatch = looksLikeExternalCookieOverlay(node.textContent || ''); return isViewportOverlay(node, keywordMatch) ? node : null; }; const unblockScroll = () => { if (document.body instanceof HTMLElement) { document.body.style.removeProperty('overflow'); document.body.style.removeProperty('position'); document.body.style.removeProperty('height'); } document.documentElement.style.removeProperty('overflow'); }; const runGuard = () => { const nodes = document.querySelectorAll('div, section, aside, dialog'); let removed = 0; knownExternalSelectors.forEach((selector) => { document.querySelectorAll(selector).forEach((node) => { if (!(node instanceof HTMLElement)) { return; } if (ownSurfaceIds.has(node.id)) { return; } const root = findOverlayRoot(node) ?? node; markHidden(root); removed += 1; }); }); nodes.forEach((node) => { if (!(node instanceof HTMLElement)) { return; } if (node.id && ownSurfaceIds.has(node.id)) { return; } if (!looksLikeExternalCookieOverlay(node.textContent || '')) { return; } const root = findOverlayRoot(node) ?? node; if (root instanceof HTMLElement && !ownSurfaceIds.has(root.id)) { markHidden(root); removed += 1; } }); document.querySelectorAll('iframe').forEach((frame) => { if (!(frame instanceof HTMLIFrameElement)) { return; } const src = normalize(frame.src || ''); const title = normalize(frame.title || ''); const marker = `${src} ${title}`; const cookieHint = marker.includes('cookie') || marker.includes('consent') || marker.includes('privacy'); if (!cookieHint) { return; } const root = findOverlayRoot(frame) ?? frame.parentElement; if (root instanceof HTMLElement && !ownSurfaceIds.has(root.id)) { markHidden(root); removed += 1; } }); if (removed > 0) { unblockScroll(); } }; let scheduled = false; const scheduleGuard = () => { if (scheduled) { return; } scheduled = true; window.requestAnimationFrame(() => { scheduled = false; runGuard(); }); }; if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', scheduleGuard, { once: true }); } else { scheduleGuard(); } window.addEventListener('load', scheduleGuard); const observer = new MutationObserver(scheduleGuard); observer.observe(document.documentElement, { childList: true, subtree: true, }); })();