-
Notifications
You must be signed in to change notification settings - Fork 0
/
youtube-statistics.js
47 lines (45 loc) · 1.82 KB
/
youtube-statistics.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
// ==UserScript==
// @name youtube playlist statitics
// @name:zh-CN 统计YouTube播放列表的时长
// @namespace http://tampermonkey.net/
// @version 0.2
// @description statirics the videos duration of youtube playlist video include total,longest,shortest time
// @description:zh-cn 统计YouTube播放列表的时长包括总时长,最长,最短,平均
// @author Youer@https://github.com/youerning
// @match https://www.youtube.com/playlist?list=*
// @grant none
// @require https://code.jquery.com/jquery-2.2.4.min.js
// ==/UserScript==
(function() {
//'use strict';
//var allSpan = document.getElementsByTagName("tbody")[0].getElementsByTagName("span");
var allSpan = $("ul").find("tbody").find('span[aria-label]');
// Total seconds
var sumAll = 0;
var vidTime = 0;
var timeList = [];
for(var i=0;i<allSpan.length;i++) {
var sp = allSpan[i];
var spText = sp.innerText;
var sumOne = 0;
if (spText.indexOf(":") >= 0) {
var spTextLis = spText.split(":");
var lg = spTextLis.length;
for (var j=0; j < lg; j++){
var m = Math.pow(60, (lg - 1 - j));
vidTime = parseInt(spTextLis[j]) * m;
sumOne += vidTime;
}
} else {
vidTime = parseInt(spText);
sumOne += vidTime;
}
timeList.push(sumOne);
sumAll += sumOne;
}
// console somethings
console.log("The playlist is total: " + (sumAll/3600).toFixed(2) + "hours");
console.log("average time of all: " + (sumAll / (60 * allSpan.length)).toFixed(2) + "minutes");
console.log("longest video time: " + (Math.max.apply(Math, timeList)) / 60 + "minutes");
console.log("shortest video time: " + (Math.min.apply(Math, timeList)) / 60 + "minutes");
})();