From 32ca193b9cb58d46cffa361c97add02040579375 Mon Sep 17 00:00:00 2001 From: wanhose Date: Thu, 1 Jul 2021 14:56:47 +0200 Subject: [PATCH 1/5] feat(data): update elements --- data/elements.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/data/elements.txt b/data/elements.txt index b50cadd..2299f6e 100644 --- a/data/elements.txt +++ b/data/elements.txt @@ -1188,7 +1188,6 @@ div[data-notificationid="cookie"] .cookies_alert .cookie--form div[class*="cookieDisclaimer"] -.ot-sdk-show-settings .basic_features-cookiemessage .data-protection-notice #CookieReportsButton @@ -12433,4 +12432,5 @@ html[id="facebook"] > body > div.__fb-light-mode #cc-banner-wrap .css-1dbjc4n r-1awozwy r-1m3jxhj r-qo02w8 r-18u37iz r-1d7fvdj r-d9fdf6 r-tvv088 r-13qz1uu .sibbo-layout -body > sibbo-cmp-layout \ No newline at end of file +body > sibbo-cmp-layout +.cc_banner-wrapper \ No newline at end of file From 8349c52555f2e13ae190ae900dd28e375425ecea Mon Sep 17 00:00:00 2001 From: wanhose Date: Thu, 1 Jul 2021 15:10:38 +0200 Subject: [PATCH 2/5] feat(styles): update loading styles --- styles/content.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/styles/content.css b/styles/content.css index 036a83d..7112b79 100644 --- a/styles/content.css +++ b/styles/content.css @@ -1,5 +1,5 @@ body { - opacity: 0; + display: none !important; } @media (prefers-color-scheme: dark) { From f4d87d053be09a2026b37d728dd48f4dee66421d Mon Sep 17 00:00:00 2001 From: wanhose Date: Thu, 1 Jul 2021 15:11:09 +0200 Subject: [PATCH 3/5] feat(scripts): add state management to background scripts --- scripts/background.js | 89 ++++++++++++++++++++++++++++++------------- 1 file changed, 63 insertions(+), 26 deletions(-) diff --git a/scripts/background.js b/scripts/background.js index bd78d3f..10ff7da 100644 --- a/scripts/background.js +++ b/scripts/background.js @@ -23,59 +23,66 @@ const isValid = (cache) => /** * @function disableIcon - * @description Disables icon + * @description Disables icon if there is a tab * * @param {string} [tabId] - * @returns {boolean} */ const disableIcon = (tabId) => { - chrome.browserAction.setIcon({ - path: "assets/icons/disabled.png", - tabId, - }); + if (tabId) { + chrome.browserAction.setIcon({ + path: "assets/icons/disabled.png", + tabId, + }); + } }; /** * @function disablePopup - * @description Disables popup + * @description Disables popup if there is a tab * * @param {string} [tabId] */ const disablePopup = (tabId) => { - chrome.browserAction.setPopup({ - popup: "", - tabId, - }); + if (tabId) { + chrome.browserAction.setPopup({ + popup: "", + tabId, + }); + } }; /** * @function enableIcon - * @description Enables icon + * @description Enables icon if there is a tab * * @param {string} [tabId] */ const enableIcon = (tabId) => { - chrome.browserAction.setIcon({ - path: "assets/icons/enabled.png", - tabId, - }); + if (tabId) { + chrome.browserAction.setIcon({ + path: "assets/icons/enabled.png", + tabId, + }); + } }; /** * @function enablePopup - * @description Enables popup + * @description Enables popup if there is a tab * * @param {string} [tabId] */ const enablePopup = (tabId) => { - chrome.browserAction.setPopup({ - popup: "popup.html", - tabId, - }); + if (tabId) { + chrome.browserAction.setPopup({ + popup: "popup.html", + tabId, + }); + } }; /** @@ -170,27 +177,54 @@ const updateCache = (hostname, state) => { }); }; +/** + * @function updateState + * @description Set an extension state + * + * @param {string} [tabId] + * @param {string} [state] + */ + +const updateState = (tabId, state) => { + switch (state) { + case "loading": + chrome.tabs.insertCSS(tabId, { + file: "styles/content.css", + runAt: "document_start", + }); + break; + case "ready": + chrome.tabs.removeCSS(tabId, { + file: "styles/content.css", + }); + break; + default: + break; + } +}; + /** * @description Listens to content messages */ chrome.runtime.onMessage.addListener((request, sender, responseCallback) => { chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => { + const hasPermission = !sender.frameId || sender.frameId === 0; const tab = tabs[0]; - const tabId = tab.id; + const tabId = tab ? tab.id : undefined; switch (request.type) { case "DISABLE_ICON": - disableIcon(tabId); + if (hasPermission) disableIcon(tabId); break; case "DISABLE_POPUP": - disablePopup(tabId); + if (hasPermission) disablePopup(tabId); break; case "ENABLE_ICON": - enableIcon(tabId); + if (hasPermission) enableIcon(tabId); break; case "ENABLE_POPUP": - enablePopup(tabId); + if (hasPermission) enablePopup(tabId); break; case "GET_CACHE": getCache(request.hostname, responseCallback); @@ -204,6 +238,9 @@ chrome.runtime.onMessage.addListener((request, sender, responseCallback) => { case "UPDATE_CACHE": updateCache(request.hostname, request.state); break; + case "UPDATE_STATE": + if (hasPermission) updateState(tabId, request.state); + break; default: break; } From f0a4673ce8109a6657f5a556c881aae079b5abbd Mon Sep 17 00:00:00 2001 From: wanhose Date: Thu, 1 Jul 2021 15:11:32 +0200 Subject: [PATCH 4/5] feat(scripts): implement content state methods --- scripts/content.js | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/scripts/content.js b/scripts/content.js index e2d2485..5e25d1b 100644 --- a/scripts/content.js +++ b/scripts/content.js @@ -59,8 +59,7 @@ const fix = () => { if (body) body.style.setProperty("overflow-y", "unset", "important"); if (facebook) facebook.style.setProperty("position", "unset", "important"); if (html) html.style.setProperty("overflow-y", "unset", "important"); - if (body && !loading) body.style.setProperty("opacity", "1"); - if (html && !loading) html.style.setProperty("background-color", "initial"); + if (!loading) dispatch({ state: "ready", type: "UPDATE_STATE" }); }; /** @@ -148,7 +147,7 @@ const runTasks = () => { fix(); removeFromCache(); if (attempts <= 5) removeFromNetwork(); - if (document.readyState !== "loading") attempts += 1; + if (document.readyState === "complete") attempts += 1; } if (attempts > 20) { @@ -163,20 +162,17 @@ const runTasks = () => { dispatch( { hostname: document.location.hostname, type: "GET_CACHE" }, null, - async ({ enabled, matches }) => { + ({ enabled, matches }) => { dispatch({ type: "ENABLE_POPUP" }); if (enabled) { + dispatch({ state: "loading", type: "UPDATE_STATE" }); selectorsFromCache = matches; dispatch({ type: "ENABLE_ICON" }); - dispatch({ type: "GET_LIST" }, null, async ({ selectors }) => { + dispatch({ type: "GET_LIST" }, null, ({ selectors }) => { selectorsFromNetwork = selectors; intervalId = setInterval(runTasks, 500); }); - } else { - document.addEventListener("DOMContentLoaded", () => { - document.body.style.setProperty("opacity", "1", "important"); - }); } } ); From 77d63554e48a4973d39e23e86b2b824b00e94ad0 Mon Sep 17 00:00:00 2001 From: wanhose Date: Thu, 1 Jul 2021 15:11:43 +0200 Subject: [PATCH 5/5] feat(manifest): update permissions and version --- manifest.json | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/manifest.json b/manifest.json index ab1296a..92a31af 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "manifest_version": 2, "name": "Do Not Consent", - "version": "4.0.3", + "version": "4.1.0", "default_locale": "en", "description": "__MSG_appDesc__", "icons": { @@ -21,12 +21,11 @@ "content_scripts": [ { "all_frames": true, - "css": ["styles/content.css"], "js": ["scripts/content.js"], "matches": ["http://*/*", "https://*/*"], "run_at": "document_start" } ], - "permissions": ["https://raw.githubusercontent.com/*", "storage", "tabs"], + "permissions": ["http://*/*", "https://*/*", "storage", "tabs"], "web_accessible_resources": ["assets/fonts/*", "scripts/*", "styles/*"] }