From 9ac68b7b9a0fd9ba05d9f5f3e00d5742e91084c4 Mon Sep 17 00:00:00 2001 From: wanhose Date: Wed, 10 Nov 2021 11:10:35 +0100 Subject: [PATCH 1/7] feat(data): add elements --- data/elements.txt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/data/elements.txt b/data/elements.txt index 11a5d7c..91d8c18 100644 --- a/data/elements.txt +++ b/data/elements.txt @@ -4860,7 +4860,6 @@ div[data-nconvert-cookie] #cookie-overlay-wrapper .js-terms-of-use-disclaimer .cookiebalk -.yt-consent-banner #CookieHead .CookieBox .GAcookies @@ -7165,7 +7164,6 @@ form > .infobanner > .content > .info .cp-module-info_bar .lam-cookie-container #sfCookieWarningBar -.yt-alert yt-alert-actionable yt-alert-info cookie-alert .cc_banner-wrapper_FB #overlay_pri .cookieconsent @@ -12483,7 +12481,6 @@ div[title*="Before you continue"][aria-modal="true"][role="dialog"] div[title*="Bevor Sie"][aria-modal="true"][role="dialog"] div[title*="Avant d'accéder"][aria-modal="true"][role="dialog"] div[title*="Prima di continuare"][aria-modal="true"][role="dialog"] -.ytd-consent-bump-v2-lightbox .mde-consent-modal-container .cmpContainer #axeptio_overlay @@ -12512,4 +12509,7 @@ script[src*="cookie-first"] #cf-root .miniConsent div.consent[style="display: none"] -iframe[src*="cmp.autoweek.nl"] \ No newline at end of file +iframe[src*="cmp.autoweek.nl"] +div[class*="ConsentBanner"] +html#facebook > body > div > div > div > div > :nth-child(5) +.cc-dialog.nl \ No newline at end of file From 1e701d9b8712fe336289de5a83ee4779b515289f Mon Sep 17 00:00:00 2001 From: wanhose Date: Wed, 10 Nov 2021 11:17:35 +0100 Subject: [PATCH 2/7] feat(scripts): add get fixes in background script --- scripts/background.js | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/scripts/background.js b/scripts/background.js index c359253..52c4efc 100644 --- a/scripts/background.js +++ b/scripts/background.js @@ -112,6 +112,28 @@ const getClasses = async (callback) => { } }; +/** + * @async + * @description Retrieves a selectors list + * @param {void} [callback] + * @returns {Promise<{ classes: string[] }>} + */ + +const getFixes = async (callback) => { + try { + const url = + "https://raw.githubusercontent.com/wanhose/cookie-dialog-monster/master/data/fixes.txt"; + const response = await fetch(url); + const data = await response.text(); + + if (response.status !== 200) throw new Error(); + + callback({ fixes: data.split("\n") }); + } catch { + callback({ fixes: [] }); + } +}; + /** * @async * @description Retrieves a selectors list @@ -128,7 +150,7 @@ const getSelectors = async (callback) => { if (response.status !== 200) throw new Error(); - callback({ selectors: data.split("\n").join(",") }); + callback({ selectors: data.split("\n") }); } catch { callback({ selectors: [] }); } @@ -230,6 +252,9 @@ chrome.runtime.onMessage.addListener((request, sender, callback) => { case "GET_CLASSES": getClasses(callback); break; + case "GET_FIXES": + getFixes(callback); + break; case "GET_SELECTORS": getSelectors(callback); break; From e0ce2a3d07f16c061c85bda6cd987eba36e51336 Mon Sep 17 00:00:00 2001 From: wanhose Date: Wed, 10 Nov 2021 11:24:59 +0100 Subject: [PATCH 3/7] feat(scripts): improve code and replace fixes logic --- scripts/content.js | 151 +++++++++++++++++++++++---------------------- 1 file changed, 77 insertions(+), 74 deletions(-) diff --git a/scripts/content.js b/scripts/content.js index 0390def..f967766 100644 --- a/scripts/content.js +++ b/scripts/content.js @@ -12,6 +12,13 @@ let classes = []; const dispatch = chrome.runtime.sendMessage; +/** + * @description Array of instructions + * @type {string[]} + */ + +let fixes = []; + /** * @description Hostname */ @@ -22,20 +29,20 @@ const hostname = document.location.hostname; * @description Is consent preview page? */ -const isConsentPreview = hostname.startsWith("consent."); +const isPreview = hostname.startsWith("consent."); /** * @description Options provided to observer */ -const options = { childList: true, subtree: true }; +const options = { attributes: true, childList: true, subtree: true }; /** * @description Selectors list - * @type {string} + * @type {string[]} */ -let selectors = ""; +let selectors = []; /** * @description Target provided to observer @@ -51,8 +58,8 @@ const target = document.body || document.documentElement; const check = (node) => node instanceof HTMLElement && node.parentElement && - !["APP", "ROOT"].includes(node.id.toUpperCase()) && - !["BODY", "HTML"].includes(node.tagName); + !["BODY", "HTML"].includes(node.tagName) && + !["APP", "ROOT"].includes(node.id.toUpperCase()); /** * @description Cleans DOM @@ -62,12 +69,11 @@ const clean = () => { if (selectors.length) { const nodes = document.querySelectorAll(selectors); - for (let i = nodes.length; i--; ) { - const node = nodes[i]; + nodes.forEach((node) => { const valid = check(node); if (valid) node.outerHTML = ""; - } + }); } }; @@ -76,108 +82,100 @@ const clean = () => { */ const fix = () => { - const automobiel = /automobielmanagement.nl/g.test(hostname); const body = document.body; - const facebook = document.getElementsByClassName("_31e")[0]; - const frame = document.location.ancestorOrigins.length; - const google = document.querySelector('form[action*="consent.google"]'); + const frame = window.frameElement; const html = document.documentElement; - const play = hostname.startsWith("play.google."); - const yahoo = document.querySelector("#consent-page"); - if (automobiel && body) { - for (let i = body.childNodes.length; i--; ) { - const node = body.childNodes[i]; - - if (node instanceof HTMLElement) { - node.style.setProperty("filter", "initial", "important"); - } - } - } - - if (body) { + if (body && html) { body.classList.remove(...classes); - - if (!frame) { - body.style.setProperty("overflow-y", "initial", "important"); - body.style.setProperty("position", "initial", "important"); - } - } - - if (facebook) { - facebook.style.setProperty("position", "initial", "important"); - } - - if (google) { - const submit = google.querySelector("button"); - - if (submit && submit instanceof HTMLElement) { - submit.click(); - } - } - - if (html) { html.classList.remove(...classes); if (!frame) { + body.style.setProperty("position", "initial", "important"); + body.style.setProperty("overflow-y", "initial", "important"); html.style.setProperty("position", "initial", "important"); html.style.setProperty("overflow-y", "initial", "important"); } } - if (play) { - const node = document.querySelector("body > div"); + fixes.forEach((fix) => { + const [match, selector, action, property] = fix.split("##"); - if (node && node instanceof HTMLElement) { - node.style.setProperty("z-index", "initial", "important"); + if (hostname.includes(match)) { + switch (action) { + case "click": + const submit = document.querySelector(selector); + + if (submit && submit instanceof HTMLElement) { + submit.click(); + } + break; + case "reset": + const node = document.querySelector(selector); + + if (node && node instanceof HTMLElement) { + node.style.setProperty(property, "initial", "important"); + } + break; + case "resetAll": + const nodes = document.querySelectorAll(selector); + + nodes.forEach((node) => { + if (node instanceof HTMLElement) { + node.style.setProperty(property, "initial", "important"); + } + }); + break; + default: + break; + } } - } - - if (yahoo) { - const submit = yahoo.querySelector('button[type="submit"]'); - - if (submit && submit instanceof HTMLElement) { - submit.click(); - } - } + }); }; const observer = new MutationObserver((mutations, instance) => { instance.disconnect(); fix(); - if (!isConsentPreview) { - for (let i = mutations.length; i--; ) { - const mutation = mutations[i]; - - for (let j = mutation.addedNodes.length; j--; ) { - const node = mutation.addedNodes[j]; + if (!isPreview) { + mutations.forEach((mutation) => { + mutation.addedNodes.forEach((node) => { const valid = check(node); if (valid && node.matches(selectors)) node.outerHTML = ""; - } - } + }); + }); } instance.observe(target, options); }); /** - * @description Setups classes selectors + * @description Queries classes selectors * @returns {Promise<{ classes: string[] }>} */ -const setupClasses = () => +const queryClasses = () => new Promise((resolve) => { dispatch({ type: "GET_CLASSES" }, null, resolve); }); /** - * @description Setups elements selectors + * @description Queries fixes instructions + * @returns {Promise<{ fixes: string[] }>} + */ + +const queryFixes = () => + new Promise((resolve) => { + dispatch({ type: "GET_FIXES" }, null, resolve); + }); + +/** + * @description Queries elements selectors * @returns {Promise<{ selectors: string }>} */ -const setupSelectors = () => +const querySelectors = () => new Promise((resolve) => { dispatch({ type: "GET_SELECTORS" }, null, resolve); }); @@ -189,7 +187,7 @@ const setupSelectors = () => document.addEventListener("readystatechange", () => { dispatch({ hostname, type: "GET_CACHE" }, null, async ({ enabled }) => { - if (document.readyState === "complete" && enabled && !isConsentPreview) { + if (document.readyState === "complete" && enabled && !isPreview) { fix(); clean(); setTimeout(clean, 2000); @@ -206,9 +204,14 @@ dispatch({ hostname, type: "GET_CACHE" }, null, async ({ enabled }) => { if (enabled) { dispatch({ type: "ENABLE_ICON" }); - const results = await Promise.all([setupClasses(), setupSelectors()]); + const results = await Promise.all([ + queryClasses(), + queryFixes(), + querySelectors(), + ]); classes = results[0].classes; - selectors = results[1].selectors; + fixes = results[1].fixes; + selectors = results[2].selectors; observer.observe(target, options); } }); From d0f841759172127498ce07b971c1e9a035328eca Mon Sep 17 00:00:00 2001 From: wanhose Date: Wed, 10 Nov 2021 11:25:36 +0100 Subject: [PATCH 4/7] chore(manifest): add new exclusions and upgrade version --- manifest.json | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/manifest.json b/manifest.json index 5a4f655..c911da2 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "manifest_version": 2, "name": "Cookie Dialog Monster", - "version": "5.4.1", + "version": "5.4.2", "default_locale": "en", "description": "__MSG_appDesc__", "icons": { @@ -20,7 +20,11 @@ "content_scripts": [ { "all_frames": true, - "exclude_matches": ["*://*.gfycat.com/*"], + "exclude_matches": [ + "*://*.gfycat.com/*", + "*://*.gmx.com/*", + "*://*.rundschau-online.de/*" + ], "js": ["scripts/content.js"], "matches": ["http://*/*", "https://*/*"], "run_at": "document_start" From dd6f6c997480dab86d7b7f385d2703540388fd63 Mon Sep 17 00:00:00 2001 From: wanhose Date: Wed, 10 Nov 2021 11:40:26 +0100 Subject: [PATCH 5/7] feat(scripts): improve reports --- scripts/background.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/scripts/background.js b/scripts/background.js index 52c4efc..07149c6 100644 --- a/scripts/background.js +++ b/scripts/background.js @@ -178,11 +178,13 @@ const getTab = (callback) => { const report = () => { chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => { const tab = tabs[0]; + const userAgent = window.navigator.userAgent; + const version = chrome.runtime.getManifest().version; if (tab) { fetch("https://cdm-report-service.herokuapp.com/rest/v1/report/", { body: JSON.stringify({ - text: tab.url, + text: `There's a problem with ${tab.url} using ${userAgent} in CDM ${version}`, to: "wanhose.development@gmail.com", subject: "Cookie Dialog Monster Report", }), From 7a45974e98322aedb02a3fd1cc090f229eb6b442 Mon Sep 17 00:00:00 2001 From: wanhose Date: Wed, 10 Nov 2021 14:07:18 +0100 Subject: [PATCH 6/7] fix(scripts): background wrong performance --- scripts/background.js | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/scripts/background.js b/scripts/background.js index 07149c6..202d2ec 100644 --- a/scripts/background.js +++ b/scripts/background.js @@ -207,8 +207,6 @@ const updateCache = (hostname, state) => { chrome.storage.local.get(null, (cache) => { const current = cache[hostname]; - if (!state.enabled) report(); - chrome.storage.local.set({ [hostname]: { enabled: @@ -228,25 +226,18 @@ chrome.runtime.onMessage.addListener((request, sender, callback) => { const hasPermission = !sender.frameId || sender.frameId === 0; let tabId = sender.tab ? sender.tab.id : undefined; - if (!tabId) { - chrome.tabs.query( - { active: true, currentWindow: true }, - (tabs) => (tabId = tabs[0] ? tabs[0].id : 0) - ); - } - switch (request.type) { case "DISABLE_ICON": - if (hasPermission) disableIcon(tabId); + if (hasPermission && tabId) disableIcon(tabId); break; case "DISABLE_POPUP": - if (hasPermission) disablePopup(tabId); + if (hasPermission && tabId) disablePopup(tabId); break; case "ENABLE_ICON": - if (hasPermission) enableIcon(tabId); + if (hasPermission && tabId) enableIcon(tabId); break; case "ENABLE_POPUP": - if (hasPermission) enablePopup(tabId); + if (hasPermission && tabId) enablePopup(tabId); break; case "GET_CACHE": getCache(request.hostname, callback); From 96e463b4704dd7e1c79e41e73fb2c6352404516a Mon Sep 17 00:00:00 2001 From: wanhose Date: Wed, 10 Nov 2021 15:34:30 +0100 Subject: [PATCH 7/7] fix(scripts): content iframe detection --- scripts/content.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/content.js b/scripts/content.js index f967766..10dc72c 100644 --- a/scripts/content.js +++ b/scripts/content.js @@ -59,7 +59,7 @@ const check = (node) => node instanceof HTMLElement && node.parentElement && !["BODY", "HTML"].includes(node.tagName) && - !["APP", "ROOT"].includes(node.id.toUpperCase()); + !(node.id && ["APP", "ROOT"].includes(node.id.toUpperCase())); /** * @description Cleans DOM @@ -83,7 +83,7 @@ const clean = () => { const fix = () => { const body = document.body; - const frame = window.frameElement; + const frame = !(window === window.parent || window.opener); const html = document.documentElement; if (body && html) {