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