// ==UserScript== // @name 微知库网课助手 // @namespace http://tampermonkey.net/ // @version 0.32 // @description 支持微知库视频·文档·PPT·图像等任务自动观看,自动跳转下一章 // @author lodge // @match http://*.36ve.com/?q=items/student/study/* // @match http://*.cavtc.cn/?q=items/student/study/* // @match http://wzk.36ve.com/Student/learning-content/index?tcourseId=* // @match http://wzk.36ve.com/Student/learning-content/learning?resource_id=* // @grant unsafeWindow // @grant GM_setValue // @grant GM_getValue // @require http://code.jquery.com/jquery-3.4.1.js // @run-at document-end // @downloadURL none // ==/UserScript== 'use strict'; var window = unsafeWindow var url = location.pathname var setting = { //时间单位均为毫秒! viedo_wait_time: 7000 //等待页面加载的延迟,时间过小容易导致无法自动开始播放 , jump_time: 3000 //检测视频播放完成的时间,小于3000可能会导致没看完课就跳转 , unfold_time: 20000 //展开章节的等待时间,若课程比较多,可以调大点 , success_check_time: 3000 //任务完成检测等待的时间,机子性能差请适当调高,但会增加刷课时间 } var chapter_num var $next_course function init() { setting.div = $( '
' ).appendTo('body').on('click', 'button', function () { var name = $(this).attr('name') // console.log(name) if (name == 'clean') { $('#log').html('') } }).end() } init() if (url == '/Student/learning-content/index') { GM_setValue('is_studying', 'false') open_chapter() setTimeout(() => { clearInterval() msg('log', '正在获取全部课程') var $course_list = $('#lhMenu').find('a[target="_blank"]') var $not_completed_list = [] $.each($course_list, function (indexInArray, valueOfElement) { var $this = $(this) var $rate_span = $this.prevAll('.label.label-primary') var name = $this.find('.text-overflow').attr('title') var herf = $this.attr('href') if ($rate_span.length != 0) { var rate = $rate_span.html() $not_completed_list.push($this) // console.log('log', `当前课程 ${name}得分 ${rate}`) } // console.log(`名称${name},网址${herf}`) }); msg('log', `获取到${$not_completed_list.length}节未完成课程`) var now = 0 var total = $not_completed_list.length setInterval(() => { if (now <= total) { var is_studying = GM_getValue('is_studying', 'false') console.log(`is_studying${is_studying}`) var $this = $not_completed_list[now] var name = $this.find('.text-overflow').attr('title') var href = $this.attr('href') if (is_studying == 'false') { msg('log', `即将学习:${name}`) // GM_setValue('is_studying', true) window.open(href, '_blank') now = now + 1 } else { var last_c_course_name = $not_completed_list[now - 1].find('.text-overflow').attr('title') console.log(`当前正在学习课程:${last_c_course_name}!`) } } }, setting.success_check_time); }, setting.unfold_time); } else if (url == '/Student/learning-content/learning') { GM_setValue('is_studying', 'true') window.onbeforeunload = function (event) { GM_setValue('is_studying', 'false') }; if (is_video() == true) { msg('log', '当前为视频') msg('log',` ${setting.viedo_wait_time/1000}秒后开始播放`) setTimeout(() => { console.log('start playing') var playerId = $('[id^=ckplayer]').attr('id') if (playerId != undefined) { console.log('当前页面采用flash播放器!'); var $player = CKobject.getObjectById(playerId) $player.videoPlay() $player.changeVolume(0) setInterval(() => { var info = $player.getStatus() var time = parseInt(info['time']) var total_time = parseInt(info['totalTime']) if (!info.hasOwnProperty('totalTime')) { total_time = parseInt(info['totaltime']) } console.log(`当前秒${time}总秒${total_time}`) if (time == total_time) { console.log('当前视频观看完毕,跳转中') msg('log', '当前视频观看完毕') setTimeout(() => { // GM_setValue('is_studying', false) window.close() }, 2000); } }, setting.jump_time); } else { // $('video').attr('muted')='muted' // $('#log').click() console.log('当前页面采用html播放器!'); $('[data-title=点击播放] canvas').click() var player = window.player console.log(player) player.volume = 0 var totalTime = player.getMetaDate().duration // console.log(player.getMetaDate()) setInterval(() => { play_time = player.time console.log(`当前秒${play_time}总秒${totalTime}`) if (parseInt(play_time) == parseInt(totalTime)) { console.log('当前视频观看完毕,跳转中') msg('log', '当前视频观看完毕') setTimeout(() => { // GM_setValue('is_studying', false) window.close() }, 2000); } }, setting.jump_time); } }, setting.viedo_wait_time); } else { setTimeout(() => { msg('log', '本节学习完毕') setTimeout(() => { // GM_setValue('is_studying', false) window.close() }, 2000); }, 1000); } } else if (url == '/') { (function () { chapter_num = $('.listitem').length - 1 $('[style="background:none;"]').remove() var $course = get_course() start_learning($course) })(); } function open_chapter() { setInterval(() => { var $right = $('i[data-type="right"]') $right.click() }, 100); msg('log', `正在展开课程,时间${setting.unfold_time / 1000}秒`) } function check_player() { var playerId = $('[id^=ckplayer]').attr('id') if (playerId != undefined) { console.log('当前页面采用flash播放器!') return 'falsh' } else { console.log('html5') return 'html5' } } function msg(id, msg) { var myDate = new Date(); var old = $(`#${id}`).html() var time = `${myDate.getHours()}:${myDate.getMinutes()}:${myDate.getSeconds()}` var newmsg = `${old}${time}${msg}` + '\n' // console.log(`id${id}msg${msg} oldmsg${old} new msg${newmsg}`) $(`#${id}`).html(newmsg) } function start_learning($course) { console.log('开始学习,名称:' + $course.text()) console.log(`当前页面任务名称:${$('.current').find('.itemtitle').text()}待进入任务名${$course.text()}`); if ($('.current').find('.itemtitle').text() != $course.text()) { console.log('跳转中……') jump_to_course($course) } else { console.log('当前页面是正确的课程') } if (is_video()) { console.log('当前是视频') msg('log',` ${setting.viedo_wait_time/1000}秒后开始播放`) setTimeout(() => { console.log('start playing') var playerId = $('[id^=ckplayer]').attr('id') if (playerId != undefined) { console.log('当前页面采用flash播放器!'); var $player = CKobject.getObjectById(playerId) $player.videoPlay() $player.changeVolume(0) setInterval(() => { var info = $player.getStatus() var time = parseInt(info['time']) var total_time = parseInt(info['totalTime']) if (!info.hasOwnProperty('totalTime')) { total_time = parseInt(info['totaltime']) } console.log(`当前秒${time}总秒${total_time}`) if (time == total_time) { console.log('当前视频观看完毕,跳转中') find_next($course) start_learning($next_course) } }, setting.jump_time); } else { console.log('当前页面采用html播放器!'); setTimeout(() => { $('[data-title=点击播放] canvas').click() var player = window.player console.log(player) player.volume = 0 $("p:contains('4倍速')").click() var totalTime = player.getMetaDate().duration // console.log(player.getMetaDate()) setInterval(() => { play_time = player.time console.log(`当前秒${play_time}总秒${totalTime}`) if (parseInt(play_time) == parseInt(totalTime)) { console.log('当前视频观看完毕,跳转中') find_next($course) start_learning($next_course) } }, setting.jump_time); }, 1000); } }, setting.viedo_wait_time); } else { console.log('当前是文档') } } function get_course() { var $course_list = $('.itemtitle') var $course // $course_list.css('border', '3px solid red') if ($('.current').length == 0) { $.each($course_list, function (indexInArray, valueOfElement) { var $this = $(this) // console.log('课程名字'+$this.text()+'分数'+$this.attr('score')+'播放地址'+$this.attr('href')) if (is_compleated($this)) { console.log('已找到' + $this.text()) $course = $this return false } // console.log($(this).text()) }); return $course } else { $course = $('.current').find('.itemtitle') if (is_compleated($course)) { find_next($course) return $next_course } else { return $course } // $course = $('.current').find('.itemtitle') // console.log('已找到' + $course.text()) // return $course } } function find_next($course) { // var $chapter = $course.parent().parent().parent().parent() var $chapter = $course.parent().parent().parent() var chapter_id = parseInt($chapter.attr('id').replace('listitem', '')) var next_par_id = chapter_id + 1 // next chapter 有问题 console.log('next par id is' + next_par_id) var $next_chapter = $(`#listitem${next_par_id}`) // var $next_chapter=$('.listitem'+next_par_id) // $chapter.css('border', '5px solid green') // $next_chapter.css('border', '5px solid red') if ($course.parent().is(':last-child')) { if ($chapter.parent().is(':last-child')) { console.log('已经是最后一章了') return null } else { $next_course = $next_chapter.find('.itemtitle:first') console.log('当前判断课程' + $next_course.text()) if (is_compleated($next_course)) { find_next($next_course) } else { console.log('下一个任务为:' + $next_course.text()) // return $next_course } } } else { $next_course = $course.parent().next().find('.itemtitle') console.log('当前判断课程' + $next_course.text()) if (is_compleated($next_course)) { find_next($next_course) } else { console.log('该课程还未观看:' + $next_course.text()) // return $next_course } } } function jump_to_course($course) { $course[0].click(function (e) { e.preventDefault(); }); } function is_video() { if ($('div[id^=videobox]').length != 0 || $('div[id^=video]').length != 0) { return true } else { return false } } function is_compleated($course) { if ($course.attr('score') == '10') { return true } else { return false } }