@@ -4,10 +4,14 @@ import { For, Show } from 'solid-js';
44import { createStore } from 'solid-js/store' ;
55import { render } from 'solid-js/web' ;
66
7- import { fileType , hijackFn , querySelector , querySelectorAll , t } from 'helper' ;
7+ import { hijackFn , querySelector , querySelectorAll , t } from 'helper' ;
88import { request , toast } from 'main' ;
99
10- import { searchNhentai } from '../../userscript/nhentaiApi' ;
10+ import {
11+ getNhentaiData ,
12+ searchNhentai ,
13+ toImgList ,
14+ } from '../../userscript/nhentaiApi' ;
1115import { type GalleryContext , isInCategories } from './helper' ;
1216
1317type ItemData = {
@@ -23,39 +27,44 @@ type SiteFn = {
2327 errorTip : ( context : GalleryContext ) => string ;
2428} ;
2529
26- const nhentai : SiteFn = async ( { setState, galleryTitle } ) => {
27- const downImg = async ( i : number , media_id : string , type : string ) => {
28- const imgRes = await request < Blob > (
29- `https://i.nhentai.net/galleries/${ media_id } /${ i + 1 } .${ fileType [ type ] } ` ,
30- {
31- headers : { Referer : `https://nhentai.net/g/${ media_id } ` } ,
32- responseType : 'blob' ,
33- fetch : false ,
34- } ,
35- ) ;
36- return URL . createObjectURL ( imgRes . response ) ;
37- } ;
38-
30+ const nhentai : SiteFn = async ( { setState, galleryTitle, galleryId } ) => {
3931 const result = await searchNhentai ( galleryTitle ! ) ;
40- return result . map ( ( { id, title, images, num_pages, media_id } ) => {
41- const itemId = `@nh:${ id } ` ;
42- setState ( 'comicMap' , itemId , {
43- getImgList : ( { dynamicLazyLoad } ) =>
44- dynamicLazyLoad ( {
45- loadImg : ( i ) => downImg ( i , media_id , images . pages [ i ] . t ) ,
46- length : num_pages ,
47- id : itemId ,
48- } ) ,
49- } ) ;
32+ return result
33+ . map ( ( { id, english_title, japanese_title, media_id } ) => {
34+ const itemId = `@nh:${ id } ` ;
5035
51- return {
52- id : itemId ,
53- showText : `${ id } ` ,
54- title : title . english || title . japanese ,
55- href : `https://nhentai.net/g/${ id } ` ,
56- class : 'gtl' ,
57- } ;
58- } ) ;
36+ setState ( 'comicMap' , itemId , {
37+ getImgList : async ( { dynamicLazyLoad } ) => {
38+ const galleryData = await getNhentaiData ( `${ id } ` ) ;
39+ const imgList = toImgList ( galleryData ) ;
40+ return dynamicLazyLoad ( {
41+ loadImg : async ( i ) => {
42+ const imgRes = await request < Blob > ( imgList [ i ] . src , {
43+ headers : { Referer : `https://nhentai.net/g/${ id } ` } ,
44+ responseType : 'blob' ,
45+ fetch : false ,
46+ } ) ;
47+ return URL . createObjectURL ( imgRes . response ) ;
48+ } ,
49+ length : imgList . length ,
50+ id : itemId ,
51+ } ) ;
52+ } ,
53+ } ) ;
54+
55+ return {
56+ id : itemId ,
57+ showText : `${ id } ` ,
58+ title : japanese_title || english_title ,
59+ href : `https://nhentai.net/g/${ id } ` ,
60+ class : `${ galleryId } ` === media_id ? 'gt' : 'gtl' ,
61+ } ;
62+ } )
63+ . sort (
64+ ( a , b ) =>
65+ ( a . class === 'gt' ? 0 : 1 ) - ( b . class === 'gt' ? 0 : 1 ) ||
66+ Number ( b . showText ) - Number ( a . showText ) ,
67+ ) ;
5968} ;
6069nhentai . errorTip = ( context ) =>
6170 t ( 'site.ehentai.nhentai_failed' , {
0 commit comments