| 46 | |
| 47 | const SUPPORTED_APPS = SERVICES |
| 48 | export class WebParser { |
| 49 | url: URL |
| 50 | |
| 51 | constructor(url: string) { |
| 52 | this.url = new URL(url) |
| 53 | } |
| 54 | |
| 55 | isSupportedApp() { |
| 56 | const hostname = this.url.hostname |
| 57 | const app = SUPPORTED_APPS.find((app) => app.matchHostname.test(hostname)) |
| 58 | |
| 59 | if (!app) return false |
| 60 | |
| 61 | const Parser = ParserModules[app.id as keyof typeof ParserModules] |
| 62 | if (!Parser) return false |
| 63 | |
| 64 | return true |
| 65 | } |
| 66 | |
| 67 | detectApp() { |
| 68 | const hostname = this.url.hostname |
| 69 | const app = SUPPORTED_APPS.find((app) => app.matchHostname.test(hostname)) |
| 70 | |
| 71 | return app ?? null |
| 72 | } |
| 73 | |
| 74 | createMetadataExtractor() { |
| 75 | return new MetadataExtractor(this.url) |
| 76 | } |
| 77 | |
| 78 | createAppParser() { |
| 79 | const hostname = this.url.hostname |
| 80 | const app = SUPPORTED_APPS.find((app) => app.matchHostname.test(hostname)) |
| 81 | |
| 82 | if (!app) return null |
| 83 | |
| 84 | const Parser = ParserModules[app.id as keyof typeof ParserModules] |
| 85 | if (!Parser) return null |
| 86 | |
| 87 | return new Parser(app, this.url) as WebAppExtractor |
| 88 | } |
| 89 | |
| 90 | useFallbackParser(document: Document) { |
| 91 | const articleParser = new ArticleParser(this.url) |
| 92 | |
| 93 | const isArticle = articleParser.isArticle(document) |
| 94 | console.log('Is article', isArticle) |
| 95 | |
| 96 | if (isArticle) { |
| 97 | return articleParser |
| 98 | } else { |
| 99 | return new LinkParser(this.url) |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | createWebviewExtractor(document: Document) { |
| 104 | return new WebViewExtractor(this.url, document) |
| 105 | } |
nothing calls this directly
no outgoing calls
no test coverage detected