feat(browser-extension): improve content script
This commit is contained in:
parent
9f993f5399
commit
fb85ac7865
@ -43,15 +43,25 @@ const preview = hostname.startsWith('consent.') || hostname.startsWith('myprivac
|
|||||||
* @returns {boolean}
|
* @returns {boolean}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const match = (node) =>
|
const match = (node) => {
|
||||||
node instanceof HTMLElement &&
|
if (!(node instanceof HTMLElement)) return false;
|
||||||
node.parentElement &&
|
|
||||||
!forbiddenTags.includes(node.tagName?.toUpperCase?.()) &&
|
const rect = node.getBoundingClientRect();
|
||||||
node.matches(data?.elements ?? []);
|
const isFullscreen = rect.bottom + rect.top > 0 && rect.bottom - rect.top === 0;
|
||||||
|
const isVisible = rect.top <= (window.innerHeight || document.documentElement.clientHeight);
|
||||||
|
|
||||||
|
return (
|
||||||
|
!forbiddenTags.includes(node.tagName?.toUpperCase?.()) &&
|
||||||
|
(isFullscreen || isVisible) &&
|
||||||
|
(node.offsetParent || window.getComputedStyle(node).position === 'fixed') &&
|
||||||
|
node.parentElement &&
|
||||||
|
node.matches(data?.elements ?? [])
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description Cleans DOM
|
* @description Cleans DOM
|
||||||
* @param {HTMLElement[]} nodes
|
* @param {Element[]} nodes
|
||||||
* @param {boolean?} skipMatch
|
* @param {boolean?} skipMatch
|
||||||
* @returns {void}
|
* @returns {void}
|
||||||
*/
|
*/
|
||||||
@ -126,7 +136,7 @@ const observer = new MutationObserver((mutations) => {
|
|||||||
|
|
||||||
window.addEventListener('pageshow', async (event) => {
|
window.addEventListener('pageshow', async (event) => {
|
||||||
if (event.persisted) {
|
if (event.persisted) {
|
||||||
const state = dispatch({ hostname, type: 'GET_STATE' });
|
const state = await dispatch({ hostname, type: 'GET_STATE' });
|
||||||
|
|
||||||
if (data?.elements?.length && state?.enabled && !preview) {
|
if (data?.elements?.length && state?.enabled && !preview) {
|
||||||
const nodes = [...document.querySelectorAll(data.elements)];
|
const nodes = [...document.querySelectorAll(data.elements)];
|
||||||
|
Loading…
Reference in New Issue
Block a user