From d93e6a9351c575dc276bfecf6994e21ae58d08c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Jose=CC=81=20Vi=CC=81lchez?= Date: Wed, 27 Jan 2021 20:27:57 +0100 Subject: [PATCH 1/5] feat(filters): increase support --- src/filters/index.txt | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) 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 From 33c579d0c1f13be86d80a98a4d2787d9e9722862 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Jose=CC=81=20Vi=CC=81lchez?= Date: Wed, 27 Jan 2021 20:28:31 +0100 Subject: [PATCH 2/5] feat(content): implement cache --- src/scripts/content.js | 44 ++++++++++++++++++++++++++++++++++-------- 1 file changed, 36 insertions(+), 8 deletions(-) diff --git a/src/scripts/content.js b/src/scripts/content.js index 67446bd..1975c1f 100644 --- a/src/scripts/content.js +++ b/src/scripts/content.js @@ -19,22 +19,50 @@ if (!!window.chrome) { }); }); - 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 removeFromCache = () => { + chrome.storage.sync.get([document.location.hostname], (value) => { + const matches = value[document.location.hostname]; - filters.forEach((match) => { - const element = document.querySelector(match); + if (matches && !!matches.length) { + matches.forEach((match) => { + const element = document.querySelector(match); + const tagName = element ? element.tagName.toUpperCase() : ""; - if (element && element.tagName !== "BODY" && element.tagName !== "HTML") { - element.remove(); + if (element && !["BODY", "HTML"].includes(tagName)) { + matches.push(match); + 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 () => { fix(); + removeFromCache(); await remove(); observe(); })(); From 607a73a589856f355c9500dd2488ed5e470fe101 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Jose=CC=81=20Vi=CC=81lchez?= Date: Wed, 27 Jan 2021 20:28:49 +0100 Subject: [PATCH 3/5] feat(manifest): update permissions and update version --- src/manifest.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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"] } From c84762c259e8df183a6fd13927928d74c9ea2459 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Jose=CC=81=20Vi=CC=81lchez?= Date: Wed, 27 Jan 2021 21:53:57 +0100 Subject: [PATCH 4/5] fix(content): use local storage instead of sync storage and performance improvements --- src/scripts/content.js | 110 ++++++++++++++++++++++++++--------------- 1 file changed, 70 insertions(+), 40 deletions(-) diff --git a/src/scripts/content.js b/src/scripts/content.js index 1975c1f..87f2a2e 100644 --- a/src/scripts/content.js +++ b/src/scripts/content.js @@ -1,31 +1,38 @@ 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.sync.get([document.location.hostname], (value) => { + chrome.storage.local.get([document.location.hostname], (value) => { const matches = value[document.location.hostname]; if (matches && !!matches.length) { matches.forEach((match) => { - const element = document.querySelector(match); + const element = retrieveElement(match); const tagName = element ? element.tagName.toUpperCase() : ""; if (element && !["BODY", "HTML"].includes(tagName)) { @@ -37,33 +44,56 @@ if (!!window.chrome) { }); }; - const saveToCache = (value) => { - chrome.storage.sync.set({ [document.location.hostname]: value }); - }; + const updateCache = (value) => { + chrome.storage.local.get([document.location.hostname], (store) => { + const matches = store[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"); - 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(); + 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], + }); } }); - - saveToCache(matches); }; - (async () => { - fix(); - removeFromCache(); - await remove(); - observe(); - })(); + 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(); } From 2fc972dc71bdacc6be6c4d62b41da1b76f08da53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Jose=CC=81=20Vi=CC=81lchez?= Date: Wed, 27 Jan 2021 23:53:31 +0100 Subject: [PATCH 5/5] docs: fix pr template --- docs/pull_request_template.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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).