Last active
August 13, 2019 12:44
-
-
Save ToreJuloe/7faad1a25fe321b4087cb65087c37970 to your computer and use it in GitHub Desktop.
Remove click-bait on BT
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() { | |
const setContent = element => nodesArray => { | |
element.innerText = ""; | |
nodesArray.forEach(node => { | |
element.appendChild(node); | |
}); | |
}; | |
const parseHTML = text => new DOMParser().parseFromString(text, "text/html"); | |
const getElements = selectorArray => doc => | |
selectorArray.map(el => doc.querySelector(el)); | |
document.querySelectorAll(".dre-item__title").forEach(el => | |
fetch(el.href) | |
.then(response => response.text()) | |
.then(parseHTML) | |
.then( | |
getElements(["h1.article-title", ".article-content>p:first-of-type"]) | |
) | |
.then(setContent(el))); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment