-
-
Notifications
You must be signed in to change notification settings - Fork 47
/
tiktok_downloadWatchingVideo.js
98 lines (84 loc) · 2.73 KB
/
tiktok_downloadWatchingVideo.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import { runScriptInCurrentTab, showLoading } from "./helpers/utils.js";
import { shared as tiktok_downloadVideo } from "./tiktok_downloadVideo.js";
export default {
icon: "https://www.tiktok.com/favicon.ico",
name: {
en: "Tiktok - Download watching video",
vi: "Tiktok - Tải video đang xem",
},
description: {
en: "Download tiktok video you are watching (no watermark)",
vi: "Tải video tiktok bạn đang xem (không watermark)",
},
changeLogs: {
1.66: {
"2024-04-27": "fix bug - use snaptik",
},
},
whiteList: ["https://www.tiktok.com/*"],
onClickExtension: async function () {
const { closeLoading, setLoadingText } = showLoading("Đang lấy video id..");
let title = "tiktok_video";
const getLinkFuncs = [
async () => {
setLoadingText("Đang tìm videoid...");
const videos = await shared.getListVideoIdInWebsite();
if (videos.length) {
let video = videos[0];
title = video?.title?.split?.("#")?.[0] || video.id || title;
setLoadingText(`Đang tìm link tải video ${title}...`);
let res = await tiktok_downloadVideo.getVideoNoWaterMark(
shared.genTiktokUrl(video.author, video.id)
);
return res;
}
},
async () => {
setLoadingText("Đang tìm video url từ DOM...");
return await runScriptInCurrentTab(
async () => await UfsGlobal.DOM.getWatchingVideoSrc()
);
},
];
let link;
for (let func of getLinkFuncs) {
try {
link = await func();
if (link) break;
} catch (e) {
alert("lol");
}
}
if (!link) alert("Không tìm được link video");
else {
setLoadingText("Đang tải video...");
await UfsGlobal.Utils.downloadBlobUrl(link, title + ".mp4");
}
closeLoading();
},
};
export const shared = {
genTiktokUrl(author, videoId) {
return `https://www.tiktok.com/@${author}/video/${videoId}`;
},
getListVideoIdInWebsite: async function () {
return await runScriptInCurrentTab(() => {
const { getOverlapScore, closest } = UfsGlobal.DOM;
let allVideos = Array.from(document.querySelectorAll("video"));
let result = [];
for (let video of allVideos) {
try {
result.push({
overlapScore: getOverlapScore(video),
id: video.parentElement.id.split("-").at(-1),
title: closest(video, '[data-e2e="video-desc"]')?.textContent,
author: closest(video, '[data-e2e="video-author-avatar"]')?.href,
});
} catch (e) {
console.log("ERROR on get: ", e);
}
}
return result.sort((a, b) => b.overlapScore - a.overlapScore);
});
},
};