Last active
February 15, 2019 12:35
-
-
Save maury91/b6b30e7158896a69def366663846bdaf 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 realText(elem) { | |
if (elem instanceof Text) { | |
return elem.textContent; | |
} | |
const visibleText = [...elem.childNodes] | |
.filter(elem => elem instanceof Text || window.getComputedStyle(elem, "").display !== 'none') | |
.flatMap(elem => realText(elem)) | |
.join('') | |
return visibleText | |
} | |
function isSponsored(elem) { | |
return elem && realText(elem).toLowerCase().startsWith('sponsored') | |
} | |
function isArticleSponsored(elem) { | |
return isSponsored(elem.querySelector('div[id^=feed_subtitle]')) | |
} | |
const domInsertionObserver = new MutationObserver(function(mutationsList){ | |
[...mutationsList] | |
.filter(mutation => mutation.type === 'childList' && mutation.addedNodes.length) | |
.flatMap(mutation => [...mutation.addedNodes]) | |
.filter(addedNode => typeof addedNode.id === 'string' && addedNode.id.startsWith('u_fetchstream')) | |
.filter(isArticleSponsored) | |
.forEach(post => post.parentElement.removeChild(post)) | |
}); | |
domInsertionObserver.observe(document.querySelector('div[id^=feed_stream]'), { childList: true, subtree: true }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment