超星尔雅网课视频辅助

本脚本用于超星学习通视频快速学习。

// ==UserScript==
// @name 超星尔雅网课视频辅助
// @namespace https://tampermonkey.net/
// @version 0.3
// @description 本脚本用于超星学习通视频快速学习。
// @author WildernessRanger
// @match https://mooc1.chaoxing.com/mycourse/studentstudy*
// @match https://mooc1-1.chaoxing.com/mycourse/studentstudy*
// @match https://mooc1-3.chaoxing.com/mycourse/studentstudy*
// @grant none
// ==/UserScript==
"use strict";

var currentElement, studySpeed;

function handleStudy() {
	if (!studySpeed)
		studySpeed = prompt("输入播放速度:", "2");
	if (studySpeed) {
		var doc = document.getElementById("iframe").contentDocument.getElementsByTagName("iframe")[0].contentDocument;
		var vid = doc.getElementsByTagName("video")[0];
		vid.playbackRate = studySpeed;
		vid.addEventListener("ended", function (e) { window.clearInterval(hndl); window.setTimeout(nextStudy, 1000); });
		doc.getElementsByClassName("vjs-big-play-button")[0].click();
		window.addEventListener("mouseout", function (e) { e.stopPropagation(); }, true);
		var hndl = window.setInterval(function () {
			var quiz = doc.getElementsByClassName("ans-videoquiz")[0];
			if (quiz) {
				var opts = quiz.getElementsByTagName("input");
				for (var i = 0; i < opts.length; i++) if (opts[i].value == "true")
						opts[i].click();
				quiz.getElementsByClassName("ans-videoquiz-submit")[0].click();
			}
		}, 1000);
	}
}
function nextStudy() {
	var nxt = currentElement.parentElement.nextElementSibling;
	if (nxt) {
		nxt.getElementsByTagName("a")[0].click();
		currentElement = nxt.children[0];
		window.setTimeout(handleStudy, 1000);
	} else {
		currentElement = null;
		alert("本章节已学习完成!");
	}
}

window.setTimeout(function () {
	var id = location.search.match(/(?<=(?:\?|&)(?:chapterId=))[^&]*(?=&|$)/)[0];
	currentElement = document.getElementById("cur" + id);
	var btn = document.createElement("button");
	btn.onclick = handleStudy;
	btn.textContent = "快速学习";
	document.getElementById("mainid").previousElementSibling.appendChild(btn);
	console.log("已加载超星尔雅网课视频辅助。");
}, 1000);