Last active
July 4, 2020 20:02
-
-
Save yakkomajuri/626c36739d2ec7f7e24d35c6299db7bd to your computer and use it in GitHub Desktop.
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
function removeAds() { | |
// Get all 'span' elements on the page | |
let spans = document.getElementsByTagName("span"); | |
for (let i = 0; i < spans.length; ++i) { | |
// Check if they contain the text 'Promoted' | |
if (spans[i].innerHTML === "Promoted") { | |
// Get the div that wraps around the entire ad | |
let card = spans[i].closest(".feed-shared-update-v2"); | |
// If the class changed and we can't find it with closest(), get the 6th parent | |
if (card === null) { | |
// Could also be card.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode :D | |
let j = 0; | |
card = spans[i]; | |
while (j < 6) { | |
card = card.parentNode; | |
++j; | |
} | |
} | |
// Make the ad disappear! | |
card.setAttribute("style", "display: none !important;"); | |
} | |
} | |
} | |
removeAds(); | |
// Ensures ads will be removed as the user scrolls | |
setInterval(function () { | |
removeAds(); | |
}, 100) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment