Greasy Fork is available in English.

超星尔雅助手

后台静音播放(自动),可以5秒内一节,部分课程可自动切换(可以先不答题的才可以开启)

您查看的为 2018-09-20 18:00:11 UTC 提交的版本。查看 最新版本

// ==UserScript==
// @icon            https://ss0.baidu.com/73t1bjeh1BF3odCf/it/u=3507160010,2121752339&fm=77&s=1947387E66836BF52423D3FB0300A01E
// @name			超星尔雅助手
// @namespace       http://tampermonkey.net/
// @author			fpschen
// @description		后台静音播放(自动),可以5秒内一节,部分课程可自动切换(可以先不答题的才可以开启)
// @description		窗口最小化时,自动切换功能发生错误(错误等同于开了5秒模式)
// @version			1.0.8
// @match			*://*.chaoxing.com/mycourse/*
// @requier         https://mooc1-1.chaoxing.com/js/build/jquery.js
// @supportURL      https://greasyfork.org/zh-CN/scripts/372319/feedback
// @grant			none
// ==/UserScript==


var player, course, currents, cursor;
var setting = {
    muted : true,                //视频静音,默认开启
	auto_change : false,         //自动切换课程,仅部分课程可用,可选(可能会有些问题,如果有问题请反馈一下,谢谢!)
    cycle : null,    		     //循环标记,禁止改动
    proxy : false,               //自动答题(即将上线,敬请期待)
    five_second : false,         //5秒真男人,默认关闭;如若开启把false改为true
    //仅当开启5秒模式生效
    alarm : true                 //若开启5秒真男人则会有提示,默认开启
};


$(document).ready(function(){
    if(new RegExp("study").test(location.href)) add_style();
});

//检查元素是否存在
function check()
{
    if(typeof(player) === 'undefined')
    {
        player = $("iframe").contents().find("iframe").contents().find('video#video_html5_api')[0];
        let tmp = $("h4.currents")[0];
        if(typeof(currents) === 'undefined') currents = document.getElementsByTagName("h4");
        for(let i = 0; i < currents.length; i++)
            if(tmp === currents[i])
            { cursor = i; break;}
        setTimeout(check, 500);
    }
    else
        start();
}

//开始自动播放
function start()
{
    if(typeof(player) === 'undefined') check();
    else
    {
        if(player.paused){player.play();}
        if(setting.muted && !player.muted){player.muted = true;}
        if((player.duration - player.currentTime) <= 2)
        {
            clearTimeout(setting.cycle);
            if(!setting.auto_change) { alert("答题了!"); return;}
			player.pause();
			if(setting.auto_change)
				change();
        }
        if(setting.five_second)
        {
            let time = player.currentTime + player.duration/8;
            if(time < (player.duration - 3))
                player.currentTime = time;
            else {player.currentTime = player.duration - 1.02;}
        }
        setting.cycle = setTimeout(start, 300);
    }
}

function stop()
{
	player.pause();
    clearTimeout(setting.cycle);
}

function re_check()
{
    player = undefined;
    check();
}

function add_style()
{
    let div_block, stop_btn, start_btn, tbl, check_box;
    div_block = document.createElement("div");
    start_btn = document.createElement("button");
    stop_btn = document.createElement("button");
	tbl = document.createElement("table");
	check_box = document.createElement("input");
    div_block.setAttribute("class", "div_block");
    div_block.setAttribute("style", "position:fixed;left:10%;top:10%");
	check_box.setAttribute("id", "ckb");
	check_box.setAttribute("type", "checkbox");
    start_btn.innerHTML = "开始";
    stop_btn.innerHTML = "暂停";
	tbl.innerHTML = "开启自动跳课";
	tbl.addEventListener('click', function(){ setting.auto_change = check_box.checked;});
    start_btn.addEventListener('click', re_check);
    stop_btn.addEventListener('click', stop);
	tbl.appendChild(check_box);
    div_block.appendChild(start_btn);
    div_block.appendChild(stop_btn);
	div_block.appendChild(tbl);
    $("body")[0].appendChild(div_block);
	if(setting.five_second && setting.alarm)
		alarm();
}

function alarm()
{
	let div, p, recycle;
    recycle = function(){ $("#alarm")[0].style.display = "";};
	div = document.createElement("div");
	p = document.createElement("p");
	p.innerHTML = "你是个好男人!";
    div.setAttribute("id", "alarm");
	div.setAttribute("style", "position:fixed;top:0%;left:25%;opacity:0.55");
	p.setAttribute("style", "font-size:600%;color:green;opacity:0.55;");
    div.addEventListener("click", function(){
        div.style.display = "none";
        setTimeout(recycle, 2000);
    });
	div.appendChild(p);
	$("#mainid")[0].after(div);
}

function change()
{
    if(currents[++cursor].parentElement.href != "javascript:void()")
        currents[cursor].click();
    else return;
    setTimeout(test_change, 1000);
}

function test_change()
{
    let blk = document.getElementById("dct1");
    if(blk.title != "视频")
    {
        document.getElementById("dct2").click();
     }
     setTimeout(re_check, 3000);
}

function Pause(mills)
{
    let start, end;
    start = new Date();
    start = start.valueOf();
    while(true)
    {
        end = new Date();
        if((end.valueOf() - start) > mills)
        {console.log("end"); break;}
    }
}