Created
October 17, 2022 06:12
-
-
Save leonmak/4c3df3fc859f5d0084bb75f5c873a236 to your computer and use it in GitHub Desktop.
get-substack
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
const runner = ((links) => { | |
var parser = new DOMParser(); | |
links.forEach(async link => { | |
const resp = await fetch(link) | |
const text = await resp.text() | |
const doc = parser.parseFromString(text, "text/html"); | |
const title = doc.querySelector('.post-title').textContent; | |
const subtitle = doc.querySelector('.subtitle').textContent | |
const bodyHTML = doc.querySelector('.available-content').innerHTML; | |
const html = `<html> | |
<h1>${title}</h1> | |
<h2>${subtitle}</h2> | |
${bodyHTML} | |
</html>`; | |
const blob = new Blob([html], { type: 'text/html' }); | |
const e = document.createEvent('MouseEvents'); | |
const a = document.createElement('a'); | |
a.download = link.replace('https://newsletter.REPLACEME.com/p/','') + '.html'; | |
a.href = window.URL.createObjectURL(blob) | |
a.dataset.downloadurl = ['text/html', a.download, a.href].join(':') | |
e.initMouseEvent('click', true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null) | |
a.dispatchEvent(e) | |
}) | |
})(links) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment