Skip to content

Instantly share code, notes, and snippets.

@wolph
Last active September 1, 2023 13:19
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save wolph/985a6072b35926eb4a3f9d2cdd0a2dad to your computer and use it in GitHub Desktop.
Save wolph/985a6072b35926eb4a3f9d2cdd0a2dad to your computer and use it in GitHub Desktop.
Google Cookie Consent Remover
@Sithuk
Copy link

Sithuk commented Apr 4, 2022

Nice script. Can you make it work for countries with a second-level domain too? For example, www.google.co.za

https://en.wikipedia.org/wiki/.co_(second-level_domain)

@wolph
Copy link
Author

wolph commented Apr 4, 2022

Nice script. Can you make it work for countries with a second-level domain too? For example, www.google.co.za

https://en.wikipedia.org/wiki/.co_(second-level_domain)

I believe I've updated it to work with every TLD now. Can you try?

@paoloiulita
Copy link

paoloiulita commented Apr 11, 2022

My updated version:

  • uses xPath to get button by text so even if they change the HTML tag this should work
  • triggers after 1 second because the popup may not be immediately in page
const run = () => {
    const xpath = '//*[contains(text(),"I Agree")]';
    const agreeBtn = document.evaluate(xpath, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
    if(agreeBtn) agreeBtn.click();

    document.querySelector('div[aria-modal]')?.remove();

    const form = document.querySelector('form');

    if(form?.action?.match(/consent/)?.length === 1) {
        form.querySelector('button')?.click();
    }
}

setTimeout(run, 1000);

@mm1992
Copy link

mm1992 commented Apr 14, 2022

Do I have to reopen the browser in order to changes make effect?
I tried with both scripts of @wolph and @paoloiulita. I use Tampermonkey and I've enabled this addon to work in incognito mode (Chrome), but whatever I use, the f#cking Google s#it still redirects to consent page.
It would be great to make it work, because I often use incognito mode to reduce my activity on Google account.

Screens:
https://i.ibb.co/xJRB59T/scr1.jpg
https://i.ibb.co/YTYwqxp/scr2.jpg
https://i.ibb.co/mS76L6j/scr3.jpg (sorry for Polish lang version)

But the effect is:
https://i.ibb.co/k5B7MJj/scr4.jpg

@wolph
Copy link
Author

wolph commented Apr 14, 2022

@mm1992 I've updated the script to include the changes from @paoloiulita with a few small modifications.

With regards to the issues you're experiencing, are you sure the script is running in incognito? Tampermonkey should show how many scripts were executed:
image

If it's enabled you only need to reload the page. Nothing else should be needed.

@iTech0
Copy link

iTech0 commented Oct 19, 2022

Does this script block the "before you continue to google" prompt? Not working for me...

https://ibb.co/QXm8kYv

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment