11import { UfsGlobal } from "./content-scripts/ufs_global.js" ;
2+ import { BADGES } from "./helpers/badge.js" ;
23import { hookFetch } from "./libs/ajax-hook/index.js" ;
34import { scrollToVeryEnd } from "./scrollToVeryEnd.js" ;
45
@@ -11,19 +12,21 @@ export default {
1112 description : {
1213 en : "Select and download all tiktok video (user profile, tiktok explore)." ,
1314 vi : "Tải hàng loạt video tiktok (trang người dùng, trang tìm kiếm), có giao diện chọn video muốn tải." ,
14- img : "/scripts/tiktok_batchDownload.jpg " ,
15+ img : "/scripts/tiktok_batchDownload.png " ,
1516 } ,
16-
17+ badges : [ BADGES . new , BADGES . hot ] ,
1718 changeLogs : {
1819 "2024-04-27" : "fix bug - use snaptik" ,
1920 "2024-05-16" : "fix style" ,
21+ "2024-07-28" : "re-build hook fetch" ,
2022 } ,
2123
2224 whiteList : [ "https://www.tiktok.com/*" ] ,
2325
2426 pageScript : {
2527 onDocumentStart : async ( ) => {
2628 const CACHED = {
29+ hasNew : true ,
2730 videoById : new Map ( ) ,
2831 } ;
2932
@@ -39,8 +42,10 @@ export default {
3942
4043 if ( json ?. itemList ) {
4144 json . itemList . forEach ( ( _ ) => {
42- if ( _ . video . playAddr || _ . imagePost ?. images ?. length )
45+ if ( _ . video . playAddr || _ . imagePost ?. images ?. length ) {
4346 CACHED . videoById . set ( _ . video . id , _ ) ;
47+ CACHED . hasNew = true ;
48+ }
4449
4550 if ( _ . imagePost ?. images ?. length ) console . log ( _ ) ;
4651 } ) ;
@@ -56,6 +61,7 @@ export default {
5661 json . data . forEach ( ( _ ) => {
5762 if ( _ . type === 1 ) {
5863 CACHED . videoById . set ( _ . item . video . id , _ . item ) ;
64+ CACHED . hasNew = true ;
5965 }
6066 } ) ;
6167 }
@@ -169,9 +175,13 @@ export default {
169175</div>` ,
170176 created ( ) {
171177 setInterval ( ( ) => {
172- this . videos = Array . from ( CACHED . videoById . values ( ) )
173- // inject index
174- . map ( ( v , i ) => ( { ...v , index : i + 1 } ) ) ;
178+ if ( CACHED . hasNew ) {
179+ this . videos = Array . from ( CACHED . videoById . values ( ) )
180+ // inject index
181+ . map ( ( v , i ) => ( { ...v , index : i + 1 } ) ) ;
182+
183+ CACHED . hasNew = false ;
184+ }
175185 } , 1000 ) ;
176186 } ,
177187 data ( ) {
@@ -384,7 +394,7 @@ export default {
384394 ) ;
385395 } ,
386396 scrollToVeryEnd ( ) {
387- setTimeout ( ( ) => scrollToVeryEnd ( ) , 100 ) ;
397+ setTimeout ( ( ) => scrollToVeryEnd ( false ) , 100 ) ;
388398 } ,
389399 scrollToTop ( e ) {
390400 e . target . parentElement . scrollTo ( { top : 0 , behavior : "smooth" } ) ;
0 commit comments