From 3f8e106bf5f96a453b7be8f4d83a8282e00f08f7 Mon Sep 17 00:00:00 2001 From: Kuba Orlik Date: Tue, 16 Aug 2022 14:32:33 +0200 Subject: [PATCH] Update click-all script to handle "accept" buttons hidden in shadow-dom --- Docker/click-accept-all.js | 44 +++++++++++++++++++++++++++++--------- 1 file changed, 34 insertions(+), 10 deletions(-) diff --git a/Docker/click-accept-all.js b/Docker/click-accept-all.js index cc701b6..67753e4 100644 --- a/Docker/click-accept-all.js +++ b/Docker/click-accept-all.js @@ -1,12 +1,34 @@ -regexes = ["allow", "accept", "agree", "akceptuj", /przejdź(?! do główn).*/]; -avoid = ["dostosuj", "don't"]; +console.log("start"); -buttons = Array.from(document.querySelectorAll("*")).filter( +regexes = [ + "allow", + "accept", + "agree", + "akceptuj", + "zgadzam", + "zezwól", + /przejdź(?! do główn).*/, +]; +avoid = ["dostosuj", "don't", "nie zga", "nie zezw", "tylko"]; + +elements = Array.from(document.querySelectorAll("*")); + +// Tik Tok hides the "accept" button within shadowRoot, so it we need to do some digging +elements.forEach((element) => { + if (element.shadowRoot !== null) { + elements.push(...Array.from(element.shadowRoot.querySelectorAll("*"))); + } +}); + +buttons = elements.filter( (e) => - e.textContent.length < 50 && + e.textContent.length < + 70 /* FB has a really long one: Zezwól na korzystanie z niezbędnych i opcjonalnych plików cookie */ && regexes.some((regex) => e.textContent.toLowerCase().match(regex) !== null) ); +console.log("buttons after first filter", buttons); + operations = [ (buttons) => buttons.filter((button) => { @@ -17,16 +39,17 @@ operations = [ !(rect.width == 0 && rect.height == 0) ); }), + (buttons) => + buttons.filter((e) => + avoid.every((word) => !e.textContent.toLowerCase().includes(word)) + ), (buttons) => buttons.filter((e) => !e.textContent.toLowerCase().includes("only")), (buttons) => buttons.filter((e) => e.tagName.toLowerCase() === "button"), (buttons) => buttons.filter((e) => !e.textContent.toLowerCase().includes("do not")), (buttons) => buttons.filter((e) => e.tagName.toLowerCase() === "a"), - (buttons) => - buttons.filter((e) => - avoid.every((word) => !e.textContent.toLowerCase().includes(word)) - ), + (buttons) => buttons.filter( (e) => e.tagName.toLowerCase() === "input" && e.type === "submit" @@ -38,14 +61,15 @@ for (const operation of operations) { break; } const result = operation(buttons); + console.log("RESULT", operation, result); if (result.length) { buttons = result; } } +buttons; + buttons.forEach((button) => button.click()); buttons.forEach((button) => { button.querySelectorAll("input").forEach((child) => child.click()); }); - -buttons;