feat(browser-extension): some performance improvements avoiding duplicate checks and fake dialogs
This commit is contained in:
parent
f84b2ab31f
commit
415c36386e
@ -26,6 +26,12 @@ const options = { childList: true, subtree: true };
|
|||||||
*/
|
*/
|
||||||
const preview = hostname.startsWith('consent.') || hostname.startsWith('myprivacy.');
|
const preview = hostname.startsWith('consent.') || hostname.startsWith('myprivacy.');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description Elements that were already seen
|
||||||
|
* @type {HTMLElement[]}
|
||||||
|
*/
|
||||||
|
const seen = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description Extension state
|
* @description Extension state
|
||||||
* @type {{ enabled: boolean }}
|
* @type {{ enabled: boolean }}
|
||||||
@ -117,16 +123,29 @@ function match(element, skipMatch) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!data?.tags?.length || data.tags.includes(element.tagName?.toUpperCase?.())) {
|
const tagName = element.tagName?.toUpperCase?.();
|
||||||
|
|
||||||
|
if (!data?.tags?.length || data.tags.includes(tagName)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (seen.includes(element)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
seen.push(element);
|
||||||
|
|
||||||
if (element.hasAttributes()) {
|
if (element.hasAttributes()) {
|
||||||
|
// 2023-06-10: twitch.tv temporary fix
|
||||||
|
if (element.classList.contains('chat-line__message')) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
const isDialog = tagName === 'DIALOG' && element.getAttribute('open') === 'true';
|
||||||
|
const isFakeDialog = tagName === 'DIV' && element.className.includes('cmp');
|
||||||
|
|
||||||
return (
|
return (
|
||||||
// 2023-06-10: twitch.tv temporary fix
|
(isDialog || isFakeDialog || isInViewport(element)) &&
|
||||||
!element.classList.contains('chat-line__message') &&
|
|
||||||
// ...
|
|
||||||
isInViewport(element) &&
|
|
||||||
(skipMatch || element.matches(data?.elements ?? []))
|
(skipMatch || element.matches(data?.elements ?? []))
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
@ -226,7 +245,7 @@ async function runSetup(skipReadyStateHack) {
|
|||||||
* @type {MutationObserver}
|
* @type {MutationObserver}
|
||||||
*/
|
*/
|
||||||
const observer = new MutationObserver((mutations) => {
|
const observer = new MutationObserver((mutations) => {
|
||||||
const elements = mutations.map((mutation) => Array.from(mutation.addedNodes)).flat();
|
const elements = mutations.map((mutation) => Array.from(mutation.addedNodes)).flat(1);
|
||||||
|
|
||||||
fix();
|
fix();
|
||||||
if (data?.elements.length && !preview) clean(elements);
|
if (data?.elements.length && !preview) clean(elements);
|
||||||
|
Loading…
Reference in New Issue
Block a user