11/* eslint-disable i18next/no-literal-string */
2+ import { render } from 'solid-js/web' ;
23import { For , type Component , Show } from 'solid-js' ;
3- import { request , useInit } from 'main' ;
4+ import { request , toast , useInit } from 'main' ;
45import {
56 querySelectorClick ,
67 wait ,
78 querySelector ,
89 querySelectorAll ,
910 log ,
1011} from 'helper' ;
11- import { render } from 'solid-js/web' ;
1212
1313// API 参考:https://github.com/fumiama/copymanga/blob/279e08b06a70307bf20162900103ec1fdcb97751/app/src/main/res/values/strings.xml
1414
15- const headers = {
16- webp : '1' ,
17- region : '1' ,
18- 'User-Agent' : 'COPY/2.0.7|' ,
19- version : '2.0.7' ,
20- source : 'copyApp' ,
21- referer : 'com.copymanga.app-2.0.7' ,
22- } ;
15+ const mobileApi = new ( class {
16+ headers = {
17+ webp : '1' ,
18+ region : '1' ,
19+ 'User-Agent' : 'COPY/2.0.7|' ,
20+ version : '2.0.7' ,
21+ source : 'copyApp' ,
22+ referer : 'com.copymanga.app-2.0.7' ,
23+ } ;
24+
25+ get : typeof request = async ( url , details , ...args ) =>
26+ request (
27+ url ,
28+ { responseType : 'json' , headers : this . headers , ...details } ,
29+ ...args ,
30+ ) ;
31+ } ) ( ) ;
32+
33+ const pcApi = new ( class {
34+ headers = { 'User-Agent' : navigator . userAgent , referer : location . href } ;
35+
36+ get : typeof request = async ( url , details , ...args ) =>
37+ request (
38+ `https://mapi.copy20.com${ url } ` ,
39+ { responseType : 'json' , headers : this . headers , fetch : false , ...details } ,
40+ ...args ,
41+ ) ;
42+ } ) ( ) ;
2343
2444// 在目录页显示上次阅读记录
2545const handleLastChapter = ( comicName : string ) => {
@@ -45,11 +65,7 @@ const handleLastChapter = (comicName: string) => {
4565
4666 a . textContent = '獲取中' ;
4767 a . removeAttribute ( 'href' ) ;
48- const res = await request ( `/api/v3/comic2/${ comicName } /query?platform=3` , {
49- responseType : 'json' ,
50- fetch : false ,
51- headers,
52- } ) ;
68+ const res = await pcApi . get ( `/api/v3/comic2/${ comicName } /query?platform=3` ) ;
5369
5470 const data = res . response ?. results ?. browse ;
5571 if ( ! data ) {
@@ -88,12 +104,10 @@ type HiddenType = 'web' | 'mobile' | '404';
88104const buildChapters = async ( comicName : string , hiddenType : HiddenType ) => {
89105 const {
90106 response : { results } ,
91- } = await request < { results : string } > ( `/comicdetail/${ comicName } /chapters` , {
92- responseType : 'json' ,
93- errorText : '加載漫畫目錄失敗' ,
94- headers,
95- fetch : false ,
96- } ) ;
107+ } = await mobileApi . get < { results : string } > (
108+ `/comicdetail/${ comicName } /chapters` ,
109+ { errorText : '加載漫畫目錄失敗' } ,
110+ ) ;
97111
98112 interface ChaptersGroup {
99113 name : string ;
@@ -131,7 +145,7 @@ const buildChapters = async (comicName: string, hiddenType: HiddenType) => {
131145
132146 const data = await decryptData (
133147 results . slice ( 16 ) ,
134- unsafeWindow . dio || 'xxxmanga.woo .key' ,
148+ unsafeWindow . dio || 'xxymanga.zzl .key' ,
135149 results . slice ( 0 , 16 ) ,
136150 ) ;
137151 log ( data ) ;
@@ -352,7 +366,7 @@ const buildChapters = async (comicName: string, hiddenType: HiddenType) => {
352366 . split ( '; ' )
353367 . find ( ( cookie ) => cookie . startsWith ( 'token=' ) )
354368 ?. replace ( 'token=' , '' ) ;
355- if ( token ) Reflect . set ( headers , 'Authorization' , `Token ${ token } ` ) ;
369+ if ( token ) Reflect . set ( mobileApi . headers , 'Authorization' , `Token ${ token } ` ) ;
356370
357371 let comicName = '' ;
358372 let id = '' ;
@@ -383,15 +397,14 @@ const buildChapters = async (comicName: string, hiddenType: HiddenType) => {
383397 next : string | null ;
384398 prev : string | null ;
385399 } ;
386- comic : {
387- name : string ;
388- } ;
400+ comic : { name : string } ;
389401 } ;
390402 } ;
391- const res = await request < ResData > (
403+ const res = await pcApi . get < ResData > (
392404 `/api/v3/comic/${ comicName } /chapter2/${ id } ?platform=3` ,
393- { responseType : 'json' , headers , noCheckCode : true } ,
405+ { noCheckCode : true } ,
394406 ) ;
407+
395408 if ( res . status !== 200 ) {
396409 const message = `漫畫加載失敗:${ res . response . message || res . status } ` ;
397410 if ( titleDom ) titleDom . textContent = message ;
@@ -441,9 +454,9 @@ const buildChapters = async (comicName: string, hiddenType: HiddenType) => {
441454
442455 const getCommentList = async ( ) => {
443456 const chapter_id = window . location . pathname . split ( '/' ) . at ( - 1 ) ;
444- const res = await request (
457+ const res = await pcApi . get (
445458 `/api/v3/roasts?chapter_id=${ chapter_id } &limit=100&offset=0&_update=true` ,
446- { responseType : 'json' , errorText : '获取漫画评论失败' } ,
459+ { errorText : '获取漫画评论失败' } ,
447460 ) ;
448461 return res . response . results . list . map (
449462 ( { comment } ) => comment as string ,
@@ -510,7 +523,13 @@ const buildChapters = async (comicName: string, hiddenType: HiddenType) => {
510523 titleDom . textContent =
511524 'ComicRead 提示您:你訪問的內容暫不存在,請坐和放寬,等待目錄生成' ;
512525 }
513- await buildChapters ( comicName , hiddenType ) ;
526+
527+ try {
528+ await buildChapters ( comicName , hiddenType ) ;
529+ } catch {
530+ if ( titleDom ) titleDom . textContent = 'ComicRead 提示您:目錄生成失敗😢' ;
531+ toast . error ( '目錄生成失敗😢' , { duration : Number . POSITIVE_INFINITY } ) ;
532+ }
514533 }
515534
516535 if ( ! isMobile && token ) handleLastChapter ( comicName ) ;
0 commit comments