Skip to content

Commit 30ffbf9

Browse files
committed
feat: add mangaoh provider
1 parent 1f07f5a commit 30ffbf9

File tree

3 files changed

+47
-7
lines changed

3 files changed

+47
-7
lines changed
+43-3
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,57 @@
11
import type { Detail, SearchResult, SearchOptions } from '../types';
22

3+
import { JSDOM } from 'jsdom';
4+
import { ofetch } from 'ofetch';
5+
36
import { Provider } from '../scraper';
47

58
export class Mangaoh extends Provider {
69
constructor() {
7-
super('mangaoh', '');
10+
super('mangaoh', 'https://www.mangaoh.co.jp');
811
}
912

1013
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+
});
1232
}
1333

1434
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+
};
1656
}
1757
}

packages/get-bonus/src/melonbooks/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export class Melonbooks extends Provider {
1111
}
1212

1313
async search(text: string, options: SearchOptions): Promise<SearchResult[]> {
14-
const html: string = await ofetch(this.baseUrl + '/search/search.php', {
14+
const html = await ofetch(this.baseUrl + '/search/search.php', {
1515
query: {
1616
name: text,
1717
'additional[]': 'pr',
@@ -35,7 +35,7 @@ export class Melonbooks extends Provider {
3535
}
3636

3737
async detail(url: string): Promise<Detail | undefined> {
38-
const html: string = await ofetch(url);
38+
const html = await ofetch(url);
3939
const dom = new JSDOM(html);
4040
const doc = dom.window.document;
4141

packages/get-bonus/src/toranoana/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export class Toranoana extends Provider {
1111
}
1212

1313
async search(text: string, options: SearchOptions): Promise<SearchResult[]> {
14-
const html: string = await ofetch(this.baseUrl + '/tora/ec/app/catalog/list', {
14+
const html = await ofetch(this.baseUrl + '/tora/ec/app/catalog/list', {
1515
query: {
1616
searchWord: text,
1717
stock_status: '○,△'
@@ -34,7 +34,7 @@ export class Toranoana extends Provider {
3434
}
3535

3636
async detail(url: string): Promise<Detail | undefined> {
37-
const html: string = await ofetch(url);
37+
const html = await ofetch(url);
3838
const dom = new JSDOM(html);
3939
const doc = dom.window.document;
4040

0 commit comments

Comments
 (0)