Merge pull request #2 from wanhose/cache

Cache
This commit is contained in:
wanhose 2021-01-27 23:54:33 +01:00 committed by GitHub
commit ace0a2b64f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 105 additions and 36 deletions

View File

@ -4,6 +4,6 @@ Give a short description about this pull request.
## Browsers
[ ] Google Chrome (specify version if checked).
[ ] Microsoft Edge (specify version if checked).
[ ] Opera (specify version if checked).
- [ ] Google Chrome (specify version if checked).
- [ ] Microsoft Edge (specify version if checked).
- [ ] Opera (specify version if checked).

View File

@ -1758,7 +1758,6 @@ tui-cookie-consent
#privacy-shield
.kjfCookieInfoBox
#policy-cookie-notice
.ui-dialog
div[style^="color: rgb(238, 238, 238); background-color: rgb(102, 102, 51);"]
#accept_cookie
.global-alert--cookie-notice
@ -2334,7 +2333,6 @@ suchen-cookie-privacy-toast
#private-policy
#bt-privacy-header
#consent-toolbar
.info.popup-content
.disclaimermessage
.datenschutzhinweis
#global-cookiewarning
@ -4024,7 +4022,6 @@ cru-cookie-policy
.cookiemanager
.cookie__container
#CNIL-cookie
.popup-content
#noteOnCookies
.cookieClass
#cookieAgree
@ -4745,7 +4742,6 @@ div[data-cmp-no-consent]
.cookies__layover
[cookie-unique-name]
#rodoNotificationWrapper
#colorbox
.wp-gdpr-cookie-notice-wrap
#y-shade
.cookie_gdpr
@ -12551,4 +12547,18 @@ div[style="position: fixed; z-index: 9999; width: 100%; height: 100%; inset: 0px
.w-cookies-popup__wrapper
.w-cookies-popup
#CybotCookiebotDialogBodyUnderlay
.tvcmscookies-notice
.tvcmscookies-notice
.ui-widget-overlay.ui-front
#policy-wrapper
div[id*="sp_message_container_"]
iframe[src="/legal/acuerdo_cookies.html"]
#popup[data-component="ePopup"]
#popupp[style="visibility: visible;"]
div[data-tracking-opt-in-overlay="true"][style="z-index: 9999999;"]
#cookie-compliant-conte
#idxrcookies
#cookieLoad
.cookieAcceptDiv
.fondo-popup-cookies
#cookie-consent-iframe
#cookies-caja

View File

@ -1,7 +1,7 @@
{
"manifest_version": 2,
"name": "Do Not Consent",
"version": "3.0.3",
"version": "3.1.0",
"default_locale": "en",
"description": "__MSG_appDesc__",
"icons": {
@ -21,5 +21,6 @@
"matches": ["http://*/*", "https://*/*"]
}
],
"permissions": ["storage", "unlimitedStorage"],
"web_accessible_resources": ["filters/index.txt"]
}

View File

@ -1,41 +1,99 @@
if (!!window.chrome) {
let attempts = 0;
const filtersUrl = chrome.runtime.getURL("filters/index.txt");
const options = {
attributes: true,
childList: true,
};
const fix = () => {
document.body.style = "overflow-y: unset !important;";
};
const observe = () => {
observer.observe(document.body, {
attributes: true,
childList: true,
});
const retrieveElement = (match) => {
if (!match.includes("[") && !match.includes(">")) {
if (match[0] === ".") {
return document.getElementsByClassName(match.slice(1))[0];
}
if (match[0] === "#") {
return document.getElementById(match.slice(1));
}
} else {
return document.querySelector(match);
}
return null;
};
const observer = new MutationObserver((mutations, observer) => {
mutations.forEach(async () => {
observer.disconnect();
fix();
await remove();
observe();
});
});
const removeFromCache = () => {
chrome.storage.local.get([document.location.hostname], (value) => {
const matches = value[document.location.hostname];
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");
if (matches && !!matches.length) {
matches.forEach((match) => {
const element = retrieveElement(match);
const tagName = element ? element.tagName.toUpperCase() : "";
filters.forEach((match) => {
const element = document.querySelector(match);
if (element && element.tagName !== "BODY" && element.tagName !== "HTML") {
element.remove();
if (element && !["BODY", "HTML"].includes(tagName)) {
matches.push(match);
element.remove();
}
});
}
});
};
(async () => {
fix();
await remove();
observe();
})();
const updateCache = (value) => {
chrome.storage.local.get([document.location.hostname], (store) => {
const matches = store[document.location.hostname];
if (matches && !!matches.length && !matches.includes(value)) {
chrome.storage.local.set({
[document.location.hostname]: [...new Set([...matches, value])],
});
} else {
chrome.storage.local.set({
[document.location.hostname]: [value],
});
}
});
};
const removeFromFilters = async () => {
if (attempts < 3) {
const text = await fetch(filtersUrl).then((res) => res.text());
const filters = text.split("\n");
filters.forEach((match) => {
const element = retrieveElement(match);
const tagName = element ? element.tagName.toUpperCase() : "";
if (element && !["BODY", "HTML"].includes(tagName)) {
updateCache(match);
element.remove();
}
});
}
};
const observer = new MutationObserver((mutations, observer) => {
mutations.forEach(() => {
observer.disconnect();
fix();
removeFromCache();
removeFromFilters();
attempts += 1;
observer.observe(document.body, options);
});
});
const observe = () => {
observer.observe(document.body, options);
};
fix();
removeFromCache();
removeFromFilters();
observe();
}