diff --git a/docs/pull_request_template.md b/docs/pull_request_template.md index edd5a5f..fe8ddd2 100644 --- a/docs/pull_request_template.md +++ b/docs/pull_request_template.md @@ -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). \ No newline at end of file +- [ ] Google Chrome (specify version if checked). +- [ ] Microsoft Edge (specify version if checked). +- [ ] Opera (specify version if checked). diff --git a/src/filters/index.txt b/src/filters/index.txt index add5048..af0cb22 100644 --- a/src/filters/index.txt +++ b/src/filters/index.txt @@ -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 \ No newline at end of file +.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 \ No newline at end of file diff --git a/src/manifest.json b/src/manifest.json index 5a2f8b0..c59e65c 100644 --- a/src/manifest.json +++ b/src/manifest.json @@ -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"] } diff --git a/src/scripts/content.js b/src/scripts/content.js index 67446bd..87f2a2e 100644 --- a/src/scripts/content.js +++ b/src/scripts/content.js @@ -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(); }