Update click-all script to handle "accept" buttons hidden in shadow-dom
This commit is contained in:
parent
e11ef09e84
commit
3f8e106bf5
|
@ -1,12 +1,34 @@
|
||||||
regexes = ["allow", "accept", "agree", "akceptuj", /przejdź(?! do główn).*/];
|
console.log("start");
|
||||||
avoid = ["dostosuj", "don't"];
|
|
||||||
|
|
||||||
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) =>
|
||||||
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)
|
regexes.some((regex) => e.textContent.toLowerCase().match(regex) !== null)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
console.log("buttons after first filter", buttons);
|
||||||
|
|
||||||
operations = [
|
operations = [
|
||||||
(buttons) =>
|
(buttons) =>
|
||||||
buttons.filter((button) => {
|
buttons.filter((button) => {
|
||||||
|
@ -17,16 +39,17 @@ operations = [
|
||||||
!(rect.width == 0 && rect.height == 0)
|
!(rect.width == 0 && rect.height == 0)
|
||||||
);
|
);
|
||||||
}),
|
}),
|
||||||
|
(buttons) =>
|
||||||
|
buttons.filter((e) =>
|
||||||
|
avoid.every((word) => !e.textContent.toLowerCase().includes(word))
|
||||||
|
),
|
||||||
(buttons) =>
|
(buttons) =>
|
||||||
buttons.filter((e) => !e.textContent.toLowerCase().includes("only")),
|
buttons.filter((e) => !e.textContent.toLowerCase().includes("only")),
|
||||||
(buttons) => buttons.filter((e) => e.tagName.toLowerCase() === "button"),
|
(buttons) => buttons.filter((e) => e.tagName.toLowerCase() === "button"),
|
||||||
(buttons) =>
|
(buttons) =>
|
||||||
buttons.filter((e) => !e.textContent.toLowerCase().includes("do not")),
|
buttons.filter((e) => !e.textContent.toLowerCase().includes("do not")),
|
||||||
(buttons) => buttons.filter((e) => e.tagName.toLowerCase() === "a"),
|
(buttons) => buttons.filter((e) => e.tagName.toLowerCase() === "a"),
|
||||||
(buttons) =>
|
|
||||||
buttons.filter((e) =>
|
|
||||||
avoid.every((word) => !e.textContent.toLowerCase().includes(word))
|
|
||||||
),
|
|
||||||
(buttons) =>
|
(buttons) =>
|
||||||
buttons.filter(
|
buttons.filter(
|
||||||
(e) => e.tagName.toLowerCase() === "input" && e.type === "submit"
|
(e) => e.tagName.toLowerCase() === "input" && e.type === "submit"
|
||||||
|
@ -38,14 +61,15 @@ for (const operation of operations) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
const result = operation(buttons);
|
const result = operation(buttons);
|
||||||
|
console.log("RESULT", operation, result);
|
||||||
if (result.length) {
|
if (result.length) {
|
||||||
buttons = result;
|
buttons = result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
buttons;
|
||||||
|
|
||||||
buttons.forEach((button) => button.click());
|
buttons.forEach((button) => button.click());
|
||||||
buttons.forEach((button) => {
|
buttons.forEach((button) => {
|
||||||
button.querySelectorAll("input").forEach((child) => child.click());
|
button.querySelectorAll("input").forEach((child) => child.click());
|
||||||
});
|
});
|
||||||
|
|
||||||
buttons;
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user