feat(content): implement cache
This commit is contained in:
parent
d93e6a9351
commit
33c579d0c1
@ -19,22 +19,50 @@ if (!!window.chrome) {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
const remove = async () => {
|
const removeFromCache = () => {
|
||||||
const filtersUrl = chrome.runtime.getURL("filters/index.txt");
|
chrome.storage.sync.get([document.location.hostname], (value) => {
|
||||||
const text = await fetch(filtersUrl).then((res) => res.text());
|
const matches = value[document.location.hostname];
|
||||||
const filters = text.split("\n");
|
|
||||||
|
|
||||||
filters.forEach((match) => {
|
if (matches && !!matches.length) {
|
||||||
|
matches.forEach((match) => {
|
||||||
const element = document.querySelector(match);
|
const element = document.querySelector(match);
|
||||||
|
const tagName = element ? element.tagName.toUpperCase() : "";
|
||||||
|
|
||||||
if (element && element.tagName !== "BODY" && element.tagName !== "HTML") {
|
if (element && !["BODY", "HTML"].includes(tagName)) {
|
||||||
|
matches.push(match);
|
||||||
element.remove();
|
element.remove();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const saveToCache = (value) => {
|
||||||
|
chrome.storage.sync.set({ [document.location.hostname]: value });
|
||||||
|
};
|
||||||
|
|
||||||
|
const remove = async () => {
|
||||||
|
const filtersUrl = chrome.runtime.getURL("filters/index.txt");
|
||||||
|
const text = await fetch(filtersUrl).then((res) => res.text());
|
||||||
|
const filters = text.split("\n");
|
||||||
|
const matches = [];
|
||||||
|
|
||||||
|
filters.forEach((match) => {
|
||||||
|
const element = document.querySelector(match);
|
||||||
|
const tagName = element ? element.tagName.toUpperCase() : "";
|
||||||
|
|
||||||
|
if (element && !["BODY", "HTML"].includes(tagName)) {
|
||||||
|
matches.push(match);
|
||||||
|
element.remove();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
saveToCache(matches);
|
||||||
};
|
};
|
||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
fix();
|
fix();
|
||||||
|
removeFromCache();
|
||||||
await remove();
|
await remove();
|
||||||
observe();
|
observe();
|
||||||
})();
|
})();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user