Blocking ads on Facebook (and Google, soon)

The longer version:
I’m not a big fan of ads on the websites (I’m OK with innovative ads on YouTube though), especially on Facebook as these ads are disguising themselves as a post in my feed. What to do? Using Adblock? Nah, at least as of the moment since Adblock cannot easily detect Facebook ads.

Luckily, this TamperMonkey script called Facebook unsponsored come to the rescue. The idea is really simple:

  •  Locate the divs containing the ads: currently, it is under div.userContentWrapper and having the text such as “Sponsored“, “Suggested Post“, “Chartered
  • Add a MutationObserver to the HTML body, upon detection of body elements changed, look for these ads and remove them from the DOM tree.

It was short and simple. I’m going to take this approach to write Google Ads block script. Hang on tight.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.