feat(content): improve performance
This commit is contained in:
parent
ace0a2b64f
commit
3b3c173a62
@ -1,6 +1,6 @@
|
|||||||
if (!!window.chrome) {
|
if (!!window.chrome) {
|
||||||
let attempts = 0;
|
let attempts = 0;
|
||||||
const filtersUrl = chrome.runtime.getURL("filters/index.txt");
|
let filters = [];
|
||||||
const options = {
|
const options = {
|
||||||
attributes: true,
|
attributes: true,
|
||||||
childList: true,
|
childList: true,
|
||||||
@ -36,7 +36,6 @@ if (!!window.chrome) {
|
|||||||
const tagName = element ? element.tagName.toUpperCase() : "";
|
const tagName = element ? element.tagName.toUpperCase() : "";
|
||||||
|
|
||||||
if (element && !["BODY", "HTML"].includes(tagName)) {
|
if (element && !["BODY", "HTML"].includes(tagName)) {
|
||||||
matches.push(match);
|
|
||||||
element.remove();
|
element.remove();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -48,10 +47,12 @@ if (!!window.chrome) {
|
|||||||
chrome.storage.local.get([document.location.hostname], (store) => {
|
chrome.storage.local.get([document.location.hostname], (store) => {
|
||||||
const matches = store[document.location.hostname];
|
const matches = store[document.location.hostname];
|
||||||
|
|
||||||
if (matches && !!matches.length && !matches.includes(value)) {
|
if (!!matches) {
|
||||||
chrome.storage.local.set({
|
if (!matches.includes(value)) {
|
||||||
[document.location.hostname]: [...new Set([...matches, value])],
|
chrome.storage.local.set({
|
||||||
});
|
[document.location.hostname]: [...new Set([...matches, value])],
|
||||||
|
});
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
chrome.storage.local.set({
|
chrome.storage.local.set({
|
||||||
[document.location.hostname]: [value],
|
[document.location.hostname]: [value],
|
||||||
@ -60,11 +61,8 @@ if (!!window.chrome) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const removeFromFilters = async () => {
|
const removeFromFilters = () => {
|
||||||
if (attempts < 3) {
|
if (attempts < 3) {
|
||||||
const text = await fetch(filtersUrl).then((res) => res.text());
|
|
||||||
const filters = text.split("\n");
|
|
||||||
|
|
||||||
filters.forEach((match) => {
|
filters.forEach((match) => {
|
||||||
const element = retrieveElement(match);
|
const element = retrieveElement(match);
|
||||||
const tagName = element ? element.tagName.toUpperCase() : "";
|
const tagName = element ? element.tagName.toUpperCase() : "";
|
||||||
@ -92,8 +90,14 @@ if (!!window.chrome) {
|
|||||||
observer.observe(document.body, options);
|
observer.observe(document.body, options);
|
||||||
};
|
};
|
||||||
|
|
||||||
fix();
|
(async () => {
|
||||||
removeFromCache();
|
const url = chrome.runtime.getURL("filters/index.txt");
|
||||||
removeFromFilters();
|
const db = await fetch(url).then((res) => res.text());
|
||||||
observe();
|
filters = db.split("\n");
|
||||||
|
|
||||||
|
fix();
|
||||||
|
removeFromCache();
|
||||||
|
removeFromFilters();
|
||||||
|
observe();
|
||||||
|
})();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user