Skip to content

Instantly share code, notes, and snippets.

@lamchau
Last active June 9, 2019 06:20
Show Gist options
  • Save lamchau/8f7a374fc487b7f97732d638d3af9f24 to your computer and use it in GitHub Desktop.
Save lamchau/8f7a374fc487b7f97732d638d3af9f24 to your computer and use it in GitHub Desktop.
Facebook builds an extensive list for targeting you on ads, this bookmarklet script will remove/purge all interests.

Usage:

  1. Use code below and create a bookmarklet here: https://mrcoles.com/bookmarklet/
    1. Drag bookmarklet to Chrome bookmarks toolbar
  2. Navigate to 'https://www.facebook.com/ads/preferences'
    1. Click bookmarklet from step above
    2. Need to expand 'More' from 'Your Interest' section image
const pagingInterval = setInterval(() => {
  const seeMore = Array.from(document.querySelectorAll('._45yr'));
  if (seeMore.length) {
    seeMore.forEach($link => $link.click());
  } else {
    clearInterval(pagingInterval);
    Array.from(document.querySelectorAll('.accessible_elem'))
      .filter($button => $button.innerText === 'Remove' || $button.innerText === 'Hide all ads from this advertiser')
      .forEach(($button, index) => {
        // API may be throttled, just in case let's add a small delay
        setTimeout(() => $button.click(), index * 100);
      });
  }
}, 250);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment