// ==UserScript== // @name 职培云刷课 // @namespace http://tampermonkey.net/ // @version 1.0 // @description 职培云刷课时 // @author 攸泠 // @match https://px.class.com.cn/player/* // @grant none // @license MIT // @downloadURL none // ==/UserScript== (function() { /*当前观看的课程*/ var current; /*课程中的所有课程*/ var list; /*观看状态:1表示未完成课程,0表示已完成课程*/ var lessonstatus = 1; /*查看模式:0代表未看完的方式,1代表已看完重刷一次,默认1即可刷所有视频,0只能刷未看完的视频*/ var watchmode = 1; /*开始统计视频总时长(5秒内可自行选择起始视频)*/ setTimeout(function() { /*分*/ var minute = -1; /*秒*/ var second = 0; /*课程内所有视频*/ list = document.getElementById("list_chapter"); /*时间累加*/ for(var i = 0; i < list.getElementsByClassName("section").length; i++) { //定位到当前视频 if(list.getElementsByClassName("section")[i].className.indexOf("active")!=-1) { current = i; minute = 0; } if(minute >= 0){ minute += parseInt(list.getElementsByClassName("time")[i].innerHTML.split(":")[0]); second += parseInt(list.getElementsByClassName("time")[i].innerHTML.split(":")[1]); } } minute += parseInt(second/60); alert("视频总长"+minute+"分"+second%60+"秒"); }, 5000); /*刷已完成课程*/ /*因为是iframe标签,所以使用监听非常麻烦,这里采用计时的方式*/ /*考虑到网络延时,多增加了10秒延迟*/ function watchover(){ lessonstatus = 0; var minute = parseInt(list.getElementsByClassName("time")[current].innerHTML.split(":")[0]); var second = parseInt(list.getElementsByClassName("time")[current].innerHTML.split(":")[1])+10; list.getElementsByClassName("active")[0].innerHTML += "-"+minute+":"+second; console.log(current); setTimeout(function() { current ++; list.getElementsByClassName("section")[current].click(); lessonstatus = 1; //list.getElementsByClassName("section")[current].innerHTML += "时("+minute+":"+second+"),状("+watchstatus+")"; }, (minute*60+second)*1000); } /*刷未完成课程*/ function watchnew(){ var test = list.getElementsByClassName("section")[current].getElementsByClassName("status-done")[0]; //判断是否播放完成 if(typeof(test) != "undefined") { console.log("视频已播放完成"+test); current ++; list.getElementsByClassName("section")[current].click(); } } /*定时启动判断程序*/ setInterval(function() { if (watchmode == 1){ if (lessonstatus == 1){ watchover(); } }else{ watchnew(); } },10000) })();