|
1 | 1 | import type { Detail, SearchResult, SearchOptions } from '../types';
|
2 | 2 |
|
| 3 | +import { JSDOM } from 'jsdom'; |
| 4 | +import { ofetch } from 'ofetch'; |
| 5 | + |
3 | 6 | import { Provider } from '../scraper';
|
4 | 7 |
|
5 | 8 | export class Mangaoh extends Provider {
|
6 | 9 | constructor() {
|
7 |
| - super('mangaoh', ''); |
| 10 | + super('mangaoh', 'https://www.mangaoh.co.jp'); |
8 | 11 | }
|
9 | 12 |
|
10 | 13 | async search(text: string, options: SearchOptions): Promise<SearchResult[]> {
|
11 |
| - return []; |
| 14 | + const html = await ofetch(this.baseUrl + '/search', { |
| 15 | + query: { |
| 16 | + q: text + ' +特典' |
| 17 | + } |
| 18 | + }); |
| 19 | + |
| 20 | + const dom = new JSDOM(html); |
| 21 | + const doc = dom.window.document; |
| 22 | + |
| 23 | + const resultItems = doc.querySelectorAll('.result-card'); |
| 24 | + return [...resultItems].map((item) => { |
| 25 | + const a = item.querySelector('.prd_name') as HTMLAnchorElement; |
| 26 | + return { |
| 27 | + provider: this.id, |
| 28 | + title: a.textContent?.trim?.() || '', |
| 29 | + url: this.baseUrl + a.href |
| 30 | + }; |
| 31 | + }); |
12 | 32 | }
|
13 | 33 |
|
14 | 34 | async detail(url: string): Promise<Detail | undefined> {
|
15 |
| - return undefined; |
| 35 | + const html = await ofetch(url); |
| 36 | + const dom = new JSDOM(html); |
| 37 | + const doc = dom.window.document; |
| 38 | + |
| 39 | + const title = doc.querySelector('.product-name'); |
| 40 | + const imgs = doc.querySelectorAll('.thickbox > img'); |
| 41 | + const descs = doc |
| 42 | + .querySelector('.thickbox:last-of-type') |
| 43 | + ?.nextElementSibling?.textContent?.split?.('+'); |
| 44 | + |
| 45 | + const items = [...imgs].map((img, i) => ({ |
| 46 | + image: (img as HTMLImageElement).src, |
| 47 | + description: descs?.[i] || '' |
| 48 | + })); |
| 49 | + |
| 50 | + return { |
| 51 | + provider: this.id, |
| 52 | + title: title?.textContent?.trim() || '', |
| 53 | + url, |
| 54 | + items |
| 55 | + }; |
16 | 56 | }
|
17 | 57 | }
|
0 commit comments