Merge pull request #2208 from omnivore-app/wechat-handler

Add content handler for weixin.qq.com
This commit is contained in:
Hongbo Wu
2023-05-16 15:09:56 +08:00
committed by GitHub
2 changed files with 34 additions and 0 deletions

View File

@ -33,6 +33,7 @@ import { ScrapingBeeHandler } from './websites/scrapingBee-handler'
import { StackOverflowHandler } from './websites/stack-overflow-handler'
import { TDotCoHandler } from './websites/t-dot-co-handler'
import { TwitterHandler } from './websites/twitter-handler'
import { WeixinQqHandler } from './websites/weixin-qq-handler'
import { WikipediaHandler } from './websites/wikipedia-handler'
import { YoutubeHandler } from './websites/youtube-handler'
@ -75,6 +76,7 @@ const contentHandlers: ContentHandler[] = [
new StackOverflowHandler(),
new EnergyWorldHandler(),
new PipedVideoHandler(),
new WeixinQqHandler(),
]
const newsletterHandlers: ContentHandler[] = [

View File

@ -0,0 +1,32 @@
import { ContentHandler } from '../content-handler'
export class WeixinQqHandler extends ContentHandler {
constructor() {
super()
this.name = 'Weixin QQ'
}
shouldPreParse(url: string, dom: Document): boolean {
return new URL(url).hostname.endsWith('weixin.qq.com')
}
async preParse(url: string, dom: Document): Promise<Document> {
// This replace the class name of the article info to preserve the block
dom
.querySelector('.rich_media_meta_list')
?.setAttribute('class', '_omnivore_rich_media_meta_list')
// This removes the title
dom.querySelector('.rich_media_title')?.remove()
// This removes the profile info
dom.querySelector('.profile_container')?.remove()
// This removes the footer
dom.querySelector('#content_bottom_area')?.remove()
dom.querySelector('.rich_media_area_extra')?.remove()
dom.querySelector('#js_pc_qr_code')?.remove()
return Promise.resolve(dom)
}
}