网址
处javascript: (function() {
var hour = 0;
var minute = 0;
var second = 0;
var txt = document.getElementsByClassName('cur-page')[0].innerHTML;
var page = txt.match(/\/(\d+)/)[1];
function f1() {
hour = 0;
minute = 0;
second = 0;
var min = 0;
var sec = 0;
if (document.getElementById('divChild')) {
d.removeChild(document.getElementById('divChild'));
}
if (parseInt(input1.value) >= 1 && parseInt(input1.value) <= page && parseInt(input2.value) <= page && parseInt(input1.value) <= parseInt(input2.value)) {
for (var i = parseInt(input1.value) - 1; i < parseInt(input2.value); i++) {
var time = document.getElementsByClassName('duration')[i].innerHTML;
var t = time.match(/\d+/g);
if (t.length == 3) {
var h = t[0];
var m = t[1];
var s = t[2];
} else {
var h = 0;
var m = t[0];
var s = t[1];
}
hour += parseInt(h);
min += parseInt(m);
sec += parseInt(s);
}
hour += parseInt(min / 60);
minute = min - parseInt(min / 60) * 60 + parseInt(sec / 60);
second = sec - parseInt(sec / 60) * 60;
if (minute >= 60) {
hour += parseInt(minute / 60);
minute = minute - parseInt(minute / 60) * 60;
}
if (second >= 60) {
minute = parseInt(second / 60);
second = second - parseInt(second / 60) * 60;
}
if (input3.value != 1) {
var total = hour * 3600 + minute * 60 + second;
total = total / input3.value;
hour = parseInt(total / 3600);
minute = parseInt((total % 3600) / 60);
second = total % 60;
}
var d1 = document.createElement('div');
d1.style.cssText = "margin-top:15px";
d1.setAttribute("id", "divChild");
d.appendChild(d1);
var t1 = document.createTextNode("全" + (parseInt(input2.value) - parseInt(input1.value) + 1) + "集:" + hour + "时" + minute + "分" + parseInt(second) + "秒");
d1.appendChild(t1);
} else {
var d1 = document.createElement('div');
d1.style.cssText = "margin-top:15px";
d1.setAttribute("id", "divChild");
d.appendChild(d1);
var t1 = document.createTextNode("输入与实际集数不符");
d1.appendChild(t1);
}
}
function over() {
btn.style.backgroundColor = "#E4E4E4";
}
function out() {
btn.style.backgroundColor = "#F4F4F4";
}
var body = document.body;
var d = document.createElement("div");
d.style.cssText = "padding-top:15px;width:145px;height:135px;background-color:#F4F4F4;position:absolute;right:55px;top:218px;border:1px solid #00A1D6;color:#00A1D6;z-index:999;text-align:center;font-size:14px";
body.appendChild(d);
var d2 = document.createElement("div");
d.appendChild(d2);
var t2 = document.createTextNode("第");
d2.appendChild(t2);
var input1 = document.createElement('input');
input1.setAttribute("type", "number");
input1.style.cssText = "border: 1px solid deepskyblue;width:40px";
d2.appendChild(input1);
var t3 = document.createTextNode("集到");
d2.appendChild(t3);
var input2 = document.createElement('input');
input2.setAttribute("type", "number");
input2.style.cssText = "border: 1px solid deepskyblue;width:40px";
d2.appendChild(input2);
var t4 = document.createTextNode("集");
d2.appendChild(t4);
var btn = document.createElement('input');
btn.setAttribute("type", "button");
btn.setAttribute("value", "计算");
btn.style.cssText = "width:50px;margin-top:15px;border: 1px solid #00A1D6;cursor:pointer";
d.appendChild(btn);
btn.onclick = f1;
btn.onmouseover = over;
btn.onmouseout = out;
var t5 = document.createTextNode("倍速:");
d2.appendChild(t5);
var input3 = document.createElement('input');
input3.setAttribute("type", "number");
input3.style.cssText = "border: 1px solid deepskyblue;width:50px;margin-top:15px;margin-right:10px";
input3.value = 1;
d2.appendChild(input3);
var t6 = document.createTextNode("倍");
d2.appendChild(t6);
})();
var ul = document.querySelector(".cur-list>.list-box"),
liList = ul.getElementsByTagName("li"), // 获取列表的liList数组
titleAry = [], // 存放标题
times = 0, // 存放时间
timesStr = ""; // 处理时间格式 h:m:s 这种
// 处理(获取)总时长
[].forEach.call(liList, (item) => {
var a = item.getElementsByTagName("a")[0],
title = a.title,
div = a.getElementsByClassName("duration")[0],
time = div.innerText.replace(
/(\d+)\:(\d+)/,
($0, $1, $2) => Number($1) * 60 + Number($2)
);
times += Number(time);
titleAry.push(title);
});
// 处理时间格式
((_) => {
var h = parseInt(times / 3600),
m = parseInt((times - h * 3600) / 60),
ss = times - h * 3600 - m * 60, // 仅仅是验证秒的正确性
s = times % 60;
[h, m, s].forEach((item, index) => {
item = item < 10 ? "0" + item : item;
// 让[h, m, s]的最后一位时走esle
index < 2 ? timesStr += item + ":" : timesStr += item;
});
})();
console.log(titleAry); // 分P标题
console.log("总时长为:" + times + "S 即:" + timesStr);
Console
控制台鼠标右击空白处,选择检查,打开后,选择 Console
控制台;
或者键盘 按F12(没反应的话,就Fn + F12)
粘贴代码,回车。最下方显示时长
。
如果本人分享的一字一句能够帮助到你,荣幸之至。
手机扫一扫
移动阅读更方便
你可能感兴趣的文章