Skip to content

Instantly share code, notes, and snippets.

@yakkomajuri
Last active July 4, 2020 20:02
Show Gist options
  • Save yakkomajuri/626c36739d2ec7f7e24d35c6299db7bd to your computer and use it in GitHub Desktop.
Save yakkomajuri/626c36739d2ec7f7e24d35c6299db7bd to your computer and use it in GitHub Desktop.
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