Merge pull request #746 from wanhose/v7.1.2

7.1.2
This commit is contained in:
wanhose 2024-08-10 13:07:09 +02:00 committed by GitHub
commit 0757bf24e8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 277 additions and 63 deletions

View File

@ -1,7 +1,7 @@
{ {
"manifest_version": 3, "manifest_version": 3,
"name": "Cookie Dialog Monster", "name": "Cookie Dialog Monster",
"version": "7.1.1", "version": "7.1.2",
"default_locale": "en", "default_locale": "en",
"description": "__MSG_appDesc__", "description": "__MSG_appDesc__",
"icons": { "icons": {

View File

@ -72,7 +72,7 @@
"stylesheet", "stylesheet",
"xmlhttprequest" "xmlhttprequest"
], ],
"urlFilter": "||cmp.inmobi.com^" "urlFilter": "||cdn.optable.co^"
} }
}, },
{ {
@ -91,7 +91,7 @@
"stylesheet", "stylesheet",
"xmlhttprequest" "xmlhttprequest"
], ],
"urlFilter": "||consent.trustarc.com^" "urlFilter": "||cdntranscend.eventbrite.com^"
} }
}, },
{ {
@ -110,7 +110,7 @@
"stylesheet", "stylesheet",
"xmlhttprequest" "xmlhttprequest"
], ],
"urlFilter": "||optanon.blob.core.windows.net^" "urlFilter": "||cmp.inmobi.com^"
} }
}, },
{ {
@ -119,6 +119,177 @@
"action": { "action": {
"type": "block" "type": "block"
}, },
"condition": {
"resourceTypes": [
"font",
"image",
"media",
"object",
"script",
"stylesheet",
"xmlhttprequest"
],
"urlFilter": "||consent.trustarc.com^"
}
},
{
"id": 8,
"priority": 1,
"action": {
"type": "block"
},
"condition": {
"resourceTypes": [
"font",
"image",
"media",
"object",
"script",
"stylesheet",
"xmlhttprequest"
],
"urlFilter": "||consent.cookiebot.com^"
}
},
{
"id": 10,
"priority": 1,
"action": {
"type": "block"
},
"condition": {
"resourceTypes": [
"font",
"image",
"media",
"object",
"script",
"stylesheet",
"xmlhttprequest"
],
"urlFilter": "||consentcdn.cookiebot.com^"
}
},
{
"id": 11,
"priority": 1,
"action": {
"type": "block"
},
"condition": {
"resourceTypes": [
"font",
"image",
"media",
"object",
"script",
"stylesheet",
"xmlhttprequest"
],
"urlFilter": "||cp.as.com^"
}
},
{
"id": 12,
"priority": 1,
"action": {
"type": "block"
},
"condition": {
"resourceTypes": [
"font",
"image",
"media",
"object",
"script",
"stylesheet",
"xmlhttprequest"
],
"urlFilter": "||eu.fastcmp.com^"
}
},
{
"id": 13,
"priority": 1,
"action": {
"type": "block"
},
"condition": {
"resourceTypes": [
"font",
"image",
"media",
"object",
"script",
"stylesheet",
"xmlhttprequest"
],
"urlFilter": "||lensois.com/wp-admin/admin-ajax.php"
}
},
{
"id": 14,
"priority": 1,
"action": {
"type": "block"
},
"condition": {
"resourceTypes": [
"font",
"image",
"media",
"object",
"script",
"stylesheet",
"xmlhttprequest"
],
"urlFilter": "||optanon.blob.core.windows.net^"
}
},
{
"id": 15,
"priority": 1,
"action": {
"type": "block"
},
"condition": {
"resourceTypes": [
"font",
"image",
"media",
"object",
"script",
"stylesheet",
"xmlhttprequest"
],
"urlFilter": "||redditstatic.com/onetrust.*.js"
}
},
{
"id": 16,
"priority": 1,
"action": {
"type": "block"
},
"condition": {
"resourceTypes": [
"font",
"image",
"media",
"object",
"script",
"stylesheet",
"xmlhttprequest"
],
"urlFilter": "||static.fastcmp.com^"
}
},
{
"id": 17,
"priority": 1,
"action": {
"type": "block"
},
"condition": { "condition": {
"resourceTypes": [ "resourceTypes": [
"font", "font",
@ -131,5 +302,24 @@
], ],
"urlFilter": "||wcpstatic.microsoft.com^" "urlFilter": "||wcpstatic.microsoft.com^"
} }
},
{
"id": 18,
"priority": 1,
"action": {
"type": "block"
},
"condition": {
"resourceTypes": [
"font",
"image",
"media",
"object",
"script",
"stylesheet",
"xmlhttprequest"
],
"urlFilter": "||webtools.europa.eu/js/webtools.cck.js^"
}
} }
] ]

View File

@ -16,7 +16,13 @@
/** /**
* @typedef {Object} RunParams * @typedef {Object} RunParams
* @property {boolean | undefined} skipTriggerEvent * @property {HTMLElement[] | undefined} elements
* @property {boolean | undefined} skipMatch
*/
/**
* @typedef {Object} SetUpParams
* @property {boolean | undefined} skipRunFn
*/ */
if (typeof browser === 'undefined') { if (typeof browser === 'undefined') {
@ -89,11 +95,6 @@ const seen = [];
*/ */
let state = { enabled: true }; let state = { enabled: true };
/**
* @description Event name to trigger the cleaning process
*/
const triggerEventName = 'cookie-dialog-monster';
/** /**
* @description Clean DOM * @description Clean DOM
* @param {Element[]} elements * @param {Element[]} elements
@ -140,13 +141,22 @@ function clean(elements, skipMatch) {
requestAnimationFrame(chunk); requestAnimationFrame(chunk);
} }
/**
* @description Check if element contains a common word
* @param {HTMLElement} element
*/
function containsCommonWord(element) {
return !!element.outerHTML.match(new RegExp(commonWords.join('|')));
}
/** /**
* @description Force a DOM clean in the specific element * @description Force a DOM clean in the specific element
* @param {HTMLElement} element * @param {HTMLElement} element
* @returns {void} * @returns {void}
*/ */
function forceClean(element) { function forceClean(element) {
const elements = [...element.querySelectorAll(tokens.selectors)]; const nodes = [...element.querySelectorAll(tokens.selectors)];
const elements = nodes.flatMap((node) => filterMapEarly(node));
if (elements.length) { if (elements.length) {
fix(); fix();
@ -262,15 +272,29 @@ function match(element, skipMatch) {
(skipMatch || element.matches(tokens.selectors)) (skipMatch || element.matches(tokens.selectors))
); );
} else { } else {
// 2023-06-10: fix edge case force cleaning on children if no attributes
if (commonWords && element.outerHTML.match(new RegExp(commonWords.join('|')))) {
forceClean(element); forceClean(element);
} }
}
return false; return false;
} }
/**
* @description Filter early nodes
* @param {Node} node
* @param {boolean} stopRecursion
*/
function filterMapEarly(node, stopRecursion) {
if (node.nodeType !== Node.ELEMENT_NODE || !(node instanceof HTMLElement)) {
return [];
}
if (commonWords && containsCommonWord(node) && !stopRecursion) {
return [node, ...[...node.children].flatMap((node) => filterMapEarly(node, true))];
}
return [node];
}
/** /**
* @description Fix data, middle consent page and scroll issues * @description Fix data, middle consent page and scroll issues
* @returns {void} * @returns {void}
@ -359,11 +383,43 @@ function restoreDOM() {
} }
/** /**
* @async * @description Clean DOM when this function is called
* @description Run the extension * @param {RunParams} params
* @param {RunParams | undefined} params * @returns {void}
*/ */
async function run(params) { function run(params = {}) {
if (document.body?.children.length && !preview && state.enabled && tokens?.selectors?.length) {
fix();
if (params.elements?.length) {
clean(params.elements, params.skipMatch);
}
if (params.elements === undefined) {
// 2024-08-03: look into the first level of important nodes, there are dialogs there very often
clean(
[
...document.body.children,
...[...(document.getElementsByClassName('container')[0]?.children ?? [])],
...[...(document.getElementsByClassName('layout')[0]?.children ?? [])],
...[...(document.getElementsByClassName('page')[0]?.children ?? [])],
...[...(document.getElementsByClassName('wrapper')[0]?.children ?? [])],
...[...(document.getElementById('__next')?.children ?? [])],
...[...(document.getElementById('app')?.children ?? [])],
...[...(document.getElementById('main')?.children ?? [])],
...[...(document.getElementById('root')?.children ?? [])],
].flatMap((node) => filterMapEarly(node))
);
}
}
}
/**
* @async
* @description Set up the extension
* @param {SetUpParams | undefined} params
*/
async function setUp(params) {
state = (await dispatch({ hostname, type: 'GET_HOSTNAME_STATE' })) ?? state; state = (await dispatch({ hostname, type: 'GET_HOSTNAME_STATE' })) ?? state;
dispatch({ type: 'ENABLE_POPUP' }); dispatch({ type: 'ENABLE_POPUP' });
@ -382,8 +438,8 @@ async function run(params) {
dispatch({ type: 'ENABLE_ICON' }); dispatch({ type: 'ENABLE_ICON' });
observer.observe(document.body ?? document.documentElement, options); observer.observe(document.body ?? document.documentElement, options);
if (!params?.skipTriggerEvent) { if (!params?.skipRunFn) {
window.dispatchEvent(new CustomEvent(triggerEventName)); run();
} }
} else { } else {
dispatch({ type: 'DISABLE_ICON' }); dispatch({ type: 'DISABLE_ICON' });
@ -400,9 +456,10 @@ const observer = new MutationObserver((mutations) => {
return; return;
} }
const elements = mutations.flatMap((mutation) => Array.from(mutation.addedNodes)); const nodes = mutations.flatMap((mutation) => [...mutation.addedNodes]);
const elements = nodes.flatMap((node) => filterMapEarly(node));
window.dispatchEvent(new CustomEvent(triggerEventName, { detail: { elements } })); run({ elements });
}); });
/** /**
@ -413,22 +470,17 @@ browser.runtime.onMessage.addListener(async (message) => {
switch (message.type) { switch (message.type) {
case 'RESTORE': { case 'RESTORE': {
restoreDOM(); restoreDOM();
await setUp({ skipRunFn: true });
break; break;
} }
case 'RUN': { case 'RUN': {
if (removables.length) { if (removables.length) {
window.dispatchEvent(new CustomEvent(triggerEventName), { await setUp({ skipRunFn: true });
detail: { run({ elements: removables, skipMatch: true });
elements: removables,
skipMatch: true,
},
});
} }
break; break;
} }
} }
await run({ skipTriggerEvent: message.type === 'RESTORE' });
}); });
/** /**
@ -439,7 +491,7 @@ browser.runtime.onMessage.addListener(async (message) => {
*/ */
window.addEventListener('DOMContentLoaded', async () => { window.addEventListener('DOMContentLoaded', async () => {
if (document.visibilityState === 'visible') { if (document.visibilityState === 'visible') {
await run(); await setUp();
} }
}); });
@ -450,36 +502,8 @@ window.addEventListener('DOMContentLoaded', async () => {
*/ */
window.addEventListener('pageshow', async (event) => { window.addEventListener('pageshow', async (event) => {
if (document.visibilityState === 'visible' && event.persisted) { if (document.visibilityState === 'visible' && event.persisted) {
await run(); await setUp();
window.dispatchEvent(new CustomEvent(triggerEventName)); run();
}
});
/**
* @description Force clean when this event is fired
* @listens window#cookie-dialog-monster
* @returns {void}
*/
window.addEventListener(triggerEventName, (event) => {
if (document.body?.children.length && !preview && state.enabled && tokens?.selectors?.length) {
fix();
if (event.detail?.elements) {
clean(event.detail.elements, event.detail.skipMatch);
} else {
// 2024-08-03: look into the first level of important nodes, there are dialogs there very often
clean([
...document.body.children,
...Array.from(document.getElementsByClassName('container')[0]?.children ?? []),
...Array.from(document.getElementsByClassName('layout')[0]?.children ?? []),
...Array.from(document.getElementsByClassName('page')[0]?.children ?? []),
...Array.from(document.getElementsByClassName('wrapper')[0]?.children ?? []),
...Array.from(document.getElementById('__next')?.children ?? []),
...Array.from(document.getElementById('app')?.children ?? []),
...Array.from(document.getElementById('main')?.children ?? []),
...Array.from(document.getElementById('root')?.children ?? []),
]);
}
} }
}); });
@ -492,6 +516,6 @@ window.addEventListener(triggerEventName, (event) => {
window.addEventListener('visibilitychange', async () => { window.addEventListener('visibilitychange', async () => {
if (document.visibilityState === 'visible' && !initiallyVisible) { if (document.visibilityState === 'visible' && !initiallyVisible) {
initiallyVisible = true; initiallyVisible = true;
await run(); await setUp();
} }
}); });