@@ -82,7 +82,7 @@ function start(maxPosts, waitMin, waitMax) {
8282 const btns = Array . from ( document . querySelectorAll ( selector ) ) ;
8383
8484 if ( ! btns . length ) {
85- alert ( "Không tìm thấy bài nào" ) ;
85+ alert ( "Không tìm thấy người nào để mời " ) ;
8686 return ;
8787 }
8888
@@ -101,12 +101,16 @@ function start(maxPosts, waitMin, waitMax) {
101101 count : 0 ,
102102 } ;
103103
104+ let container ;
104105 while ( window . fb_group_ext . count < maxPosts && ! window . fb_group_ext . stop ) {
105106 if ( btns . length > 0 ) {
106107 const btn = btns . shift ( ) ;
107108
109+ container = findParent ( btn , ".html-div" ) ?. children ?. [ 0 ] ;
110+ console . log ( container ) ;
111+
108112 btn . scrollIntoView ( { block : "start" , behavior : "smooth" } ) ;
109- console . log ( "click" , btn ) ;
113+ // console.log("click", btn);
110114 btn . click ( ) ;
111115
112116 window . fb_group_ext . count ++ ;
@@ -115,18 +119,26 @@ function start(maxPosts, waitMin, waitMax) {
115119 await sleep ( waitTime , ( ) => window . fb_group_ext . stop ) ;
116120 } else {
117121 // scroll to end
118- window . scrollTo ( 0 , document . body . scrollHeight ) ;
122+ if ( container ) container . scrollTo ( 0 , container . scrollHeight ) ;
123+ else window . scrollTo ( 0 , document . body . scrollHeight ) ;
124+
119125 // wait for load more
120126 await sleep ( 1000 ) ;
121127 }
122128 }
123129
124130 window . fb_group_ext . running = false ;
125- alert ( "Duyệt xong " + window . fb_group_ext . count + " bài " ) ;
131+ alert ( "Mời xong " + window . fb_group_ext . count + " người " ) ;
126132 }
127133
128134 main ( ) ;
129135
136+ function findParent ( ele , selector ) {
137+ if ( ! ele ) return null ;
138+ if ( ele . matches ( selector ) ) return ele ;
139+ return findParent ( ele . parentElement , selector ) ;
140+ }
141+
130142 function ranInt ( min , max ) {
131143 return Math . floor ( Math . random ( ) * ( max - min ) + min ) ;
132144 }
0 commit comments