Skip to content

Instantly share code, notes, and snippets.

@edjw edjw/fb_ads_remove.js
Last active Jun 5, 2019

Embed
What would you like to do?
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

This comment has been minimized.

Copy link

Dimitrinski 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") {

@edjw

This comment has been minimized.

Copy link
Owner 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 :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.