1+ const SEARCH_URL = "https://manganato.com/search/story/" ;
2+ const MAIN_URL = "https://readmanganato.com/" ;
3+ const ALT_URL = "https://manganato.com/" ;
4+
5+ function searchManga ( query ) {
6+ const res = mango . get ( SEARCH_URL + query . replace ( " " , "_" ) ) ;
7+ if ( res . status_code !== 200 )
8+ mango . raise ( 'Failed to search for manga. Status ' + res . status_code ) ;
9+ const manga = mango . css ( res . body , "div.search-story-item" ) ;
10+
11+ return JSON . stringify ( manga . map ( function ( m ) {
12+ const ch = {
13+ id : mango . attribute ( mango . css ( m , "a.item-title" ) [ 0 ] , "href" ) . split ( "/" ) . pop ( ) ,
14+ title : mango . text ( mango . css ( m , "a.item-title" ) [ 0 ] ) ,
15+ cover_url : mango . attribute ( mango . css ( m , "img.img-loading" ) [ 0 ] , "src" )
16+ } ;
17+ return ch ;
18+ } ) ) ;
19+ }
20+
21+ function getManga ( id ) {
22+ var res = mango . get ( MAIN_URL + id ) ;
23+ if ( res . status_code !== 200 )
24+ res = mango . get ( ALT_URL + id ) ;
25+ if ( res . status_code !== 200 )
26+ mango . raise ( 'Failed to get item from ' + MAIN_URL + ' & ' + ALT_URL + '.' ) ;
27+ return res ;
28+ }
29+
30+ function listChapters ( id ) {
31+ const res = getManga ( id ) ;
32+ if ( res . status_code !== 200 )
33+ mango . raise ( 'Failed to get chapters. Status ' + res . status_code ) ;
34+ const mangaTitle = mango . text ( mango . css ( res . body , "div.story-info-right h1" ) [ 0 ] ) ;
35+ const manga = mango . css ( res . body , "div.panel-story-chapter-list li.a-h" ) ;
36+
37+ return JSON . stringify ( manga . map ( function ( m ) {
38+ //const chapter = getManga(id + '/' + mango.attribute(mango.css(m, "a.chapter-name")[0], "href").split("/").pop());
39+ //const pages = mango.css(chapter.body, "div.container-chapter-reader img");
40+
41+ const obj = {
42+ id : id + '/' + mango . attribute ( mango . css ( m , "a.chapter-name" ) [ 0 ] , "href" ) . split ( "/" ) . pop ( ) ,
43+ title : mango . text ( mango . css ( m , "a.chapter-name" ) [ 0 ] ) ,
44+ manga_title : mangaTitle ,
45+ //pages: pages.length,
46+ pages : 0 ,
47+ chapter : mango . attribute ( mango . css ( m , "a.chapter-name" ) [ 0 ] , "href" ) . split ( "-" ) . pop ( ) ,
48+ language : "en" ,
49+ group_id : id ,
50+ published_at : Date . parse ( parseTime ( mango . css ( m , "span.chapter-time" ) [ 0 ] ) )
51+ } ;
52+ return obj ;
53+ } ) ) ;
54+ }
55+
56+ function parseTime ( time ) {
57+ const months = [ "Jan" , "Feb" , "Mar" , "Apr" , "May" , "Jun" , "Jul" , "Aug" , "Sep" , "Oct" , "Nov" , "Dec" ] ;
58+ const date = mango . attribute ( time , "title" ) ;
59+ const month = date . split ( " " ) [ 0 ] ;
60+ const day = date . split ( " " ) [ 1 ] . split ( "," ) [ 0 ] ;
61+ const year = date . split ( " " ) [ 1 ] . split ( "," ) [ 1 ] ;
62+ return year + "-" + months . indexOf ( month ) + "-" + day ;
63+ }
64+
65+ function selectChapter ( id ) {
66+ var mangaId = id . split ( "/" ) [ 0 ] . toString ( ) ;
67+ const manga = getManga ( mangaId ) ;
68+ if ( manga . status_code !== 200 )
69+ mango . raise ( 'Failed to get the manger.' ) ;
70+ const mangaTitle = mango . text ( mango . css ( manga . body , "div.story-info-right h1" ) [ 0 ] ) ;
71+ const chapters = mango . css ( manga . body , "div.panel-story-chapter-list li.a-h" ) ;
72+
73+ const chapter = getManga ( id ) ;
74+ if ( chapter . status_code !== 200 )
75+ mango . raise ( 'Failed to get chapter. Status ' + res . status_code ) ;
76+ const imageUrls = mango . css ( chapter . body , "div.container-chapter-reader img" ) . map ( function ( img ) {
77+ return mango . attribute ( img , "src" ) ;
78+ } ) ;
79+ mango . storage ( "manga-image-data" , JSON . stringify ( imageUrls ) ) ;
80+ mango . storage ( "manga-title" , mangaTitle ) ;
81+ mango . storage ( "page" , "0" ) ;
82+
83+ const obj = chapters . map ( function ( c ) {
84+ return obj = {
85+ id : mangaId + "/" + mango . attribute ( mango . css ( c , "a.chapter-name" ) [ 0 ] , "href" ) . split ( "/" ) . pop ( ) ,
86+ title : mangaTitle + " - " + mango . text ( mango . css ( c , "a.chapter-name" ) [ 0 ] ) ,
87+ manga_title : mangaTitle ,
88+ pages : imageUrls . length ,
89+ chapter : id . split ( "-" ) . pop ( ) ,
90+ language : "en" ,
91+ group_id : mangaId ,
92+ published_at : Date . parse ( parseTime ( mango . css ( c , "span.chapter-time" ) [ 0 ] ) )
93+ } ;
94+ } ) ;
95+
96+ return JSON . stringify ( obj . filter ( function ( f ) {
97+ return f . id == id ;
98+ } ) . pop ( ) ) ;
99+ }
100+
101+ function nextPage ( ) {
102+ const page = parseInt ( mango . storage ( "page" ) ) ;
103+ const urls = JSON . parse ( mango . storage ( "manga-image-data" ) ) ;
104+ const filename = page + '.jpg' ;
105+ if ( page >= urls . length ) return JSON . stringify ( { } ) ;
106+
107+ const len = urls . length . toString ( ) . length ;
108+ const pageNum = Array ( Math . max ( len - String ( page + 1 ) . length + 1 , 0 ) ) . join ( 0 ) + ( page + 1 ) ;
109+ const finalFilename = pageNum + '.' + filename . split ( '.' ) . pop ( ) ;
110+ mango . storage ( 'page' , ( page + 1 ) . toString ( ) ) ;
111+
112+ return JSON . stringify ( {
113+ url : urls [ page ] ,
114+ filename : finalFilename ,
115+ headers : {
116+ authority : 'v13.mkklcdnv6tempv4.com' ,
117+ accept : 'image/avif,image/webp,image/apng,image/svg+xml,image' ,
118+ pragma : 'no-cache' ,
119+ referer : 'https://readmanganato.com/'
120+ }
121+ } ) ;
122+ }
0 commit comments