fix(browser-extension): skip match already matched
This commit is contained in:
parent
51bd0e6717
commit
1463f9bafe
@ -61,23 +61,26 @@ const target = document.body || document.documentElement;
|
|||||||
/**
|
/**
|
||||||
* @description Checks if node element is removable
|
* @description Checks if node element is removable
|
||||||
* @param {any} node
|
* @param {any} node
|
||||||
|
* @param {boolean} skipMatch
|
||||||
* @returns {boolean}
|
* @returns {boolean}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const check = (node) =>
|
const check = (node, skipMatch) =>
|
||||||
node instanceof HTMLElement &&
|
node instanceof HTMLElement &&
|
||||||
node.parentElement &&
|
node.parentElement &&
|
||||||
!['BODY', 'HTML'].includes(node.tagName) &&
|
!['BODY', 'HTML'].includes(node.tagName) &&
|
||||||
!(node.id && ['APP', 'ROOT'].includes(node.id.toUpperCase?.())) &&
|
!(node.id && ['APP', 'ROOT'].includes(node.id.toUpperCase?.())) &&
|
||||||
node.matches(selectors);
|
(skipMatch || node.matches(selectors));
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description Cleans DOM
|
* @description Cleans DOM
|
||||||
* @param {HTMLElement[]} nodes
|
* @param {HTMLElement[]} nodes
|
||||||
|
* @param {boolean} skipMatch
|
||||||
* @returns {void}
|
* @returns {void}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const clean = (nodes) => nodes.filter(check).forEach((node) => (node.outerHTML = ''));
|
const clean = (nodes, skipMatch) =>
|
||||||
|
nodes.filter((node) => check(node, skipMatch)).forEach((node) => (node.outerHTML = ''));
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description Fixes scroll issues
|
* @description Fixes scroll issues
|
||||||
@ -149,8 +152,8 @@ document.addEventListener('readystatechange', () => {
|
|||||||
const nodes = selectors.length ? Array.from(document.querySelectorAll(selectors)) : [];
|
const nodes = selectors.length ? Array.from(document.querySelectorAll(selectors)) : [];
|
||||||
|
|
||||||
fix();
|
fix();
|
||||||
clean(nodes);
|
clean(nodes, true);
|
||||||
setTimeout(() => clean(nodes), 2000);
|
setTimeout(() => clean(nodes, true), 2000);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user