Skip to content

Instantly share code, notes, and snippets.

@dccampbell
Created February 18, 2019 18:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dccampbell/1ff8ef37db3acf22e85650042f968449 to your computer and use it in GitHub Desktop.
Save dccampbell/1ff8ef37db3acf22e85650042f968449 to your computer and use it in GitHub Desktop.
A script for selectively batch removing advertisers from your Facebook preferences.
// https://www.facebook.com/ads/preferences/
function loadAllAdvertisers() {
if(!document.querySelector('#interacted ._45ys')) {
document.querySelector('#interacted div[role=button]').click();
}
window.interactedInterval = setInterval(function() {
var moreBtn = document.querySelector('#interacted ._45yr');
if(moreBtn) {
document.querySelector('#interacted ._45yr').click();
} else {
clearInterval(interactedInterval);
console.log('All advertisers loaded.');
}
}, 800);
}
loadAllAdvertisers();
function killAdvertiser() {
for(var ad of document.querySelectorAll('#interacted ._2b2e')) {
for(var i=0; i < arguments.length; i++) {
if(ad.textContent.includes(arguments[i]) && ad.textContent.includes("Remove")) {
ad.querySelector('button').click();
}
}
}
}
// Usage Examples:
// killAdvertiser('Auto', 'Motors', 'Truck', 'BMW', 'Volks', 'Toyota', 'Kia', 'Hyundai', 'Nissan', 'Honda');
// killAdvertiser('Ford', 'Mazda', 'Dodge', 'Subaru', 'Land Rover', 'Benz', 'Acura', 'Buick', 'Chevy', 'Lexus');
// killAdvertiser('Realtor', 'Realty', 'Real Estate', 'Homes', 'Houses');
// killAdvertiser(''); // remove all (may be extremely slow or even crash if too many)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment