Last active
June 17, 2023 11:59
-
-
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)
This file contains hidden or 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
| 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