Skip to content

Instantly share code, notes, and snippets.

@meniluca
Created May 18, 2021 08:41
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 meniluca/346139e6eaa630dde8640bbf489a4f28 to your computer and use it in GitHub Desktop.
Save meniluca/346139e6eaa630dde8640bbf489a4f28 to your computer and use it in GitHub Desktop.
To remove ads and annoying videos from your Facebook home. Can be used in combination with "Ad Blocker for Facebook™".
// Simple Facebook "Suggested for your" blocks removal (no distractions!)
// Instructions: copy and paste this code into the browser console
// open Facebook -> ctrl+shift+J (ignore alert) -> (paste into the console) ctrl+V -> ENTER
var removedADS = 0;
function get_a_elements_by_inner(word) {
res = []
elems = [...document.getElementsByTagName('a')];
elems.forEach((elem) => {
if(elem.outerHTML.includes(word)) {
res.push(elem)
}
})
return(res)
}
function get_span_elements_by_inner(word) {
res = []
elems = [...document.getElementsByTagName('span')];
elems.forEach((elem) => {
if(elem.innerHTML.includes(word)) {
res.push(elem)
}
})
return(res)
}
var remove = setInterval(function() {
if (window.location.href.indexOf("marketplace") > -1) {
/*
arr_a=get_a_elements_by_inner("Sponsored");
var filtered = arr_a.filter(function(element, index, array) { return (index % 2 === 0);});
filtered.forEach(function(x){
x.parentElement.remove();
removedADS++;
})
blanks=get_a_elements_by_inner("_blank");
blanks.forEach(function(x){
x.parentElement.remove();
removedADS++;
})
noclue=get_a_elements_by_inner("href=\"#\"")
noclue.forEach(function(x){
x.parentElement.remove();
removedADS++;
})
*/
console.log("Removing marketplace ADS not implemented");
// console.log('Removed marketplace ADS ('+removedADS+' so far)');
} else {
arr_a=get_a_elements_by_inner("Sponsored");
arr_a.forEach(function(x){
x.parentNode.parentNode.parentNode.parentNode.parentElement.parentNode.parentNode.parentElement.remove();
removedADS++;
})
arr_span=get_span_elements_by_inner("Suggested for you");
arr_span.forEach(function(x){
x.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.remove();
removedADS++;
})
console.log('REMOVING ADS ('+removedADS+' so far)');
}
}, 5000); // runs every 5 seconds
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment