Greasy Fork

Greasy Fork is available in English.

UOOC assistant

【使用前先看介绍/有问题可反馈】【欢迎一键三连(好评+打赏+收藏),你的支持是作者维护下去的最大动力!】UOOC优课联盟助手(UOOC assistant):视频自动连播,可选自动二倍速播放(因为超过二倍速可能无法记录任务点),可选是否静音,可选是否播放,离开页面能够继续保持状态,自动回答视频中途弹出问题;键盘左右方向键可控制快进快退;自动签到慕课;如果视频标题下面出现 倍速/静音/播放 选项说明脚本正常启动运行。

当前为 2020-11-06 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

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

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         UOOC assistant
// @name:en      UOOC assistant
// @namespace    http://tampermonkey.net/
// @version      0.8.2
// @description  【使用前先看介绍/有问题可反馈】【欢迎一键三连(好评+打赏+收藏),你的支持是作者维护下去的最大动力!】UOOC优课联盟助手(UOOC assistant):视频自动连播,可选自动二倍速播放(因为超过二倍速可能无法记录任务点),可选是否静音,可选是否播放,离开页面能够继续保持状态,自动回答视频中途弹出问题;键盘左右方向键可控制快进快退;自动签到慕课;如果视频标题下面出现 倍速/静音/播放 选项说明脚本正常启动运行。
// @description:en  【使用前先看介绍/有问题可反馈】【欢迎一键三连(好评+打赏+收藏),你的支持是作者维护下去的最大动力!】UOOC优课联盟助手(UOOC assistant):视频自动连播,可选自动二倍速播放(因为超过二倍速可能无法记录任务点),可选是否静音,可选是否播放,离开页面能够继续保持状态,自动回答视频中途弹出问题;键盘左右方向键可控制快进快退;自动签到慕课;如果视频标题下面出现 倍速/静音/播放 选项说明脚本正常启动运行。
// @author       cc
// @include      http://www.uooc.net.cn/*
// @grant        none
// ==/UserScript==

(function () {
    'use strict';
    const jsName = 'UOOC-assistant.js';
    if (location.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) {
                    if (document.getElementById('rate').checked)
                        video.playbackRate = 2;
                    else
                        video.playbackRate = 1;
                    if (document.getElementById('volume').checked)
                        video.muted = true;
                    else
                        video.muted = false;
                    if (document.getElementById('play').checked && !video.ended)
                        video.play();
                    else
                        video.pause();
                    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 && document.getElementById('play').checked) {
                            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) {
                        console.log('found video exists.');
                        let current_video = document.querySelector('.basic.active');
                        let next_video = current_video.nextElementSibling;
                        while (next_video && !next_video.querySelector('span.icon-video')) {
                            next_video = next_video.nextElementSibling;
                        };
                        if (next_video && next_video.querySelector('span.icon-video')) {
                            console.log('found next_video.');
                            next_video.click();
                            setTimeout(recursive, 500);
                        } else {
                            console.log('not found next_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(uncomplete_video);
                                console.log('found uncomplete video, ready to click...');
                                uncomplete_video.click();
                                setTimeout(() => {
                                    let ul = uncomplete_video.parentNode.querySelector('ul');
                                    if (ul && ul.querySelector('.basic')) {
                                        console.log('found useful ul.');
                                        let next_video = uncomplete_video.parentNode.querySelector('ul').querySelector('.basic');
                                        next_video.click();
                                        setTimeout(() => {
                                            next_video.nextElementSibling.querySelector('.basic').click();
                                            setTimeout(recursive, 1000);
                                        }, 500);
                                    } else {
                                        console.log('not found useful ul.');
                                        uncomplete_video.nextElementSibling.firstElementChild.click();
                                        setTimeout(recursive, 1000);
                                    }
                                }, 500);
                            } else {
                                let next_section = document.querySelector('li div.basic.active').parentNode.parentNode.parentNode.parentNode.nextElementSibling.firstChild;
                                console.log('next_section as follows:');
                                console.log(next_section);
                                if (next_section) {
                                    console.log('found uncomplete section, ready to click...');
                                    next_section.click();
                                    setTimeout(() => {
                                        let next_video = next_section.nextElementSibling.firstElementChild;
                                        if (next_video.firstElementChild) {
                                            console.log('found next video, ready to click...');
                                            next_video.firstElementChild.click();
                                            setTimeout(() => {
                                                next_video.querySelector('div:nth-child(2) > div.basic').click();
                                                setTimeout(recursive, 500);
                                            }, 500);
                                        } else {
                                            console.log('not found next video, end recursive function.');
                                        };
                                    }, 500);
                                } else {
                                    let complete_items = document.querySelectorAll('.complete');
                                    let complete_video = complete_items.item(complete_items.length - 1);
                                    let uncomplete_video = complete_video.nextElementSibling;
                                    if (uncomplete_video) {
                                        console.log('found next video in the list.')
                                        uncomplete_video.click();
                                        setTimeout(recursive, 1000);
                                    } else {
                                        console.log('not found next video in the list.');
                                        complete_video = document.querySelector('.basic.active');
                                        let next_chapter = complete_video.parentNode.parentNode.nextElementSibling;
                                        if (next_chapter) {
                                            console.log('found next chapter of next chapter in the list.');
                                            next_chapter.firstElementChild.click();
                                            setTimeout(() => {
                                                let next_sub_chapter = next_chapter.querySelector('ul').querySelector('.basic.uncomplete');
                                                if (next_sub_chapter) {
                                                    console.log('found next chapter of next sub chapter in the list.');
                                                    next_sub_chapter.click();
                                                    setTimeout(() => {
                                                        let next_video = next_sub_chapter.nextElementSibling.querySelector('div');
                                                        if (next_video) {
                                                            console.log('found next video in next chapter of next sub chapter in the list.');
                                                            next_video.click();
                                                            setTimeout(recursive, 500);
                                                        } else {
                                                            console.log('not found next video in next chapter of next sub chapter in the list, end recursive function.');
                                                        };
                                                    }, 500);
                                                } else {
                                                    console.log('not found next chapter of next sub chapter in the list, end recursive function.');
                                                };
                                            }, 500);
                                        } else {
                                            console.log('not found next video of next chapter in the list.');
                                        };
                                    };
                                    console.log('not found uncomplete video, end recursive function.');
                                };
                            };
                        };
                    } else {
                        console.log('video not found.');
                    };
                };
            } catch (e) {
                console.log(e);
            };
        }; // end recursive
        let wait = () => {
            if (document.readyState == 'complete') {
                console.log('ready to set checkboxes.');
                let getCheckbox = (name, text) => {
                    let p = document.createElement('p');
                    p.style.color = '#cccccc';
                    let checkbox = document.createElement('input');
                    checkbox.id = name;
                    checkbox.type = 'checkbox';
                    checkbox.checked = true;
                    checkbox.name = name;
                    checkbox.value = name;
                    checkbox.style.marginLeft = '25px';
                    p.append(checkbox);
                    let label = document.createElement('label');
                    label.setAttribute('for', name);
                    label.innerText = text;
                    label.style.marginLeft = '15px';
                    p.append(label);
                    p.style.margin = '5px';
                    return p;
                };
                let rateCheckbox = getCheckbox('rate', '倍速');
                let volumeCheckbox = getCheckbox('volume', '静音');
                let playCheckbox = getCheckbox('play', '播放');
                let head = document.querySelector('.learn-head');
                let container = document.createElement('div');
                container.id = 'container';
                container.style.display = 'flex';
                container.style.flexDirection = 'row';
                container.style.alignItems = 'center';
                container.append(rateCheckbox);
                container.append(volumeCheckbox);
                container.append(playCheckbox);
                let a = document.createElement('a');
                a.href = 'https://s1.ax1x.com/2020/10/23/BEnDsS.png';
                a.target = '_blank';
                a.innerHTML = '<u>本脚本使用完全免费,您的打赏是作者维护下去的最大动力!点此打赏作者😊</u>';
                a.style.color = '#cccccc';
                a.style.fontWeight = 'bold';
                a.style.height = 'min-height';
                a.style.margin = '0px 20px 0px';
                a.style.padding = '2px 5px 2px';
                a.style.bordRadius = '5px';
                a.style.fontSize = '13px';
                container.appendChild(a);                
                head.append(container);
                console.log('checkboxes have been set.');
                let cid = location.href.match(/\d+/g)[0];
                let httpRequest = new XMLHttpRequest();
                httpRequest.open('GET', `http://www.uooc.net.cn/home/course/info?cid=${cid}`, true);
                httpRequest.send();
                httpRequest.onreadystatechange = function () {
                    if (httpRequest.readyState == 4 && httpRequest.status == 200) {
                        console.log('Automatic sign-in succeeded.');
                    } else {
                        console.log('Automatic sign-in failed.');
                    };
                };
                document.onkeydown = (event) => {
                    let e = event || window.event;
                    let k = event.key;
                    let complete = false;
                    let div = document.querySelector('div.basic.active');
                    if (div && div.classList.contains('complete'))
                        complete = true;
                    let video = document.getElementById('player_html5_api');
                    if (video) {
                        switch (k) {
                            case 'ArrowLeft':
                                video.currentTime -= 10;
                                break;
                            case 'ArrowRight':
                                if (complete)
                                    video.currentTime += 10;
                                break;
                        };
                    };
                };
                recursive();
            } else {
                setTimeout(wait, 200);
            };
        }; // end wait
        wait();
    }
})();