Skip to content

Commit 13d45ae

Browse files
committed
fix: 🐛 修复 ehentai 匹配 hitomi 功能在 CG 类画廊上未启用的 bug
#243
1 parent 1be1ffa commit 13d45ae

4 files changed

Lines changed: 47 additions & 24 deletions

File tree

src/site/ehentai/crossSiteLink.tsx

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {
1414
} from 'helper';
1515
import { request, toast } from 'main';
1616

17-
import type { GalleryContext } from './helper';
17+
import { isInCategories, type GalleryContext } from './helper';
1818

1919
type ItemData = {
2020
id: string;
@@ -24,10 +24,12 @@ type ItemData = {
2424
class: string;
2525
};
2626

27-
const nhentai = async ({
28-
setState,
29-
galleryTitle,
30-
}: GalleryContext): Promise<ItemData[]> => {
27+
type SiteFn = {
28+
(context: GalleryContext): Promise<ItemData[]>;
29+
errorTip: (context: GalleryContext) => string;
30+
};
31+
32+
const nhentai: SiteFn = async ({ setState, galleryTitle }) => {
3133
type ComicInfo = {
3234
id: number;
3335
media_id: string;
@@ -93,15 +95,12 @@ const nhentai = async ({
9395
};
9496
});
9597
};
96-
nhentai.errorTip = (context: GalleryContext) =>
98+
nhentai.errorTip = (context) =>
9799
t('site.ehentai.nhentai_failed', {
98100
nhentai: `<a href='https://nhentai.net/search/?q=${context.galleryTitle}' target="_blank"> <u> nhentai </u> </a>`,
99101
});
100102

101-
const hitomi = async ({
102-
setState,
103-
galleryId,
104-
}: GalleryContext): Promise<ItemData[]> => {
103+
const hitomi = async ({ setState, galleryId }) => {
105104
const domain = 'gold-usergeneratedcontent.net';
106105

107106
const downImg = async (url: string) => {
@@ -174,11 +173,17 @@ hitomi.errorTip = () => t('site.ehentai.hitomi_error');
174173

175174
/** 关联外站 */
176175
export const crossSiteLink = async (context: GalleryContext) => {
177-
/** 只处理「Doujinshi」「Manga」 */
178-
if (!querySelector('#gdc > .cs:is(.ct2, .ct3)')) return;
179176
if (!context.galleryTitle)
180177
return toast.error(t('site.ehentai.html_changed_link_failed'));
181178

179+
// 根据当前分类判断要匹配哪些站点
180+
const siteList: SiteFn[] = [];
181+
if (isInCategories('Doujinshi', 'Manga', 'Artist CG', 'Game CG', 'Image Set'))
182+
siteList.push(hitomi);
183+
if (isInCategories('Doujinshi', 'Manga')) siteList.push(nhentai);
184+
185+
if (siteList.length === 0) return;
186+
182187
const [comicMap, setComicMap] = createStore<
183188
Record<string, ItemData[] | string>
184189
>({});
@@ -260,7 +265,7 @@ export const crossSiteLink = async (context: GalleryContext) => {
260265
});
261266

262267
// 获取外站数据
263-
for (const getSiteComic of [hitomi, nhentai]) {
268+
for (const getSiteComic of siteList) {
264269
setComicMap(getSiteComic.name, 'searching...');
265270
try {
266271
const itemList = await getSiteComic(context);

src/site/ehentai/helper/index.ts

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
import { querySelectorAll } from 'helper';
1+
import { querySelector, querySelectorAll } from 'helper';
2+
3+
export * from './context';
24

35
type EscHandler = { (): true | unknown; order: number }[];
46
export const escHandler: EscHandler = [];
@@ -59,4 +61,24 @@ export const getTagNameFull = (tag: string) => {
5961
return tag;
6062
};
6163

62-
export * from './context';
64+
/** 画廊分类图标对应的 class。在列表页是「.ct2」,在画廊里是「.gt2」 */
65+
const categoriesMap = {
66+
Western: 'ta',
67+
Misc: 't1',
68+
Doujinshi: 't2',
69+
Manga: 't3',
70+
'Artist CG': 't4',
71+
'Game CG': 't5',
72+
'Image Set': 't6',
73+
Cosplay: 't7',
74+
'Asian Porn': 't8',
75+
'Non-H': 't9',
76+
} as const;
77+
78+
/** 判断是否当前画廊是否是指定的分类 */
79+
export const isInCategories = (...name: (keyof typeof categoriesMap)[]) =>
80+
Boolean(
81+
querySelector(
82+
`#gdc > .cs:is(${name.map((c) => `.c${categoriesMap[c]}`).join(', ')})`,
83+
),
84+
);

src/site/ehentai/index.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ import { crossSiteLink } from './crossSiteLink';
3939
import { detectAd } from './detectAd';
4040
import { expandTagList } from './expandTagList';
4141
import { floatTagList } from './floatTagList';
42-
import { createEhContext, escHandler } from './helper';
42+
import { createEhContext, escHandler, isInCategories } from './helper';
4343
import { addHotkeysActions } from './hotkeys';
4444
import { quickFavorite } from './quickFavorite';
4545
import { quickRating } from './quickRating';
@@ -161,8 +161,7 @@ import { tagLint } from './tagLint';
161161
// 自动调整阅读配置
162162
if (
163163
options.auto_adjust_option &&
164-
// 在「Doujinshi」「Manga」「Non-H」以外的分类下
165-
!querySelector('#gdc > .cs:is(.ct2, .ct3, .ct9)')
164+
!isInCategories('Doujinshi', 'Manga', 'Non-H')
166165
) {
167166
let option: MangaProps['defaultOption'] = {
168167
// 使用单页模式

src/site/ehentai/tagLint.tsx

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ import {
2222

2323
import type { GalleryContext } from './helper';
2424

25-
import { getTaglist, getTagNameFull } from './helper';
25+
import { getTaglist, getTagNameFull, isInCategories } from './helper';
2626

2727
export const tagLint = ({ dom: { newTagField } }: GalleryContext) => {
2828
/** 是否是「Doujinshi」「Manga」「Non-H」 */
29-
const isManga = querySelector('#gdc > .cs:is(.ct2, .ct3, .ct9)');
29+
const isManga = isInCategories('Doujinshi', 'Manga', 'Non-H');
3030

3131
const lintRules = getTagLintRules();
3232
type RuleNames = keyof typeof lintRules;
@@ -157,10 +157,7 @@ export const tagLint = ({ dom: { newTagField } }: GalleryContext) => {
157157
addOtherWarn(t('eh_tag_lint.correct_tag'), correctTags);
158158

159159
// 涉及到图库类型的,比较复杂的检查
160-
if (
161-
querySelector('#gdc > .cs.ct2') &&
162-
isMissingNamespace(tagList, 'parody')
163-
)
160+
if (isInCategories('Doujinshi') && isMissingNamespace(tagList, 'parody'))
164161
addOtherWarn(t('eh_tag_lint.miss_parody'), ['parody:original']);
165162
if (
166163
isManga &&

0 commit comments

Comments
 (0)