11javascript:
2- if ( typeof ( loaded ) == "undefined" ) {
2+ if ( typeof ( loaded ) == "undefined" ) {
33 var loaded = true ;
44 function scanChapters ( chapter ) {
55 var chapterList = chapter . getElementsByClassName ( "tab-pane fade show active" ) [ 0 ] . getElementsByTagName ( "ul" ) [ 0 ] . getElementsByTagName ( "a" ) ;
66 var chapterArr = Array ( ) ;
7- for ( var i = 0 ; i < chapterList . length ; i ++ ) {
7+ for ( var i = 0 ; i < chapterList . length ; i ++ ) {
88 chapterArr . push ( JSON . constructor ( ) ) ;
99 chapterArr [ i ] [ "name" ] = chapterList [ i ] . title ;
1010 chapterArr [ i ] [ "url" ] = chapterList [ i ] . href ;
1111 }
1212 return chapterArr ;
1313 }
14+ function smoothLoadChapter ( speed , interval ) {
15+ let prevHeight = document . body . scrollHeight ;
16+ let lastTime = 0 ;
17+ let ticking = false ;
18+ function requestTick ( ) {
19+ if ( ! ticking ) {
20+ ticking = true ;
21+ requestAnimationFrame ( step ) ;
22+ }
23+ }
24+ function step ( timestamp ) {
25+ if ( ! lastTime ) lastTime = timestamp ;
26+ const elapsed = timestamp - lastTime ;
27+ if ( elapsed >= interval ) {
28+ const index = document . getElementsByClassName ( "comicIndex" ) [ 0 ] . innerText ;
29+ const count = document . getElementsByClassName ( "comicCount" ) [ 0 ] . innerText ;
30+ GM . setLoadingDialogProgress ( index , count ) ;
31+ window . scrollBy ( 0 , speed ) ;
32+ lastTime = timestamp ;
33+ const currentHeight = document . body . scrollHeight ;
34+ if ( Math . round ( window . innerHeight + window . scrollY + 0.5 ) >= currentHeight ) { /*避免小数不符无法触发*/
35+ if ( currentHeight === prevHeight ) {
36+ var images = document . getElementsByClassName ( "container-fluid comicContent" ) [ 0 ] . getElementsByTagName ( "li" ) ;
37+ var nextChapter = document . getElementsByClassName ( "comicContent-next" ) [ 0 ] . getElementsByTagName ( "a" ) [ 0 ] . href ;
38+ var prevChapter = document . getElementsByClassName ( "comicContent-prev" ) [ 1 ] . getElementsByTagName ( "a" ) [ 0 ] . href ;
39+ if ( nextChapter == location . href ) nextChapter = "null" ;
40+ if ( prevChapter == location . href ) prevChapter = "null" ;
41+ var result = document . title . split ( " - " ) [ 1 ] + " " + location . href . substring ( location . href . lastIndexOf ( "/" ) + 1 ) + "\n" + nextChapter + "\n" + prevChapter ;
42+ for ( var i = 0 ; i < images . length ; i ++ ) result += "\n" + images [ i ] . getElementsByTagName ( "img" ) [ 0 ] . dataset . src ;
43+ GM . setLoadingDialog ( false ) ;
44+ GM . loadChapter ( result ) ;
45+ return ;
46+ }
47+ prevHeight = currentHeight ;
48+ }
49+ }
50+ ticking = false ;
51+ requestTick ( ) ;
52+ }
53+ requestTick ( ) ;
54+ }
1455 function modify ( ) {
1556 var url = location . href ;
16- if ( url . indexOf ( "/chapter/" ) > 0 ) {
17- window . scroll ( { top : document . body . scrollHeight , left : 0 , behavior : 'smooth' } ) ;
18- setTimeout ( ( ) => {
19- window . scroll ( { top : document . body . scrollHeight , left : 0 , behavior : 'smooth' } ) ;
20- setTimeout ( ( ) => {
21- window . scroll ( { top : document . body . scrollHeight , left : 0 , behavior : 'smooth' } ) ;
22- setTimeout ( ( ) => {
23- window . scroll ( { top : document . body . scrollHeight , left : 0 , behavior : 'smooth' } ) ;
24- setTimeout ( ( ) => {
25- window . scroll ( { top : document . body . scrollHeight , left : 0 , behavior : 'smooth' } ) ;
26- var imglist = document . getElementsByClassName ( "container-fluid comicContent" ) [ 0 ] . getElementsByTagName ( "li" ) ;
27- var nextChapter = document . getElementsByClassName ( "comicContent-next" ) [ 0 ] . getElementsByTagName ( "a" ) [ 0 ] . href ;
28- var prevChapter = document . getElementsByClassName ( "comicContent-prev" ) [ 1 ] . getElementsByTagName ( "a" ) [ 0 ] . href ;
29- if ( nextChapter == location . href ) nextChapter = "null" ;
30- if ( prevChapter == location . href ) prevChapter = "null" ;
31- var liststr = document . title . split ( " - " ) [ 1 ] + " " + location . href . substring ( location . href . lastIndexOf ( "/" ) + 1 ) + "\n" + nextChapter + "\n" + prevChapter ;
32- for ( var i = 0 ; i < imglist . length ; i ++ ) liststr += "\n" + imglist [ i ] . getElementsByTagName ( "img" ) [ 0 ] . dataset . src ;
33- GM . loadChapter ( liststr ) ;
34- } , 500 ) ;
35- } , 500 ) ;
36- } , 500 ) ;
37- } , 500 ) ;
57+ if ( url . indexOf ( "/chapter/" ) > 0 ) {
58+ GM . setLoadingDialog ( true ) ;
59+ smoothLoadChapter ( 320 , 16 ) ;
3860 } else {
3961 var json = Array ( ) ;
4062 var chapters = document . getElementsByClassName ( "upLoop" ) [ 0 ] . children ;
@@ -55,4 +77,4 @@ if (typeof (loaded) == "undefined"){
5577 }
5678 }
5779 modify ( ) ;
58- } else modify ( ) ;
80+ } else modify ( ) ;
0 commit comments