Merge pull request #55 from wanhose/v6.0.3

6.0.3
This commit is contained in:
wanhose 2022-08-17 23:24:00 +02:00 committed by GitHub
commit 405e075dde
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 51 additions and 18 deletions

View File

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

View File

@ -31,6 +31,13 @@ const options = { childList: true, subtree: true };
const preview = hostname.startsWith('consent.') || hostname.startsWith('myprivacy.'); const preview = hostname.startsWith('consent.') || hostname.startsWith('myprivacy.');
/**
* @description Element that were being removed count
* @type {number}
*/
let elementCount = 0;
/** /**
* @description Extension state * @description Extension state
* @type {{ enabled: boolean }} * @type {{ enabled: boolean }}
@ -38,6 +45,39 @@ const preview = hostname.startsWith('consent.') || hostname.startsWith('myprivac
let state = { enabled: true }; let state = { enabled: true };
/**
* @description Cleans DOM
* @param {Element[]} nodes
* @param {boolean?} skipMatch
* @returns {void}
*/
const clean = (nodes, skipMatch) => {
const targets = nodes.filter((node) => skipMatch || match(node));
targets.forEach((node) => {
node.remove();
elementCount += 1;
});
};
/**
* @description Cleans DOM
* @returns {void}
*/
const forceClean = () => {
if (data?.elements.length && state.enabled && !preview) {
const nodes = [...document.querySelectorAll(data.elements)];
if (nodes.length) {
fix();
clean(nodes, true);
elementCount += nodes.length;
}
}
};
/** /**
* @description Matches if node element is removable * @description Matches if node element is removable
* @param {Element} node * @param {Element} node
@ -60,16 +100,6 @@ const match = (node) => {
); );
}; };
/**
* @description Cleans DOM
* @param {Element[]} nodes
* @param {boolean?} skipMatch
* @returns {void}
*/
const clean = (nodes, skipMatch) =>
nodes.filter((node) => skipMatch || match(node)).forEach((node) => node.remove());
/** /**
* @description Fixes scroll issues * @description Fixes scroll issues
*/ */
@ -130,18 +160,21 @@ const observer = new MutationObserver((mutations) => {
}); });
/** /**
* @async * @description Fixes already existing element when page load issues
* @listens window#load
*/
window.addEventListener('load', () => {
if (elementCount < 2) forceClean();
});
/**
* @description Fixes bfcache issues * @description Fixes bfcache issues
* @listens window#pageshow * @listens window#pageshow
*/ */
window.addEventListener('pageshow', (event) => { window.addEventListener('pageshow', (event) => {
if (data?.elements.length && event.persisted && state.enabled && !preview) { if (event.persisted) forceClean();
const nodes = [...document.querySelectorAll(data.elements)];
fix();
if (nodes.length) clean(nodes, true);
}
}); });
/** /**