Greasy Fork

Greasy Fork is available in English.

微知库网课助手

支持微知库视频·文档·PPT·图像等任务自动观看,自动跳转下一章

当前为 2020-04-17 提交的版本,查看 最新版本

// ==UserScript==
// @name         微知库网课助手
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  支持微知库视频·文档·PPT·图像等任务自动观看,自动跳转下一章 
// @author       lodge
// @match        http://*.36ve.com/?q=items/student/study/*
// @grant        none
// @require      http://code.jquery.com/jquery-3.4.1.js
// @run-at       document-end
// ==/UserScript==




var setting = {
    viedo_wait_time: 3000 //页面载入完成后,播放视频等待的毫秒数 网速慢可以改大点
    , jump_time: 3000 //检测视频播放完成的时间,小于3000可能会导致没看完课就跳转
}

var chapter_num
var $next_course

(function () {
    'use strict';
    init()
    var $course = get_course()
    start_learning($course)
})();

function init() {
    chapter_num = $('.listitem').length - 1
    $('[style="background:none;"]').remove()
    setting.div = $(
        $(
            '<div style="width: 300px; border: 3px hidden #000000; font-size: 20px; text-align: center; background-color: rgba(135,216,64,0.80); top: 30px; color: #000000; position: fixed; right: 30px;">' +
            '  <div>微知库网课助手</div>' +
            '	<br>' +
            '  <div style="font-size: 15px">温馨提示:必须启用本网站的Flash功能,否则会出现视频看完,进度不走的情况!</div>' +
            '  <br>' +
            '  <div>' +
            '    <div style="font-size">如发现bug,或希望加入新功能,请加群反馈</div>' +
            '    <br>' +
            '    <a href="https://jq.qq.com/?_wv=1027&k=5bH9G48" target="_blank" style="font-size: 20px; color: blue; text-decoration: underline;">点我一键加群</a> </div>' +
            '</div>'

        ).appendTo('body')
    )
}

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('当前是视频')
        setTimeout(() => {
            console.log('start playing')
            var playerId = $('[id^=ckplayer]').attr('id')
            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);
        }, 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) {
        return true
    } else {
        return false
    }
}
function is_compleated($course) {
    if ($course.attr('score') == '10') {
        return true
    } else {
        return false
    }
}