2022-02-11 17:24:33 +00:00
|
|
|
export class SubstackHandler {
|
|
|
|
|
name = 'substack'
|
|
|
|
|
|
2022-05-10 09:01:23 +00:00
|
|
|
shouldPrehandle = (url: URL, dom: Document): boolean => {
|
2022-02-11 17:24:33 +00:00
|
|
|
const host = this.name + '.com'
|
|
|
|
|
// check if url ends with substack.com
|
|
|
|
|
// or has a profile image hosted at substack.com
|
|
|
|
|
return (
|
|
|
|
|
url.hostname.endsWith(host) ||
|
2022-05-10 09:01:23 +00:00
|
|
|
!!dom
|
2022-02-11 17:24:33 +00:00
|
|
|
.querySelector('.email-body img')
|
|
|
|
|
?.getAttribute('src')
|
|
|
|
|
?.includes(host)
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-10 09:01:23 +00:00
|
|
|
prehandle = (url: URL, dom: Document): Promise<Document> => {
|
|
|
|
|
const body = dom.querySelector('.email-body-container')
|
2022-02-11 17:24:33 +00:00
|
|
|
|
|
|
|
|
// this removes header and profile avatar
|
|
|
|
|
body?.querySelector('.header')?.remove()
|
|
|
|
|
body?.querySelector('.preamble')?.remove()
|
|
|
|
|
body?.querySelector('.meta-author-wrap')?.remove()
|
|
|
|
|
// this removes meta button
|
|
|
|
|
body?.querySelector('.post-meta')?.remove()
|
|
|
|
|
// this removes footer
|
|
|
|
|
body?.querySelector('.post-cta')?.remove()
|
|
|
|
|
body?.querySelector('.container-border')?.remove()
|
|
|
|
|
body?.querySelector('.footer')?.remove()
|
|
|
|
|
|
|
|
|
|
return Promise.resolve(dom)
|
|
|
|
|
}
|
|
|
|
|
}
|