// ==UserScript==
// @name 智慧树网课自动刷新跳转下一门课程
// @version 1.1
// @description 每隔一段时间刷新网页防止网络连接失败,并可以根据课程完成度自动跳转到用户设置的下一门课程
// @author 冷弋白
// @match *://studyh5.zhihuishu.com/*
// @icon https://z3.ax1x.com/2021/05/17/g2l0Z8.png
// @namespace https://greasyfork.org/users/702892
// @downloadURL none
// ==/UserScript==
window.addEventListener('load',function(){
//将下面的链接替换成您当前课程刷完后,要自动跳转的下一门课程链接
var href = 'https://studyh5.zhihuishu.com/videoStudy.html#/studyVideo?recruitAndCourseId=4e5d585b4d524258454a58595f465c40';
var num = 180;
var text = document.createElement('div');
text.classList.add('text');
document.body.appendChild(text)
var Text = document.querySelector('.text');
Text.style.fontSize = '18px'
Text.style.color = '#fff'
Text.style.position = 'absolute'
Text.style.zIndex = '99999'
Text.style.top = '60px'
Text.style.right = '0px'
Text.style.padding = '5px'
Text.style.textShadow = '0 0 10px'
Text.style.backgroundColor = '#3d84ff'
Text.style.textAlign = 'center'
Text.innerHTML = '正在加载观看数据...'
function times(arr) {
var allTime = 0;
arr.forEach(function(a) {
allTime += A(a);
});
function A(time) {
var min = parseInt(time.substr(3, 2)) * 60;
var s = parseInt(time.substr(6, 2));
var ss = min + s;
return ss;
}
return {
hour: parseInt((allTime/ 3 * 2) / 60 / 60),
min: parseInt((allTime / 3 * 2) / 60) % 60,
s: parseInt(((allTime / 3 * 2) % 60) % 60),
ss:parseInt(allTime / 3 * 2),
sss:parseInt(allTime / 3 * 2 * 1000),
};
}
var timeArr = [],finish,allTime,everyTime,finishTime,nowTime,lightDark;
setInterval(function(){
nowTime = new Date().getTime()
},1000)
setTimeout(function(){
//获取已经完成的课程数量
finish = document.querySelectorAll('.time_icofinish').length;
//获取所有课程
allTime = document.querySelectorAll('#app .video-study .box-content .box-right .el-scrollbar .el-scrollbar__wrap .el-scrollbar__view .time')
//将获取的所有课程时间添加进数组
allTime.forEach(function(a){
timeArr.push(a.innerHTML)
})
//删除已经完成的课程时长
for(var i = 0;i < finish;i++){
timeArr.shift();
}
//所需时间
//几点完成
var a = nowTime + times(timeArr).sss
finishTime = new Date(a).toLocaleString();
//多少秒完成
var b = times(timeArr).ss;
var timea = +new Date(finishTime.replace(/[\u4e00-\u9fa5]/g, ' '));
console.log('那时我将自动跳转至下一门课程,但前提您得给我课程链接')
var countDown = times(timeArr).ss
setInterval(function(){
lightDark = document.querySelector('.Patternbtn-div').querySelector('p')
if(lightDark.innerHTML == '白昼模式'){
Text.style.backgroundColor = '#3d84ff'
}else{
Text.style.backgroundColor = '#222222'
}
b-=1
everyTime = times(timeArr).hour + '时' + times(timeArr).min + '分' + times(timeArr).s + '秒';
console.log(countDown-=1)
Text.innerHTML = num + '秒后将自动刷新浏览器
来防止时间长了可能导致视频连接失败而暂停
您已完成' + finish + '节课
还有'+
(allTime.length - finish) + '节课等着您完成
在1.5倍速的状态下,您需要花'+
everyTime+'
也就是'+b+'秒后看完当前课程
预计在'+
finishTime+'看完当前课程
届时将自动跳转至您设置的下一门课程';
num--;
if (num == 0) {
location.reload();
}
if(timeArr==0){
window.open(href)
window.close();
}
},1000)
},2000)
})