@@ -24,35 +24,30 @@ class NovelNaverParser extends Parser{
2424
2525 async getChapterUrls ( dom , chapterUrlsUI ) {
2626 let chapters = this . extractPartialChapterList ( dom ) ;
27- let urlsOfTocPages = this . extractTocPageUrls ( dom ) ;
27+ let urlsOfTocPages = await this . extractTocPageUrls ( dom ) ;
2828 return ( await this . getChaptersFromAllTocPages ( chapters ,
29- this . extractPartialChapterList , urlsOfTocPages , chapterUrlsUI ) ) . reverse ( ) ;
29+ this . extractPartialChapterList , urlsOfTocPages , chapterUrlsUI ) ) ;
3030 }
3131
32- extractTocPageUrls ( dom ) {
33- let tocLinks = [ ...dom . querySelectorAll ( "div.paging a:not(.paging_next)" ) ] ;
34- let pages = tocLinks
35- . map ( a => a . textContent ) ;
36- if ( pages . length <= 1 ) {
37- return [ ] ;
38- }
39- let max = parseInt ( pages . pop ( ) ) ;
40- let baseUrl = tocLinks [ 0 ] . href ;
41- baseUrl = baseUrl . substring ( 0 , baseUrl . length - 1 ) ;
42-
43- // might be more ToC pages than given in paging control
44- // so check against num chapters
45- let volume = dom . querySelector ( "div.cont_sub > ul.list_type2 li.volumeComment" ) ;
46- if ( volume != null ) {
47- let maxChapters = parseInt ( volume . getAttribute ( "value" ) ) ;
48- max = Math . floor ( maxChapters + 9 ) / 10 ;
32+ async extractTocPageUrls ( dom ) {
33+ let found = new Set ( ) ;
34+ let urls = this . extractPartialTocPages ( dom , found ) ;
35+ let nextTocPageUrl = null ;
36+ while ( ( nextTocPageUrl = dom . querySelector ( "div.default_paging a.ico_next" ) ?. href ) != null ) {
37+ dom = ( await HttpClient . wrapFetch ( nextTocPageUrl ) ) . responseXML ;
38+ urls = urls . concat ( this . extractPartialTocPages ( dom , found ) ) ;
4939 }
40+ return urls ;
41+ }
5042
51- let tocUrls = [ ] ;
52- for ( let i = 2 ; i <= max ; ++ i ) {
53- tocUrls . push ( baseUrl + i ) ;
43+ extractPartialTocPages ( dom , found ) {
44+ let urls = [ ...dom . querySelectorAll ( "div.default_paging a" ) ]
45+ . map ( l => l . href )
46+ . filter ( u => ! found . has ( u ) ) ;
47+ for ( let u of urls ) {
48+ found . add ( u ) ;
5449 }
55- return tocUrls ;
50+ return urls ;
5651 }
5752
5853 extractPartialChapterList ( dom ) {
@@ -77,6 +72,6 @@ class NovelNaverParser extends Parser{
7772 }
7873
7974 getInformationEpubItemChildNodes ( dom ) {
80- return [ ...dom . querySelectorAll ( "div.section_area_info p.dsc " ) ] ;
75+ return [ ...dom . querySelectorAll ( "#summaryText " ) ] ;
8176 }
8277}
0 commit comments