Skip to content

Instantly share code, notes, and snippets.

@camjocotem
Last active June 17, 2023 11:59
Show Gist options
  • Select an option

  • Save camjocotem/e957b6f843104467fd521b89cd5a56f0 to your computer and use it in GitHub Desktop.

Select an option

Save camjocotem/e957b6f843104467fd521b89cd5a56f0 to your computer and use it in GitHub Desktop.
Remove Reddit Promotional Tweets (To use with Javascript extension such as Custom Javascript For Websites 2)
function findTopPostElement(el){
if(isTopPostElement(el)){
return el;
}
else{
return findTopPostElement(el.parentElement);
}
}
function isTopPostElement(el){
if(el.classList.length === 0 && el.parentElement.classList.length > 0){
return true;
}
}
function removePromotedElements() {
let promotedElements = getPromotedElements();
promotedElements.forEach(function (el) {
let topPostElement = findTopPostElement(el);
topPostElement.style.display = 'none';
})
}
document.onscroll = function(){
removePromotedElements()
}
function getPromotedElements() {
return [].slice.call(document.getElementsByTagName('span')).filter(function (el) {
if(el.innerText){
return el.innerText.toLowerCase() === 'promoted'
}
})
}
removePromotedElements()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment