电信网上大学超级学习

除了不能替你考试(暂时),更快、更全、更好用的电信网上大学学习工具。

目前为 2023-08-18 提交的版本。查看 最新版本

// ==UserScript==
// @name        电信网上大学超级学习
// @namespace   remain_true_to_our_original_aspiration
// @version     1.0.2
// @description 除了不能替你考试(暂时),更快、更全、更好用的电信网上大学学习工具。
// @author      Ghost River
// @match       https://kc.zhixueyun.com/*
// @icon        data:image/gif;base64,R0lGODlhIAAgAPcAAAAAAAAAMwAAZgAAmQAAzAAA/wArAAArMwArZgArmQArzAAr/wBVAABVMwBVZgBVmQBVzABV/wCAAACAMwCAZgCAmQCAzACA/wCqAACqMwCqZgCqmQCqzACq/wDVAADVMwDVZgDVmQDVzADV/wD/AAD/MwD/ZgD/mQD/zAD//zMAADMAMzMAZjMAmTMAzDMA/zMrADMrMzMrZjMrmTMrzDMr/zNVADNVMzNVZjNVmTNVzDNV/zOAADOAMzOAZjOAmTOAzDOA/zOqADOqMzOqZjOqmTOqzDOq/zPVADPVMzPVZjPVmTPVzDPV/zP/ADP/MzP/ZjP/mTP/zDP//2YAAGYAM2YAZmYAmWYAzGYA/2YrAGYrM2YrZmYrmWYrzGYr/2ZVAGZVM2ZVZmZVmWZVzGZV/2aAAGaAM2aAZmaAmWaAzGaA/2aqAGaqM2aqZmaqmWaqzGaq/2bVAGbVM2bVZmbVmWbVzGbV/2b/AGb/M2b/Zmb/mWb/zGb//5kAAJkAM5kAZpkAmZkAzJkA/5krAJkrM5krZpkrmZkrzJkr/5lVAJlVM5lVZplVmZlVzJlV/5mAAJmAM5mAZpmAmZmAzJmA/5mqAJmqM5mqZpmqmZmqzJmq/5nVAJnVM5nVZpnVmZnVzJnV/5n/AJn/M5n/Zpn/mZn/zJn//8wAAMwAM8wAZswAmcwAzMwA/8wrAMwrM8wrZswrmcwrzMwr/8xVAMxVM8xVZsxVmcxVzMxV/8yAAMyAM8yAZsyAmcyAzMyA/8yqAMyqM8yqZsyqmcyqzMyq/8zVAMzVM8zVZszVmczVzMzV/8z/AMz/M8z/Zsz/mcz/zMz///8AAP8AM/8AZv8Amf8AzP8A//8rAP8rM/8rZv8rmf8rzP8r//9VAP9VM/9VZv9Vmf9VzP9V//+AAP+AM/+AZv+Amf+AzP+A//+qAP+qM/+qZv+qmf+qzP+q///VAP/VM//VZv/Vmf/VzP/V////AP//M///Zv//mf//zP///wAAAAAAAAAAAAAAACH5BAEAAPwALAAAAAAgACAAAAj/APcJHEiw4D5i9AwqXLiwnR9UD3nVY8iQXsKFxGr5eXWRIsFCfgrSs1XrFS93+2z54eVx4LBXqAqiKsSrly2QLDe23DfzIU2BtQbqQ/XqlcBXhDxqTGjrVch9fughpPfn51GjC3v5mbiPECquKmfSc5VqGEE/vRbaGuiwo621+3oRKtRxn0OGL/38cbWRZS+W+4rGLPgKbkGVtdwFDexnWDunM18VMkjvKeG1vP4E3ZjX1jCVdQf6aWfwMy/O9ZwWdKzW8EB6Md1F5UXIFkqplfcNa7x6cMFCw1wVmomqskaOm1G53pfbIC9Uvcz6Wcv5YNFCy5lbJuiu48WtApXNrSStcLtHVPqG9SpZEKHA5gYz+rFM6E9MrQV5ASbme2AviETB1RQqZg0FmECpAMbLYgM9R0haBM1kWCGpECJZZAhCSJCGZ2H13kaFIKWcdjsJRIxCnxVmVkoMltiSMuC5uNOILSVkkY0HMUfYZDthtg9La7mSEkEauWjLIhOl1Ys+xNQkWioyrhXUWrbUY5ZRp7W400XK0LMkc/QM9wd5MopE4Xy1rFgmZY6FtlBAADs=
// @license     GPL3
// @grant       GM_openInTab
// @grant       GM_getValue
// @grant       GM_setValue
// @grant       GM_deleteValue
// @grant       GM_addValueChangeListener
// @grant       GM_removeValueChangeListener
// @grant       window.close
// @grant       window.focus
// ==/UserScript==

(function() {
    'use strict';
    if (!window.location.href.match('/train-new/class-detail/|/study/subject/detail/|/study/course/detail/')) return;
    //非学习页面退出。

    var max = 4;
    //最大同时学习课程数。如果同时学习的数量大于1,则需要同时启用另外名为“电信网上大学超级学习多开支持”的插件。

    var lessons = [];
    var lessonsinfo = {};
    var sections = [];
    var isTrain = false;
    var initID = '';
    var hasExam = [];
    var hasError = [];
    var currentSection = '';
    var studying = {};
    var count = 0;
    var listenerId = null
    var urls = { 'normal':'https://kc.zhixueyun.com/#/study/course/detail/11&$id$/6/1',
                'course':'https://kc.zhixueyun.com/#/study/course/detail/11&$id$/5/1'}

    var isCourse = window.location.href.match("/study/course/detail/")
    //是否学习页

    function checkStatus(){
        setTimeout(function () {
            if($('.chapter-list-box.required[data-sectiontype!=9]:not(:contains("重新学习"))').find('i.iconfont:not(.icon-suo)').length==0){
                GM_sendMessage('remain.true.to.our.original.aspiration', window.location.href.slice(-40,-4),"finished with exam is "+ ($('.chapter-list-box.required[data-sectiontype=9]').length>0));
                window.close();
            }else{
                GM_sendMessage('remain.true.to.our.original.aspiration', window.location.href.slice(-40,-4),"studying " + $('dl.chapter-list-box.required.focus').find('span.progress').text());
                autoPlay();
                checkStatus();
            }
        }, 17000);
    }

    function autoPlay() {
        if($('video').length>0) {
            if ($('video')[0].onpause === null) {
               $('video')[0].onpause = function() {
                   $('video').muted = true;
                   $('video')[0].play();
               };
            }
            $('video')[0].muted = true;
            $('video')[0].play();
        }
    }

    if( !isCourse ) {
        let r = sessionStorage.getItem(window.location.href.slice(-36));
        if (r) {
            let rhtml = JSON.parse(r);
            $(rhtml).appendTo("body");
        } else {
            GM_deleteValue('remain.true.to.our.original.aspiration')
            $('<div id="autostudydiv" style="position: fixed; top: 2%; left: 1%; z-index: 99999;">'+
              '<a id="autostudy" class="cd-btn cd-btn-primary" >自动学习</a>'+
              '<a id="wsView" style="display:none;color:red;">查看详细情况⯆</a><div id="progress" style="display:none; background-color: skyblue;"></div>'+
              '</div>').appendTo("body");
            //课程列表页,增加学习按钮
        }
    } else {
        let r = sessionStorage.getItem(window.location.href.slice(-40,-4));
        if (r) {
            console.log('非自动学习打开的页面不处理。');
            return;
        }
        //非自动学习打开的页面不处理。
        initID = window.location.href.slice(-40,-4);
        setTimeout(function () {
            if( !window.location.href.match(initID)) {
                //资源不存在
                GM_sendMessage('remain.true.to.our.original.aspiration', initID,"finished with error");
                window.close();
            } else {
                if($('.chapter-list-box.required[data-sectiontype!=9]:not(:contains("重新学习"))').length>0) {
                    $('.chapter-list-box.required[data-sectiontype!=9]:not(:contains("重新学习"))')[0].click();
                }
                autoPlay();
                checkStatus();
            }
        }, 5000)
    }

    $("#wsView").click(function () {
        if($('#progress').is(':hidden')){
            $("#progress").show();
            $("#wsView").text('查看详细情况▲');
        }else{
            $("#progress").hide();
            $("#wsView").text('查看详细情况▼');
        }
    });

    function GM_onMessage(label, callback) {
        listenerId = GM_addValueChangeListener(label, function() {
            callback.apply(undefined, arguments[2]);
        });
    }

    function GM_sendMessage(label) {
        GM_setValue(label, Array.from(arguments).slice(1));
    }

    function studyFinised() {
        if(lessonsinfo == null) return;
        let resultStr = '所有课程学习完成!'
        let url = '';
        if(isTrain) {
            url = urls['course'];
        } else {
            url = urls['normal'];
        }
        let ul = '';
        if (hasError.length>0) {
            resultStr += '部分课程资源不存在!';
            hasError.forEach(function(id){
                ul += '<li><a href="' + url.replace('$id$',id) + '" target="_blank">' + lessonsinfo[id] + '</a></li>'
            })
        }
        if (hasExam.length>0) {
            resultStr += '注意!部分课程包含考试!';
            hasExam.forEach(function(id){
                ul += '<li><a href="' + url.replace('$id$',id) + '" target="_blank"><span style="color:red;">' + lessonsinfo[id] + '<span></a></li>'
            })
        }
        $("#autostudy").text(resultStr)
        lessonsinfo = null;
        if(listenerId != null) GM_removeValueChangeListener(listenerId);
        GM_deleteValue('remain.true.to.our.original.aspiration');
        if(resultStr == '所有课程学习完成!') {
            $("#wsView").remove();
            $('#progress').remove();
            if(Math.random()>0.9) {
                $("#autostudy").append('<a href="https://gf.qytechs.cn/zh-CN/scripts/472634-%E7%94%B5%E4%BF%A1%E7%BD%91%E4%B8%8A%E5%A4%A7%E5%AD%A6%E8%B6%85%E7%BA%A7%E5%AD%A6%E4%B9%A0"><span style="color:red;">的确好用,给作者打赏。</span></a>')
            }
        } else {
            $('#progress').append('<ul>' + ul + '</ul>');
            $("#wsView").show();
            $('#progress').show();
        }
        sessionStorage.setItem(window.location.href.slice(-36),JSON.stringify($('#autostudydiv').prop("outerHTML")))
        location.reload();
    }

    function return2Contral() {
        window.focus();
        if($('#progress').is(':hidden')){
            $("#wsView").click();
        }
    }

    function doStudy() {
        if(lessons.length == 0) {
            if(count == 0) studyFinised();
            return2Contral()
            return;
        }
        if(listenerId === null) {
            GM_onMessage('remain.true.to.our.original.aspiration', function(src, message) {
                if( !isCourse && (src in studying)){
                    if(message.startsWith('studying')) {
                        let per = message.replace('studying ','');
                        if(per) $('#p'+ src).text(per)
                        studying[src] = true;
                        return;
                    }
                    if( message.endsWith("true")) hasExam.push(src)
                    if( message.endsWith("error")) hasError.push(src)
                    count--;
                    $('#' + src).remove();
                    delete studying[src]
                    if(count == 0) {
                        studyFinised();
                    } else {
                        if(lessons.length > 0) {
                            doStudy()
                        }
                        $("#autostudy").text('自动学习中,学习中课程:' + count + ',待学习课程:' + lessons.length + '。')
                    }
                }
            })
        }
        $("#wsView").show();
        if (count < max) {
            let url = ''
            if(isTrain) {
                url = urls['course']
            } else {
                url = urls['normal']
            }
            let id = lessons.shift()
            url = url.replace('$id$',id)
            studying[id] = true;
            $('#progress').append('<div id="' + id + '">' + lessonsinfo[id] + '<span id="p' + id + '" style="float:right;">待上报</div>')
            count++;
            $("#autostudy").text('自动学习中,学习中课程:' + count + ',待学习课程:' + lessons.length + '。')
            GM_openInTab(url,{ active: true, insert: true, setParent :true });
            setTimeout(function(){
               doStudy();
            },9000);
        } else {
            return2Contral()
        }
    }

    function getlessons(callback) {
        if (sections.length==0)
        {
            doStudy();
            return;
        }
        currentSection = sections.shift();
        let tk = $('#' + currentSection);
        console.log('当前学习板块: ' + currentSection)
        if(tk.attr('title') != '收起') {
            tk.click();
        }
        setTimeout(function(){
            $('div.train-citem:contains(未完成)').each(function() {
                $(this).find('.m-bottom.row-title-a.pointer').each(function() {
                    if(!$(this).attr('title').includes('考试')) {
                        let id = $(this).attr('id').slice(-36);
                        console.log('待学习课程id: ' + id);
                        lessons.push(id);
                        lessonsinfo[id] = $(this).attr("title");
                    }
                })
            })
            getlessons(callback);
        },2000);
    }

    function heartbeat() {
        if(count == 0) return;
        setTimeout(function(){
            console.log('检查心跳')
            let needRestart = false;
            for(var key in studying) {
                if(!studying[key]) {
                    console.log(key + ' 异常停止,重启')
                    needRestart = true;
                    lessons.unshift(key);
                    delete studying[key];
                     $('#' + key).remove();
                    count--;
                }
                studying[key] = false;
            }
            if(needRestart) doStudy()
            heartbeat()
        },119000)
    }

    $("#autostudy").click(function () {
        if($(this).text() != "自动学习") return
        $(this).text('获取课程中')
        console.log('开始')
        if( lessons.length > 0) return;
        $('.pointer.iconfont[id][title]').each(function() {
            sections.push($(this).attr('id'))
        })
        if(sections.length == 0) {
            console.log('普通课程');
            $("div.item.current-hover").each(function(index,element){
                if($(this).find("i.icon-reload").length==0 && $(this)[0].firstElementChild.querySelector("span.section-type").innerText == "课程"){
                    let id = $(this).attr("data-resource-id").slice(-36);
                    lessons.push(id);
                    lessonsinfo[id] = $(this).find('.inline-block.name-des.default-skin.text-overflow').attr("title");
                }
            })
            doStudy();
        } else {
            console.log('培训班');
            isTrain = true;
            getlessons(doStudy);
        }
        heartbeat()
    });
})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址