-
Notifications
You must be signed in to change notification settings - Fork 0
/
content2.js
75 lines (70 loc) · 3.66 KB
/
content2.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
let playlist_size = Number(document.querySelector('#publisher-container > div > yt-formatted-string').innerText.split('/')[1].trim().split(' ')[0]);
check(document.querySelectorAll(".style-scope ytd-thumbnail-overlay-time-status-renderer").length);
function check(a) {
console.log(a);
if (a < playlist_size) setTimeout(() => check(document.querySelectorAll(".style-scope ytd-thumbnail-overlay-time-status-renderer").length), 1000);
else document.getElementById("publisher-container").insertAdjacentHTML("beforeEnd", "<span id='totaltime' class='publisher style-scope ytd-playlist-panel-renderer complex-string yt-simple-endpoint style-scope yt-formatted-string'> - " + add_total_time() + "</span>");
}
function add_total_time() {
let times = [];
document.querySelectorAll(".style-scope ytd-thumbnail-overlay-time-status-renderer").forEach(s => times.push(s.innerText));
let time_split = [];
times.forEach(s => time_split.push(s.split(":")));
total_duration_1 = 0;
for (var i = 0; i < playlist_size; i++) {
time_add(time_split[i]);
}
let total_duration_in_string_1 = calculate_total_duration(total_duration_1);
return total_duration_in_string_1;
}
function calculate_total_duration(total_duration) {
if (total_duration >= 3600) {
let total_duration_in_string = (Math.floor(total_duration / 3600)).toString();
total_duration_in_string = total_duration_in_string.concat(":");
total_duration = total_duration % 3600;
if (Math.floor(total_duration / 60) < 10) {
total_duration_in_string = total_duration_in_string.concat("0");
}
total_duration_in_string = total_duration_in_string.concat((Math.floor(total_duration / 60)).toString());
total_duration_in_string = total_duration_in_string.concat(":");
total_duration = total_duration % 60;
if (total_duration < 10) {
total_duration_in_string = total_duration_in_string.concat("0");
}
total_duration_in_string = total_duration_in_string.concat(total_duration.toString());
return total_duration_in_string;
} else if (total_duration >= 60) {
let total_duration_in_string = "";
if (Math.floor(total_duration / 60) < 10) {
total_duration_in_string = total_duration_in_string.concat("0");
}
total_duration_in_string = total_duration_in_string.concat((Math.floor(total_duration / 60)).toString());
total_duration_in_string = total_duration_in_string.concat(":");
total_duration = total_duration % 60;
if (total_duration < 10) {
total_duration_in_string = total_duration_in_string.concat("0");
}
total_duration_in_string = total_duration_in_string.concat((total_duration).toString());
return total_duration_in_string;
} else {
let total_duration_in_string = "";
total_duration_in_string = total_duration_in_string.concat("0:");
if (total_duration < 10) {
total_duration_in_string = total_duration_in_string.concat("0");
}
total_duration_in_string = total_duration_in_string.concat(total_duration.toString());
return total_duration_in_string;
}
}
function time_add(s) {
if (s.length == 1) {
total_duration_1 = total_duration_1 + Number(s[0]);
} else if (s.length == 2) {
total_duration_1 = total_duration_1 + Number(s[0] * 60);
total_duration_1 = total_duration_1 + Number(s[1]);
} else if (s.length == 3) {
total_duration_1 = total_duration_1 + Number(s[0] * 60 * 60);
total_duration_1 = total_duration_1 + Number(s[1] * 60);
total_duration_1 = total_duration_1 + Number(s[2]);
}
}