refactor(browser-extension): move containers logic to database
This commit is contained in:
parent
d07df6cde2
commit
ab79baed41
@ -1502,6 +1502,18 @@
|
|||||||
"xh-scroll-disabled",
|
"xh-scroll-disabled",
|
||||||
"xh-thumb-disabled"
|
"xh-thumb-disabled"
|
||||||
],
|
],
|
||||||
|
"containers": [
|
||||||
|
".container",
|
||||||
|
".layout",
|
||||||
|
".page",
|
||||||
|
".wrapper",
|
||||||
|
"#__next",
|
||||||
|
"#a-page",
|
||||||
|
"#app",
|
||||||
|
"#main",
|
||||||
|
"#root",
|
||||||
|
"body > *"
|
||||||
|
],
|
||||||
"selectors": [
|
"selectors": [
|
||||||
".___eucookiePopup",
|
".___eucookiePopup",
|
||||||
".__cookie_policy",
|
".__cookie_policy",
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
* @property {string[]} commonWords
|
* @property {string[]} commonWords
|
||||||
* @property {Fix[]} fixes
|
* @property {Fix[]} fixes
|
||||||
* @property {{ domains: string[], tags: string[] }} skips
|
* @property {{ domains: string[], tags: string[] }} skips
|
||||||
* @property {{ backdrops: string[], classes: string[], selectors: string[] }} tokens
|
* @property {{ backdrops: string[], classes: string[], containers: string[], selectors: string[] }} tokens
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @typedef {Object} RunParams
|
* @typedef {Object} RunParams
|
||||||
|
* @property {HTMLElement[]} [containers]
|
||||||
* @property {HTMLElement[]} [elements]
|
* @property {HTMLElement[]} [elements]
|
||||||
* @property {boolean} [skipMatch]
|
* @property {boolean} [skipMatch]
|
||||||
*/
|
*/
|
||||||
@ -402,20 +403,11 @@ function run(params = {}) {
|
|||||||
clean(params.elements, params.skipMatch);
|
clean(params.elements, params.skipMatch);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (params.elements === undefined) {
|
if (params.elements === undefined && params.containers?.length) {
|
||||||
// 2024-08-03: look into the first level of important nodes, there are dialogs there very often
|
|
||||||
clean(
|
clean(
|
||||||
[
|
params.containers
|
||||||
...document.body.children,
|
.flatMap((container) => document.querySelector(container).children)
|
||||||
...[...(document.getElementsByClassName('container')[0]?.children ?? [])],
|
.flatMap((node) => filterNodeEarly(node))
|
||||||
...[...(document.getElementsByClassName('layout')[0]?.children ?? [])],
|
|
||||||
...[...(document.getElementsByClassName('page')[0]?.children ?? [])],
|
|
||||||
...[...(document.getElementsByClassName('wrapper')[0]?.children ?? [])],
|
|
||||||
...[...(document.getElementById('__next')?.children ?? [])],
|
|
||||||
...[...(document.getElementById('app')?.children ?? [])],
|
|
||||||
...[...(document.getElementById('main')?.children ?? [])],
|
|
||||||
...[...(document.getElementById('root')?.children ?? [])],
|
|
||||||
].flatMap((node) => filterNodeEarly(node))
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -446,7 +438,7 @@ async function setUp(params = {}) {
|
|||||||
observer.observe(document.body ?? document.documentElement, options);
|
observer.observe(document.body ?? document.documentElement, options);
|
||||||
|
|
||||||
if (!params.skipRunFn) {
|
if (!params.skipRunFn) {
|
||||||
run();
|
run({ containers: tokens.containers });
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
dispatch({ type: 'DISABLE_ICON' });
|
dispatch({ type: 'DISABLE_ICON' });
|
||||||
@ -482,7 +474,11 @@ browser.runtime.onMessage.addListener(async (message) => {
|
|||||||
}
|
}
|
||||||
case 'RUN': {
|
case 'RUN': {
|
||||||
await setUp({ skipRunFn: true });
|
await setUp({ skipRunFn: true });
|
||||||
run(removables.length ? { elements: removables, skipMatch: true } : {});
|
run(
|
||||||
|
removables.length
|
||||||
|
? { elements: removables, skipMatch: true }
|
||||||
|
: { containers: tokens.containers }
|
||||||
|
);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -508,7 +504,7 @@ window.addEventListener('DOMContentLoaded', async () => {
|
|||||||
window.addEventListener('pageshow', async (event) => {
|
window.addEventListener('pageshow', async (event) => {
|
||||||
if (document.visibilityState === 'visible' && event.persisted) {
|
if (document.visibilityState === 'visible' && event.persisted) {
|
||||||
await setUp();
|
await setUp();
|
||||||
run();
|
run({ containers: tokens.containers });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user