Skip to content

Instantly share code, notes, and snippets.

@edjw
Last active April 16, 2020 01:02
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save edjw/8f398366bcf98bec09d282b79c030edd to your computer and use it in GitHub Desktop.
Save edjw/8f398366bcf98bec09d282b79c030edd to your computer and use it in GitHub Desktop.
A script to remove you from advertisers' FB audience when they uploaded your contact information and it matched the information FB has about you
// This script removes you from advertisers' target lists on Facebook.
// They probably added you to their advert targeting list by uploading a contact list that includes
// your contact information like your email address or phone number.
// Comment below if this doesn't work for you
// *Instructions*
// 1. Go to https://www.facebook.com/ads/preferences
// 2. Open the Console in the Developer Tools
// (Mac: Alt+Cmd+K on Firefox, Alt+Cmd+J on Chrome; Windows/Linux: Control+Shift+K on Firefox, Control+Shift+J on Chrome)
// 3. Ignore the warnings from Facebook in the Console.
// I've annotated the script to help you understand it but sorry at some point you'll just have to trust me! :-)
// 4. Paste in this script below.
////////
// This just enforces certain bits of best practice in Javascript (the language this script is written in)
"use strict";
// Expands the "Advertisers you've interacted with" dropdown
const interactedList = document.getElementsByClassName("_2qo6")[1];
interactedList.click();
// Clicks the "Show more" buttons until all the advertisers are revealed
// You may have to adjust the class name for "Show More" buttons if Facebook changes them
var showMoreButton = document.getElementsByClassName("_45yq _5946")[0];
while (showMoreButton) {
showMoreButton.click();
var showMoreButton = document.getElementsByClassName("_45yq _5946")[0];
}
// Clicks into each of the interest areas one-by-one
const interests = Array.from(document.getElementsByClassName("_2b2h _2b2i"));
interests.forEach((interest) => {
interest.click();
// You may have to adjust the class names for "Remove" buttons if Facebook changes them
const removeButtons = Array.from(document.getElementsByClassName("_2b2p _4jy0 _4jy3 _517h _51sy _42ft"));
// Clicks the remove button on each of the advertisers
removeButtons.forEach((removeButton) => {
if (removeButton.title == "Hide ads from this advertiser") {
removeButton.click();
}
if (removeButton.title == "Remove") {
removeButton.click();
}
});
});
@Dimitrinski
Copy link

Found your script and tried it on my account. Was not working completely. I looked at it for a while and made some tweaks that seem to have made it work for me.

DEL if (removeButton.textContent === "Remove") {
ADD if (removeButton.title == "Hide ads from this advertiser") {

@edjw
Copy link
Author

edjw commented Jun 4, 2019

Found your script and tried it on my account. Was not working completely. I looked at it for a while and made some tweaks that seem to have made it work for me.

DEL if (removeButton.textContent === "Remove") {
ADD if (removeButton.title == "Hide ads from this advertiser") {

Thanks, I've made those changes now :-)

@ShoGinn
Copy link

ShoGinn commented Apr 16, 2020

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