Merge pull request #250 from wanhose/v6.3.4

V6.3.4
This commit is contained in:
wanhose 2023-06-13 17:35:06 +02:00 committed by GitHub
commit b6eb3ef5fb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 37 additions and 38 deletions

View File

@ -1,7 +1,7 @@
{
"manifest_version": 3,
"name": "Cookie Dialog Monster",
"version": "6.3.3",
"version": "6.3.4",
"default_locale": "en",
"description": "__MSG_appDesc__",
"icons": {
@ -24,6 +24,7 @@
"*://*.googleapis.com/embed/*",
"*://*.sharepoint.com/*",
"*://*.youtube.com/embed/*",
"*://*.youtube-nocookie.com/embed/*",
"https://www.cookie-dialog-monster.com/*"
],
"js": ["scripts/content.js", "scripts/dialog.js"],

View File

@ -48,7 +48,7 @@
<span data-i18n="popup_helpOption"></span>
</popup-button>
<popup-button
data-href="https://www.github.com/wanhose/cookie-dialog-monster"
data-href="https://github.com/wanhose/cookie-dialog-monster"
id="contribute-option"
role="link"
tabindex="0"

View File

@ -56,27 +56,12 @@ function clean(elements, skipMatch) {
}
}
/**
* @description Flat child nodes for a given element
* @param {HTMLElement} element
* @returns {number[]}
*/
function flatElement(element) {
return [...element.childNodes].flatMap((childNode) =>
childNode.nodeType === Node.TEXT_NODE
? [childNode.nodeType]
: [...[...childNode.childNodes].map((x) => x.nodeType)]
);
}
/**
* @description Forces a DOM clean in the specific element
* @param {HTMLElement} element
*/
function forceClean(element) {
if (data?.elements.length && state.enabled && !preview) {
const elements = [...element.querySelectorAll(data.elements)];
if (elements.length) {
@ -84,7 +69,6 @@ function forceClean(element) {
clean(elements, true);
}
}
}
/**
* @description Forces element to have these styles
@ -132,10 +116,6 @@ function match(element, skipMatch) {
return false;
}
if (element.childNodes.length && flatElement(element).every((x) => x === Node.TEXT_NODE)) {
return false;
}
if (element.hasAttributes()) {
return (
// 2023-06-10: twitch.tv temporary fix
@ -233,14 +213,12 @@ const observer = new MutationObserver((mutations) => {
});
/**
* @description Fixes already existing element when page load issues
* @listens window#DOMContentLoaded
* @description Fixes still existing elements when page fully load
* @listens window#load
*/
window.addEventListener('DOMContentLoaded', () => {
if (readingTime() < 4) {
forceClean(document.body);
}
window.addEventListener('load', () => {
window.dispatchEvent(new Event('run'));
});
/**
@ -250,7 +228,23 @@ window.addEventListener('DOMContentLoaded', () => {
window.addEventListener('pageshow', (event) => {
if (event.persisted) {
window.dispatchEvent(new Event('run'));
}
});
/**
* @description Forces a clean when this event is fired
* @listens window#run
*/
window.addEventListener('run', () => {
if (data?.elements.length && state.enabled && !preview) {
if (readingTime() < 4) {
forceClean(document.body);
} else {
// 2023-06-13: look into the first level of the document body, there are dialogs there very often
clean([...document.body.children]);
}
}
});
@ -265,6 +259,12 @@ window.addEventListener('pageshow', (event) => {
if (state.enabled) {
data = await dispatch({ hostname, type: 'GET_DATA' });
// 2023-06-13: hack to force clean when data request takes too long and there are no changes later
if (document.readyState === 'complete') {
window.dispatchEvent(new Event('run'));
}
dispatch({ type: 'ENABLE_ICON' });
observer.observe(document.body ?? document.documentElement, options);
}

View File

@ -100,7 +100,7 @@
</a>
<a
class="contents"
href="https://www.github.com/wanhose/cookie-dialog-monster"
href="https://github.com/wanhose/cookie-dialog-monster"
target="_blank"
title="GitHub"
>
@ -313,7 +313,7 @@
<h3 class="font-medium mt-4 text-lg text-secondary">Open source</h3>
<p class="mt-2 text-gray-500">
Feel free to contribute to our
<a href="https://www.github.com/wanhose/cookie-dialog-monster/pulls" target="_blank">
<a href="https://github.com/wanhose/cookie-dialog-monster/pulls" target="_blank">
GitHub repository
</a>
</p>
@ -442,9 +442,7 @@
<div class="max-w-5xl mx-auto">
<p class="text-center text-white text-sm">
An open source project built by you and
<a class="hover:underline" href="https://www.github.com/wanhose" target="_blank">
wanhose
</a>
<a class="hover:underline" href="https://github.com/wanhose" target="_blank"> wanhose</a>
</p>
</div>
</footer>