UOOCassistant

UOOC优课联盟,视频自动连播,自动二倍速播放(因为超过二倍速可能无法记录任务点),离开页面继续播放,自动回答视频中途弹出问题;如果视频一开始处于停止状态,可以手动点击播放;【有问题可以进行反馈】

目前為 2020-10-15 提交的版本,檢視 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         UOOCassistant
// @namespace    http://tampermonkey.net/
// @version      0.2
// @description  UOOC优课联盟,视频自动连播,自动二倍速播放(因为超过二倍速可能无法记录任务点),离开页面继续播放,自动回答视频中途弹出问题;如果视频一开始处于停止状态,可以手动点击播放;【有问题可以进行反馈】
// @author       cc
// @include      *
// @grant        none
// ==/UserScript==

(function () {
    'use strict';
    const jsName = 'UOOCassistant.js';
    const host = window.location.host;
    if (host == 'www.uooc.net.cn') {
        console.log(`excute ${jsName}`);
        let recursive = () => {
            let extraTime = 0;
            try {
                let done = false;
                let video = document.querySelector('#player_html5_api');
                if (video) {
                    video.playbackRate = 2;
                    video.autoplay = true;
                    if (video.ended) {
                        done = true;
                    };
                    let quizLayer = document.querySelector('#quizLayer');
                    if (quizLayer && quizLayer.style.display != 'none') {
                        if (done) {
                            setTimeout(() => {
                                document.querySelectorAll('.layui-layer-shade').forEach(e => e.style.display = 'none');
                            }, 1000);
                        };
                        let source = JSON.parse(document.querySelector('div[uooc-video]').getAttribute('source'));
                        let quizList = source.quiz;
                        let quizIndex = 0;
                        let currentTime = video.currentTime;
                        let quizQuestion = document.querySelector('.smallTest-view .ti-q-c').innerHTML;
                        for (let i = 0; i < quizList.length; i++) {
                            if (quizList[i].question == quizQuestion) {
                                quizIndex = i;
                                break;
                            };
                        };
                        let quizAnswer = eval(quizList[quizIndex].answer);
                        let quizOptions = quizLayer.querySelector('div.ti-alist');
                        for (let ans of quizAnswer) {
                            let labelIndex = ans.charCodeAt() - 'A'.charCodeAt();
                            quizOptions.children[labelIndex].click();
                        }; // end for
                        quizLayer.querySelector('button').click();
                        extraTime = 1000;
                    }; // end if
                    if (!done) {
                        if (video.paused) {
                            video.play();
                        } else {
                            document.querySelectorAll('.layui-layer-shade, #quizLayer').forEach(e => e.style.display = 'none');
                        };
                    };
                }; // end if (video)
                if (!done) {
                    console.log('continue recursive function...');
                    setTimeout(recursive, 250 + extraTime);
                } else {
                    console.log('done!');
                    if (video) {
                        let uncomplete_video = document.querySelector(`li[ng-repeat='pointItem in sectionItem.children'] div.uncomplete`);
                        if (!uncomplete_video) {
                            uncomplete_video = document.querySelector(`li[ng-repeat='sectionItem in chapterItem.children'] div.uncomplete`);
                        };
                        if (uncomplete_video) {
                            console.log('found uncomplete video, ready to click...');
                            uncomplete_video.click();
                            setTimeout(() => {
                                uncomplete_video.nextElementSibling.firstElementChild.click();
                                setTimeout(recursive, 1500);
                            }, 500);
                        } else {
                            console.log('not found uncomplete video, end recursive function.');
                        };
                    } else {
                        console.log('video not found');
                    };
                };
            } catch (e) {
                // do nothing
            };
        }; // end recursive
        recursive();
    }
})();