File size: 2,192 Bytes
3d7d9b5 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | (function() {
'use strict';
const rejectSelectors = [
'[id*="reject"]', '[class*="reject"]',
'[id*="decline"]', '[class*="decline"]',
'button[aria-label*="Reject"]', 'button[aria-label*="reject"]',
'#onetrust-reject-all-handler',
'.js-cookie-decline',
'[data-testid="cookie-policy-dialog-reject-button"]',
'[class*="cookie"] [class*="reject"]',
'[class*="consent"] [class*="reject"]',
'[id*="consent"] button[class*="secondary"]',
'.fc-cta-do-not-consent',
'#CybotCookiebotDialogBodyButtonDecline',
'[class*="CookieConsent"] button:last-child',
];
const bannerSelectors = [
'[class*="cookie-banner"]', '[class*="cookie-notice"]',
'[class*="consent-banner"]', '[class*="consent-modal"]',
'[id*="cookie-banner"]', '[id*="cookie-notice"]',
'#onetrust-banner-sdk', '.fc-consent-root',
'#CybotCookiebotDialog', '[class*="CookieConsent"]',
'[class*="gdpr"]', '[id*="gdpr"]',
];
function clickReject() {
for (const selector of rejectSelectors) {
const btn = document.querySelector(selector);
if (btn && btn.offsetParent !== null) {
btn.click();
return true;
}
}
return false;
}
function hideBanners() {
for (const selector of bannerSelectors) {
const el = document.querySelector(selector);
if (el && el.offsetParent !== null) {
el.style.display = 'none';
}
}
}
function attempt() {
if (clickReject()) return true;
hideBanners();
return false;
}
// Try immediately
if (!attempt()) {
// Watch for dynamically added consent banners
const obs = new MutationObserver(() => {
if (attempt()) obs.disconnect();
});
if (document.body) {
obs.observe(document.body, { childList: true, subtree: true });
} else {
document.addEventListener('DOMContentLoaded', () => {
if (!attempt()) {
obs.observe(document.body, { childList: true, subtree: true });
}
});
}
// Safety timeout
setTimeout(() => { attempt(); obs.disconnect(); }, 8000);
}
})();
|