Last active
May 1, 2024 12:33
-
-
Save moeiscool/0234781c8af0c468c01bc97f0ed022e1 to your computer and use it in GitHub Desktop.
Block/Delete Facebook Ads
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//This works for MOST ads, not all of them. Anyone with updates please share. | |
//1. Install this plugin on Chrome : https://chrome.google.com/webstore/detail/custom-javascript-for-web/poakhlngfciodnhlhhgnaaelnpjljija?hl=en | |
//2. go to facebook.com and click the CJS icon in the top right. | |
//3. Copy and Paste this code into that window. Press Save. | |
//You don't need CJS, just some way to execute custom code. This should work on any browser capable of executing custom code on load. | |
// !!!!!!!!!!!!!!!! PASTE ONLY THE CONTENTS BELOW THIS LINE !!!!!!!!!!!!!!!!!!!!! | |
if(location.host.indexOf('youtube') > -1 && location.pathname === '/'){ | |
window.onscroll = function(){ | |
clearTimeout(window.lagTimeout) | |
window.lagTimeout = setTimeout(function(){ | |
//get all <a class="yt-simple-endpoint"> elements | |
var buttonTags = document.querySelectorAll(".yt-simple-endpoint"); | |
var found = []; | |
//function that checks text inside an element, if matched it will mark it's parent for deletion | |
var checkTag = function(tagName,el){ | |
([ | |
'Global News', | |
'CNN', | |
'CTV News', | |
'CBC News', | |
'Le Devoir', | |
'CityNews', | |
'ICI ', | |
'Saskatoon StarPhoenix ', | |
]).forEach(function(tagItem){ | |
if(tagName.indexOf(tagItem) > -1)found.push(el); | |
}); | |
} | |
//iterate all <a class="yt-simple-endpoint"> and mark accepted as deletable | |
for (var i = 0; i < buttonTags.length; i++) { | |
checkTag(buttonTags[i].innerText,buttonTags[i]) | |
} | |
//mark all parents with attribute to be deleted | |
found.forEach(e => { | |
try{ | |
var deleteMe = e.closest('.ytd-rich-shelf-renderer').setAttribute('deleteThisNow', 'deleteThisNow') | |
}catch(err){ | |
} | |
}); | |
//delete elements with custom attribute added "deleteThisNow" | |
document.querySelectorAll('[deleteThisNow]').forEach(e => e.parentNode.removeChild(e)); | |
},500) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//This works for MOST ads, not all of them. Anyone with updates please share. | |
//1. Install this plugin on Chrome : https://chrome.google.com/webstore/detail/custom-javascript-for-web/poakhlngfciodnhlhhgnaaelnpjljija?hl=en | |
//2. go to facebook.com and click the CJS icon in the top right. | |
//3. Copy and Paste this code into that window. Press Save. | |
//You don't need CJS, just some way to execute custom code. This should work on any browser capable of executing custom code on load. | |
if(location.host.indexOf('facebook') > -1 && location.pathname === '/'){ | |
window.onscroll = function(){ | |
clearTimeout(window.lagTimeout) | |
window.lagTimeout = setTimeout(function(){ | |
//get all <a> elements | |
var aTags = document.getElementsByTagName("a") | |
//get all <button> elements | |
var buttonTags = document.querySelectorAll("button"); | |
var found = []; | |
//function that checks text inside an element, if matched it will mark it's parent for deletion | |
var checkTag = function(tagName,el){ | |
switch(tagName){ | |
case'Sponsored': | |
case'Get Quote': | |
case'Watch More': | |
case'Get Directions': | |
case'Subscribe': | |
case'Download': | |
case'Get Offer': | |
case'Shop Now': | |
case'Sign Up': | |
case'Learn More': | |
case'Donate Now': | |
case'Apply Now': | |
found.push(el); | |
break; | |
} | |
} | |
//iterate all <a> and mark accepted as deletable | |
for (var i = 0; i < aTags.length; i++) { | |
checkTag(aTags[i].textContent,aTags[i]) | |
} | |
//iterate all <button> and mark accepted as deletable | |
for (var i = 0; i < buttonTags.length; i++) { | |
checkTag(buttonTags[i].innerText,buttonTags[i]) | |
} | |
//mark all parents with attribute to be deleted | |
found.forEach(e => { | |
try{ | |
var deleteMe = e.closest('[role="article"]').setAttribute('deleteThisNow', 'deleteThisNow') | |
}catch(err){ | |
} | |
}); | |
//delete elements with custom attribute added "deleteThisNow" | |
document.querySelectorAll('[deleteThisNow]').forEach(e => e.parentNode.removeChild(e)); | |
},500) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Only copy line 3. This filter was provided by Reddit user "Rognvaldr_" at https://www.reddit.com/r/uBlockOrigin/comments/ec8h4e/ublock_no_longer_blocks_sponsored_posts_on/ | |
facebook.com#?#div[id^=hyperfeed_story_id_]:has(a[role^=button]:has(> span:has([data-content="S"]):not(:has([data-content="1"])):not(:has([data-content="2"])):not(:has([data-content="3"])):not(:has([data-content="4"])):not(:has([data-content="5"])):not(:has([data-content="6"])):not(:has([data-content="7"])):not(:has([data-content="8"])):not(:has([data-content="9"])):not(:has([data-content="w"])))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment