Greasy Fork

国家智慧教育公共服务平台|国家中小学智慧教育平台|教师研修|自动挂机刷课|自动答题

【bug+v:aluyunjiesmile】,中小学暑假研修,然后选择到你要看的网址。目前只支持暑假研修。

目前为 2023-07-25 提交的版本。查看 最新版本

// ==UserScript==
// @name         国家智慧教育公共服务平台|国家中小学智慧教育平台|教师研修|自动挂机刷课|自动答题
// @namespace    挂机刷课
// @version      4.5
// @license      CC BY-NC-SA
// @description  【bug+v:aluyunjiesmile】,中小学暑假研修,然后选择到你要看的网址。目前只支持暑假研修。
// @author       aluyunjie
// @match        https://basic.smartedu.cn/teacherTraining/courseDetail*
// @match        https://basic.smartedu.cn/training/*
// @match        https://basic.smartedu.cn/teacherTraining/courseIndex*
// @icon         https://www.zxx.edu.cn/favicon.ico
// @grant        GM_setValue
// @grant        GM_getValue
// ==/UserScript==

(function() {
    'use strict';
    createLogBox();
    addTextToLogBox("请转移到这个网址学习,如果已经从此网站进入,请无视。")
    addTextToLogBox("https://basic.smartedu.cn/training/2023sqpx")
    // 获取当前网址
    var currentURL = window.location.href;


    if (currentURL.includes("https://basic.smartedu.cn/training/2023sqpx")) {
        setTimeout(function(){

            //判断用户是否登录
            var isLogOBJ = document.querySelector("#root > div > div > div > div > div.fish-spin-nested-loading.x-edu-nested-loading > div > div:nth-child(1) > div:nth-child(1) > div > div > div.index-module_process_3RHjg > div")
            if(isLogOBJ === null){

            }else{
                var isLogin = document.querySelector("#root > div > div > div > div > div.fish-spin-nested-loading.x-edu-nested-loading > div > div:nth-child(1) > div:nth-child(1) > div > div > div.index-module_process_3RHjg > div").textContent;
                if(isLogin === '已开课'){
                    addTextToLogBox("请登录您的账号,并刷新页面");
                    return ;
                }else{
                    addTextToLogBox("脚本加载成功!");
                    addTextToLogBox("有bug请反馈:微信:aluyunjiesmile");
                    addTextToLogBox('脚本更新于2023-7-25');
                    addTextToLogBox('开始执行,请等待17秒');
                    setTimeout(ChosePageTimer, 17000);
                }

            }
        },2000)

    }

    if (currentURL.includes("https://basic.smartedu.cn/teacherTraining/courseIndex?courseId")) {
        addTextToLogBox("请等待!")
        setTimeout(function() {
            document.querySelector(
                "#root > div > div > div > div > div > div > section > div > div.CourseIndex-module_course_1_SiV > div.CourseIndex-module_course-action_2eWDh > a"
            ).click();
        }, 4000)
        setTimeout(function() {
            window.location.reload();
        }, 6000)

    }

    if (currentURL.includes('https://basic.smartedu.cn/teacherTraining/courseDetail?courseId')) {
        addTextToLogBox("已经进入视频播放界面!");
        setInterval(PlayingPageTimer, 5000);
    }




    // Your code here...
})();

function ChosePageTimer() {

    if(jugeMessionIsDone()){
        return;
    }else{
        choseClassPage_ChoseClass();
        setTimeout(function(){
            window.location.reload();
        },3000)

    }

}

function PlayingPageTimer() {


    jugeCurrentClassIsStudyDone();
    jugeVideoIsPlaying();
    jugePlayingPageNotPlay();


}



function jugeMessionIsDone(){
    var studyed = document.querySelector("#root > div > div > div > div > div.index-module_banner_3blPg > div.index-module_topprocess_22U2B > div.index-module_topprocessC_3zGqt > div:nth-child(2) > span.index-module_topprocessCMy_2Jl2Q").textContent;
    var studyhole = document.querySelector("#root > div > div > div > div > div.index-module_banner_3blPg > div.index-module_topprocess_22U2B > div.index-module_topprocessC_3zGqt > div:nth-child(2) > span:nth-child(2)").textContent;
    var num1 = parseFloat(studyed);
    var num2 = parseFloat(studyhole);
    if(num1 >= num2){
        addTextToLogBox("所有任务完成,结束!");
        return true;
    }else{
        return false;
    }
}

function jugePlayingPageNotPlay() {

    addTextToLogBox("检测首页学时是否足够!")
    var title = document.getElementsByClassName('fish-breadcrumb-link')[3].textContent;
    var jindu = GM_getValue(title);
    addTextToLogBox("外部首页显示进度:"+jindu);
    if(jindu === "完成"){
        window.close();
    }
    GM_setValue(title, "进行");


}

function jugeVideoIsPlaying() {
    var trueOrFasle = document.querySelector("video").paused;

    if (trueOrFasle) {
        addTextToLogBox("视频未在播放");

        //检测是否有题,
        if (shiFouYouTi()) {
            //有题--业务逻辑
            doQuestionAnwser();
        } else {
            //无题--业务逻辑
            PlayVideoButton();
        }

    } else {
        addTextToLogBox("视频正在播放,设置倍速3倍");
        //用户可以来看这个,最高3倍速播放,因为有限制,如果不信,你可以把下面的数字3改为1-16中的任何数字,代表的是1-16倍
        document.querySelector("video").playbackRate = 3;
    }
}


function choseClassPage_ChoseClass() {

    for (var i = 1; i < 8; i++) {
        var studyTitle;
        var studyedTime;
        var studyTime;
        //课程题目
        studyTitle = document.querySelector(
            "#root > div > div > div > div > div.fish-spin-nested-loading.x-edu-nested-loading > div > div:nth-child(1) > div:nth-child(" +
            i +
            ") > div > div > div.index-module_content_7FjRb > div.index-module_detail_1JEVZ > div.index-module_title_8i8E6"
        ).textContent;

        //已学
        var studyedTimeOBJ = document.querySelector(
            "#root > div > div > div > div > div.fish-spin-nested-loading.x-edu-nested-loading > div > div:nth-child(1) > div:nth-child(" +
            i +
            ") > div > div > div.index-module_process_3RHjg > div:nth-child(3) > span.index-module_processCMy_2HvHz"
        );
        if (studyedTimeOBJ === null) {
            studyedTime = '0'
        } else {
            studyedTime = document.querySelector(
                "#root > div > div > div > div > div.fish-spin-nested-loading.x-edu-nested-loading > div > div:nth-child(1) > div:nth-child(" +
                i +
                ") > div > div > div.index-module_process_3RHjg > div:nth-child(3) > span.index-module_processCMy_2HvHz"
            ).textContent;
        }
        //应学
        var studyTimeOBJ = document.querySelector(
            "#root > div > div > div > div > div.fish-spin-nested-loading.x-edu-nested-loading > div > div:nth-child(1) > div:nth-child(" +
            i + ") > div > div > div.index-module_process_3RHjg > div:nth-child(3) > span:nth-child(2)");
        if (studyTimeOBJ === null) {
            studyTime = '0';
        } else {
            studyTime = document.querySelector(
                "#root > div > div > div > div > div.fish-spin-nested-loading.x-edu-nested-loading > div > div:nth-child(1) > div:nth-child(" +
                i + ") > div > div > div.index-module_process_3RHjg > div:nth-child(3) > span:nth-child(2)")
                .textContent;
        }

        var num1 = parseFloat(studyedTime);
        var num2 = parseFloat(studyTime);
        addTextToLogBox("题目:" + studyTitle + ",已学:" + studyedTime + "应学:" + studyTime);
        if (num1 >= num2) {
            addTextToLogBox("执行设置值")
            GM_setValue(studyTitle, "完成");
        }

        var isChoseed = GM_getValue(studyTitle);
        console.log(isChoseed)
        if (isChoseed === "进行") {
            addTextToLogBox(studyTitle + "已经选过,等待刷课")
            break;
        }

        if (num1 < num2) {
            addTextToLogBox(studyTitle + "未完成,开始选择")
            document.querySelector(
                "#root > div > div > div > div > div.fish-spin-nested-loading.x-edu-nested-loading > div > div:nth-child(1) > div:nth-child(" +
                i +
                ") > div > div > div.index-module_content_7FjRb > div.index-module_detail_1JEVZ > div.index-module_title_8i8E6"
            ).click();
            //防止在外部选课页面出现bug,这里的设置进行,应放在视频播放页面
            // GM_setValue(studyTitle, "进行");
            break;
        }

    }
    if(i>= 8){
        var studyTitle = document.querySelector("#rc-tabs-0-panel-c227b3de-65e4-4cb8-957c-d8ab4bbc0cc6 > div:nth-child(2) > div > div > div.index-module_content_7FjRb > div.index-module_detail_1JEVZ > div.index-module_title_8i8E6").textContent;
        var isChoseed = GM_getValue(studyTitle);
        if (isChoseed === "进行") {
            addTextToLogBox(studyTitle + "已经选过,等待刷课")
            return 0;
        }
        document.querySelector("#rc-tabs-0-panel-c227b3de-65e4-4cb8-957c-d8ab4bbc0cc6 > div:nth-child(2) > div > div > div.index-module_content_7FjRb > div.index-module_detail_1JEVZ > div.index-module_title_8i8E6").click();

        GM_setValue(studyTitle, "进行");

    }

}




function jugeCurrentClassIsStudyDone() {
    var titleText = document.getElementsByClassName('resource-item resource-item-train resource-item-active')[0].getElementsByTagName('i')[1].title

    if (titleText == '未开始') {
        addTextToLogBox("当前视频暂未看完");
    }


    if (titleText == '进行中') {
        addTextToLogBox("当前视频暂未看完。");
        addTextToLogBox("请保持在本页,要不会暂停播放视频");
    }

    if (titleText == '已学完') {
        addTextToLogBox("当前视频已经看完,选择下一个");

        findNextVideoPlay();
		setTimeout(function() {
		    window.location.reload();
		}, 2000)
    }

}



//找到下一个播放的视频
function findNextVideoPlay() {
    //stp01,先进行遍历点击,让iconfont icon_checkbox_linear   可以显示出来
    for (var i = 0; i < 10; i++) {
        var clickButton = document.getElementsByClassName('fish-collapse-header')[i];
        if (clickButton === undefined) {
            break;
        } else {
            clickButton.click();
        }
    }
    //stp02,先找进行中的视频观看,如果没有进行中的视频,则找未观看的视频
    for (var j = 0; i < 10; i++) {
        var nextVideo = document.getElementsByClassName('iconfont icon_processing_fill')[j];
        if (nextVideo === undefined) {
            continue;
        } else {
            nextVideo.click()
        }

    }
    //set03,找不到视频就点击未观看的视频进行点击观看
    document.getElementsByClassName('iconfont icon_checkbox_linear')[0].click();


    setTimeout(PlayVideoButton,2000)
}

function danjixiayitianniu() {
    //单击下一题按钮
    document.querySelector(
        "#root > div > div > div > div > div > div > div.index-module_detail-main_bdFS3 > div.index-module_detail-main-l_1b8KB > div.index-module_video-wrapper_22Dc0 > div > div.index-module_markerExercise_KM5bU > div > div.index-module_footer_3r1Yy > button"
    ).click()
}


function doQuestionAnwser() {
    addTextToLogBox("做题");

    var tixing = document.getElementsByClassName('_qti-title-prefix-qtype')[0].textContent;
    if (tixing == '单选题') {
        addTextToLogBox("题型为单选题")
        console.log("题型为单选题")
        console.log("开始做题")
        //选择第一项
        document.getElementsByClassName("nqti-check")[0].click()

        setTimeout(danjixiayitianniu(), 1000)
        setTimeout(danjixiayitianniu(), 1000)
    }
    if (tixing == '多选题') {
        addTextToLogBox("题型为多选")
        console.log("题型为多选")
        console.log("开始做题")
        //选择第一项
        document.getElementsByClassName("nqti-check")[0].click()
        //选择第二项
        document.getElementsByClassName("nqti-check")[1].click()
        document.querySelector(
            "#root > div > div > div > div > div > div > div.index-module_detail-main_bdFS3 > div.index-module_detail-main-l_1b8KB > div.index-module_video-wrapper_22Dc0 > div > div.index-module_markerExercise_KM5bU > div > div.index-module_footer_3r1Yy > button"
        ).click()
        setTimeout(danjixiayitianniu(), 1000)
        setTimeout(danjixiayitianniu(), 1000)
    }
    if (tixing == '判断题') {
        addTextToLogBox("题型为判断")
        console.log("题型为判断")
        console.log("开始做题")
        //选择第一项
        document.getElementsByClassName("nqti-check")[0].click()

        document.querySelector(
            "#root > div > div > div > div > div > div > div.index-module_detail-main_bdFS3 > div.index-module_detail-main-l_1b8KB > div.index-module_video-wrapper_22Dc0 > div > div.index-module_markerExercise_KM5bU > div > div.index-module_footer_3r1Yy > button"
        ).click()
        setTimeout(danjixiayitianniu(), 1000)
        setTimeout(danjixiayitianniu(), 1000)
    }

}



//检测是否有题,如果有题则返回true ,否则返回false
function shiFouYouTi() {

    var question = document.getElementsByClassName('question_player-container question_player')[0];
    if (question === undefined) {
        addTextToLogBox("检测无题")
        return false;
    } else {
        addTextToLogBox("检测有题");
        return true;
    }

}



function PlayVideoButton() {

    //切换新的视频进行点击我知道了/为空则为undefined
    var button = document.getElementsByClassName('fish-modal-body')[0];
    if(button === undefined){

    }else{
        button.getElementsByTagName('button')[0].click();
    }


    //点击播放按钮,为空则为undefined
    addTextToLogBox("点击按钮,如果长时间没反应,请点击一下当前页面");
    document.getElementsByClassName('vjs-big-play-button')[0].click();


    var iknow = document.querySelector(
        "#main-content > div.content > div.index-module_container_4pMtL > div > div > micro-app > micro-app-body > div:nth-child(7) > div > div.fish-modal-wrap > div > div.fish-modal-content > div > div > div.fish-modal-confirm-btns > button"
    );
    if (iknow === null) {

    } else {
        iknow.click();
    }


}

//日志函数
function addTextToLogBox(TextLog) {

    // 获取目标 <div> 元素
    var targetDiv = document.getElementById('logBox'); // 替换为你的目标 <div> 元素的 ID
    targetDiv.appendChild(document.createElement('br'));
    // 创建文本节点
    var textNode = document.createTextNode(TextLog);
    // 添加文本节点到目标 <div> 元素
    targetDiv.appendChild(textNode);
    targetDiv.scrollTop = targetDiv.scrollHeight;

}

//创建日志框
function createLogBox() {
    var logBox = document.createElement('div');
    logBox.id = 'logBox';
    logBox.style.position = 'fixed';
    logBox.style.bottom = '0';
    logBox.style.left = '0';
    logBox.style.width = '200px';
    logBox.style.height = '200px';
    logBox.style.backgroundColor = 'black'; // 更改背景颜色为黑色
    logBox.style.color = 'green'; // 更改文本颜色为绿色
    logBox.style.overflow = 'auto';
    logBox.style.padding = '10px';
    logBox.style.fontFamily = 'Arial, sans-serif';
    logBox.style.whiteSpace = 'pre-wrap';
    document.body.appendChild(logBox);

}