fix(browser-extension): issue #703

This commit is contained in:
wanhose 2024-08-04 09:22:28 +02:00
parent aebb6b6b26
commit aee5fdfba4

View File

@ -320,19 +320,6 @@ function fix() {
} }
} }
/**
* @description Calculate reading time for the current page to avoid lags in large pages
* @returns {number}
*/
function readingTime() {
const text = document.body.innerText;
const wpm = 225;
const words = text.trim().split(/\s+/).length;
const time = Math.ceil(words / wpm);
return time;
}
/** /**
* @description Restore DOM to its previous state * @description Restore DOM to its previous state
* @returns {void} * @returns {void}
@ -468,12 +455,18 @@ window.addEventListener(triggerEventName, (event) => {
if (event.detail?.elements) { if (event.detail?.elements) {
clean(event.detail.elements, event.detail.skipMatch); clean(event.detail.elements, event.detail.skipMatch);
} else { } else {
if (readingTime() < 4) { // 2024-08-03: look into the first level of important nodes, there are dialogs there very often
forceClean(document.body); clean([
} else { ...document.body.children,
// 2023-06-13: look into the first level of the document body, there are dialogs there very often ...Array.from(document.getElementsByClassName('container')[0]?.children ?? []),
clean([...document.body.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 ?? []),
]);
} }
} }
}); });