Skip to content

Instantly share code, notes, and snippets.

@leonmak
Created October 17, 2022 06:12
Show Gist options
  • Save leonmak/4c3df3fc859f5d0084bb75f5c873a236 to your computer and use it in GitHub Desktop.
Save leonmak/4c3df3fc859f5d0084bb75f5c873a236 to your computer and use it in GitHub Desktop.
get-substack
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