Skip to content

Commit a549788

Browse files
committed
refactor
1 parent 221633c commit a549788

File tree

4 files changed

+24
-13
lines changed

4 files changed

+24
-13
lines changed

scripts/scrollToVeryEnd.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export default {
2424
},
2525
};
2626

27-
export function scrollToVeryEnd() {
27+
export function scrollToVeryEnd(animation = true) {
2828
return new Promise(async (resolve, reject) => {
2929
const notify = UfsGlobal.DOM.notify({
3030
msg: "Useful-script: Scrolling to very end...",
@@ -49,8 +49,6 @@ export function scrollToVeryEnd() {
4949
}
5050
}
5151

52-
console.log(scrollableElements);
53-
5452
// If only one scrollable element is found, return it
5553
if (scrollableElements.length === 1) {
5654
return scrollableElements[0];
@@ -72,7 +70,12 @@ export function scrollToVeryEnd() {
7270
}
7371

7472
let height = (ele) => (ele || document.body).scrollHeight;
75-
let down = (ele = document) => ele.scrollTo({ left: 0, top: height(ele) });
73+
let down = (ele = document) =>
74+
ele.scrollTo({
75+
left: 0,
76+
top: height(ele),
77+
behavior: animation ? "smooth" : "instant",
78+
});
7679
let sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
7780

7881
let lastScroll = {
@@ -91,8 +94,6 @@ export function scrollToVeryEnd() {
9194

9295
let scrollEle = findMainScrollableElement();
9396

94-
console.log(scrollEle);
95-
9697
while (running) {
9798
down(scrollEle);
9899
let currentHeight = height(scrollEle);

scripts/tiktok_batchDownload.jpg

-126 KB
Binary file not shown.

scripts/tiktok_batchDownload.js

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { UfsGlobal } from "./content-scripts/ufs_global.js";
2+
import { BADGES } from "./helpers/badge.js";
23
import { hookFetch } from "./libs/ajax-hook/index.js";
34
import { 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" });

scripts/tiktok_batchDownload.png

103 KB
Loading

0 commit comments

Comments
 (0)