// ==UserScript== // @name 智慧树网课自动刷新跳转下一门课程 // @version 1.7 // @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 num = 1200; var text = document.createElement('div'); text.classList.add('text'); document.body.appendChild(text) var Text = document.querySelector('.text'); Text.style.fontSize = '20px' Text.style.color = '#fff' Text.style.position = 'absolute' Text.style.zIndex = '99999' Text.style.top = '60px' Text.style.left = '0px' Text.style.padding = '10px' Text.style.textShadow = '0 0 10px' Text.style.backgroundColor = '#3d84ff' Text.style.textAlign = 'center' Text.innerHTML = '正在加载观看数据...' var input = document.createElement('input'); input.classList.add('hrefInput'); document.body.appendChild(input) var hrefInput = document.querySelector('.hrefInput'); hrefInput.style.position = 'absolute' hrefInput.style.width = '666px' hrefInput.style.fontSize = '14px' hrefInput.style.left = '0px' hrefInput.style.top = '290px' hrefInput.value = localStorage.getItem('href') hrefInput.placeholder = '输入的链接10秒后自动存入本地,若为空,10秒后会自动填充,无需担心因浏览器刷新而无法跳转' hrefInput.style.outline = 'none' hrefInput.style.zIndex = '99999' hrefInput.style.padding = '5px' hrefInput.style.backgroundColor = '#000' hrefInput.style.color = '#fff' hrefInput.style.border = '2px solid #fff' var inputNum = 6; setInterval(function(){ if(localStorage.getItem('href') == null){ localStorage.setItem("href",hrefInput.value); }else if(hrefInput.value == ''){ hrefInput.value=localStorage.getItem("href"); }else { localStorage.setItem("href",hrefInput.value); } },10000) 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, ' ')); var countDown = times(timeArr).ss setInterval(function(){ lightDark = document.querySelector('.Patternbtn-div').querySelector('p') finish = document.querySelectorAll('.time_icofinish').length; if(lightDark.innerHTML == '白昼模式'){ Text.style.backgroundColor = '#3d84ff' }else{ Text.style.backgroundColor = '#222222' } b-=1 everyTime = times(timeArr).hour + '时' + times(timeArr).min + '分' + times(timeArr).s + '秒'; Text.innerHTML = num + '秒后将自动刷新浏览器
来防止时间长了可能导致视频连接失败而暂停
您已完成' + finish + '节课
还有'+ (allTime.length - finish) + '节课等着您完成
在1.5倍速的状态下,您需要花'+ everyTime+'
也就是'+b+'秒后看完当前课程
预计在'+ finishTime+'看完当前课程
看完后将自动跳转至您在下方输入框输入的网页链接'; num--; if (num == 0) { location.reload(); } if(finish==allTime.length){ window.open(hrefInput.value) window.close() } },1000) },2000) })