-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.js
76 lines (66 loc) · 2.17 KB
/
main.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
var delay = 2000; //等待时间
var gen = listGen();
var csvContent = "\uFEFF";
csvContent += "folder,title,url\n";
function getCSVFileName() {
var userName = $("#h-name").text();
return userName + "的收藏夹.csv";
}
function getFolderName() {
return $("#fav-createdList-container .fav-item.cur a.text").text().trim();
}
function escapeCSV(field) {
return '"' + String(field).replace(/"/g, '""') + '"';
}
function getVideosFromPage() {
var results = [];
var folderName = getFolderName().replace(/\//g, '\\'); // Replace / with \
$(".fav-video-list > li > a.title").each(function() {
var title = $(this).text().replace(/,/g, '');
if (title !== "已失效视频") {
var url = 'https:' + $(this).attr("href");
results.push(escapeCSV(folderName) + ',' + escapeCSV(title) + ',' + escapeCSV(url));
}
});
return results.join('\n');
}
function processVideos() {
csvContent += getVideosFromPage() + '\n'; // Add a newline after each page of videos
if ($(".be-pager-next:visible").length == 0) {
setTimeout(changeList, delay);
} else {
$(".be-pager-next").click();
setTimeout(processVideos, delay);
}
}
function* listGen() {
for (var list of $("#fav-createdList-container .fav-item a").get()) {
yield list;
}
}
function changeList() {
var list = gen.next().value;
if (list) {
list.click();
setTimeout(processVideos, delay);
} else {
downloadCSV();
}
}
function downloadCSV() {
var fileName = getCSVFileName();
var blob = new Blob([csvContent], { type: 'text/csv;charset=utf-8;' });
var url = URL.createObjectURL(blob);
var win = window.open();
if (win) {
win.document.open();
win.document.write('<html><body>');
win.document.write('<a href="' + url + '" download="' + fileName + '">点击下载</a>');
win.document.write('<script>document.querySelector("a").click();</script>');
win.document.write('</body></html>');
win.document.close();
} else {
alert('下载窗口被浏览器阻止,请先在设置里允许网页弹窗后重试。');
}
}
changeList();