-
Notifications
You must be signed in to change notification settings - Fork 0
/
background.js
32 lines (29 loc) · 914 Bytes
/
background.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
chrome.contextMenus.create({
title: "Tiktok Downloader",
type: "normal",
id: "tiktok",
});
chrome.contextMenus.onClicked.addListener(function (t) {
let videoUrl = t.pageUrl;
function download(url) {
// 发送API请求
fetch(url)
.then((response) => response.json())
.then((data) => {
let downloadUrl = data.aweme_list[0].video.play_addr.url_list[0];
//打开新标签页下载
chrome.tabs.create({ url: downloadUrl });
})
.catch((error) => {
alert(error);
});
}
if (t.pageUrl.includes("tiktok")) {
let downloadUrl = `https://api.douyin.wtf/tiktok_video_data/?tiktok_video_url=${videoUrl}`;
download(downloadUrl);
} else if (t.pageUrl.includes("douyin")) {
let downloadUrl = `https://api.douyin.wtf/douyin_video_data/?douyin_video_url=${videoUrl}`;
console.log(downloadUrl);
download(downloadUrl);
}
});