@@ -14,7 +14,7 @@ import {
1414} from 'helper' ;
1515import { request , toast } from 'main' ;
1616
17- import type { GalleryContext } from './helper' ;
17+ import { isInCategories , type GalleryContext } from './helper' ;
1818
1919type 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/** 关联外站 */
176175export 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 ) ;
0 commit comments