@@ -15,19 +15,33 @@ function listChapters(query) {
1515 try {
1616 var searchResp = mango . get ( SEARCH_URL + encodeURI ( query ) + SEARCH_PARAMS ) . body ;
1717 var search = JSON . parse ( searchResp ) ;
18- var mangaID = search [ "items" ] [ 0 ] [ 0 ] [ 3 ] ;
1918 } catch ( error ) {
20- mango . raise ( "Could not find a webtoon with that title ." ) ;
19+ mango . raise ( "An error occured while searching ." ) ;
2120 }
2221
23- if ( ! mangaID ) mango . raise ( "Could not get webtoon ID." ) ;
22+ if ( search [ "items" ] . length == 0 ) mango . raise ( "Could not find a webtoon with that title." ) ;
23+
24+ var mangaID ;
25+ for ( var i = 0 ; i < search [ "items" ] [ 0 ] . length ; i ++ ) {
26+ var item = search [ "items" ] [ 0 ] [ i ] ;
27+
28+ // Get first webtoon, ignore authors
29+ if ( item [ 1 ] [ 0 ] == "TITLE" ) {
30+ mangaID = item [ 3 ] [ 0 ] ;
31+ break ;
32+ }
33+ }
34+
35+ if ( ! mangaID ) mango . raise ( "Could not find a webtoon with that title." ) ;
2436
2537 try {
2638 var resp = mango . get ( BASE_URL + LIST_ENDPOINT + mangaID ) ;
2739 var urlLocation = resp . headers . Location ;
2840 } catch ( error ) {
2941 mango . raise ( "Could not get webtoon page." ) ;
3042 }
43+
44+ if ( ! urlLocation ) mango . raise ( "Could not get webtoon page." ) ;
3145
3246 chapters = [ ] ;
3347 var html = mango . get ( MOBILE_URL + urlLocation , {
@@ -43,7 +57,7 @@ function listChapters(query) {
4357 liChapters . forEach ( function ( chapter ) {
4458 var url = mango . attribute ( mango . css ( chapter , "a" ) [ 0 ] , 'href' ) ;
4559
46- var chapterIDRegex = / w e b t o o n s \. c o m \/ \w { 2 } \/ \w + \/ ( \w - ? ) + \/ ( .+ ) \/ / ;
60+ var chapterIDRegex = / w e b t o o n s \. c o m \/ \w { 2 } \/ . + \/ ( \w - ? ) + \/ ( .+ ) \/ / ;
4761 var chapterIDMatch = chapterIDRegex . exec ( url ) ;
4862
4963 var chapterID ;
0 commit comments