ulearning

课程思政网络培训的视频每隔几分钟会暂停播放,这个脚本可以帮你自动(每分钟检测一次)继续播放,还可以跳过非视频的页面(这个功能没有仔细测试)。只支持在同一个课程内自动播放,播放结束后跳到下一章节,所以请选择一个学分数很大的课程来挂课。

目前為 2021-05-16 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         ulearning
// @namespace    http://tampermonkey.net/
// @version      1.2.0
// @description  课程思政网络培训的视频每隔几分钟会暂停播放,这个脚本可以帮你自动(每分钟检测一次)继续播放,还可以跳过非视频的页面(这个功能没有仔细测试)。只支持在同一个课程内自动播放,播放结束后跳到下一章节,所以请选择一个学分数很大的课程来挂课。
// @author       laohoo
// @match        https://ua.ulearning.cn/learnCourse/learnCourse.html*
// @icon         https://www.google.com/s2/favicons?domain=ulearning.cn
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    console.log(Date(), 'Let me go.');
    let tiemOut = 1000*60;  // 检测间隔时间,默认为一分钟(1000*60)一次
    let lists = [];
    let vFlag = '';
    let speed = 1.50;

    let video_list =[];

    function getPlayList(){
        lists = document.querySelectorAll('.page-item div.page-name.cursor');
        console.log(lists);
        return lists;
    }

    function setSpeed(){
        let speed_button = document.querySelector('.mejs__speed-button button');
        console.log(Date(),'speed_button: ',speed_button );
        if(speed_button){
            if(speed_button.innerText==='1.00x'){
                let speed = document.querySelector('li.mejs__speed-selector-list-item > input');
                console.log(Date(),'speed: ',speed );
                if(speed){
                    console.log(Date(), 'set speed 1.50x' );
                    speed.click();
                }
            }
        }

    }

    function nextPage(){
        let nextBtn = document.querySelector('.next-page-btn');
        let step = 2;
        console.log(Date(), 'next page.');

        let btn_hollow = document.querySelector('button.btn-hollow');
        if(btn_hollow){
            console.log(Date(), 'button.btn-hollow is click.');
            btn_hollow.click();
        }else if(nextBtn){
            console.log(Date(), '.next-page-btn is click.');
            nextBtn.click();
        }
    }

    function nextActivePage(){
        if(lists.length){
            console.log(Date(), 'play lists.');
            for(var index in lists){
                if(!(lists[index].classList.contains('complete')|| lists[index].classList.contains('active'))){
                    let iconFont = lists[index].querySelector('.page-icon i.iconfont');
                    if(iconFont.innerText ===vFlag){
                        console.log(Date(), 'not complete, not active. ',lists[index]);
                        lists[index].click();
                        break;
                    }
                }
            }
        }
    }

    function toContinue(){
        let pause = document.querySelector('div.modal-operation button.btn-submit');
        if(pause){
            console.log(Date(),'it is pause, continue...');
            pause.click();
        }
    }

    setInterval(function(){
        try{
            let btn_play = document.querySelector('.mejs__overlay-play');
            let playStatus = document.querySelector('div.video-progress  div.text span');
            console.log(Date(), 'btn_play: ',btn_play);
            if(lists.length<2){
                getPlayList();
            }

            if(!btn_play){
                nextPage();
            }else{
                if(btn_play.style.display!=='none'){
                    if(playStatus.innerText !='已看完'){
                        btn_play.click();
                        console.log(Date(), 'play continue... ');
                    }else{
                        nextActivePage();
                    }
                }else{
                    console.log(Date(), playStatus.innerText);
                }
            }

            setSpeed();
            toContinue();
        }
        catch(e){
            console.log(Date(), "Error in this userscript: ",e.message);
        }
    }, tiemOut);



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