feat(scripts): bypass google and yahoo preview pages

This commit is contained in:
wanhose 2021-11-06 20:09:38 +01:00
parent 49bc4ab22d
commit 7f968a57f0

View File

@ -12,6 +12,12 @@ let classes = [];
const dispatch = chrome.runtime.sendMessage; const dispatch = chrome.runtime.sendMessage;
/**
* @description Is consent preview page?
*/
const isConsentPreview = document.location.host.startsWith("consent.");
/** /**
* @description Options provided to observer * @description Options provided to observer
*/ */
@ -50,7 +56,9 @@ const clean = () => {
const fix = () => { const fix = () => {
const body = document.body; const body = document.body;
const facebook = document.getElementsByClassName("_31e")[0]; const facebook = document.getElementsByClassName("_31e")[0];
const google = document.querySelector('form[action*="consent.google"]');
const html = document.documentElement; const html = document.documentElement;
const yahoo = document.querySelector("#consent-page");
if (body) { if (body) {
if (classes.length) body.classList.remove(...classes); if (classes.length) body.classList.remove(...classes);
@ -62,17 +70,26 @@ const fix = () => {
facebook.style.setProperty("position", "initial", "important"); facebook.style.setProperty("position", "initial", "important");
} }
if (google) {
google.querySelector("button").click();
}
if (html) { if (html) {
if (classes.length) html.classList.remove(...classes); if (classes.length) html.classList.remove(...classes);
html.style.setProperty("position", "initial", "important"); html.style.setProperty("position", "initial", "important");
html.style.setProperty("overflow-y", "initial", "important"); html.style.setProperty("overflow-y", "initial", "important");
} }
if (yahoo) {
yahoo.querySelector('button[type="submit"]').click();
}
}; };
const observer = new MutationObserver((mutations, instance) => { const observer = new MutationObserver((mutations, instance) => {
instance.disconnect(); instance.disconnect();
fix(); fix();
if (!isConsentPreview) {
for (let i = mutations.length; i--; ) { for (let i = mutations.length; i--; ) {
const mutation = mutations[i]; const mutation = mutations[i];
@ -88,6 +105,7 @@ const observer = new MutationObserver((mutations, instance) => {
if (node.matches(selectors)) node.outerHTML = ""; if (node.matches(selectors)) node.outerHTML = "";
} }
} }
}
instance.observe(target, options); instance.observe(target, options);
}); });
@ -118,9 +136,13 @@ const setupSelectors = () =>
document.addEventListener("readystatechange", () => { document.addEventListener("readystatechange", () => {
if (document.readyState === "complete") { if (document.readyState === "complete") {
fix();
if (!isConsentPreview) {
clean(); clean();
setTimeout(clean, 2000); setTimeout(clean, 2000);
} }
}
}); });
/** /**