大连理工大学视频倍速+自动切换脚本
// ==UserScript==
// @name 大连理工大学视频倍速+自动切换脚本
// @run-at document-start
// @version 0.3
// @description 大连理工大学视频倍速+自动切换脚本
// @author cangxun
// @match https://learn.open.com.cn/StudentCenter/CourseWare/ShowResource*
// @icon https://www.google.com/s2/favicons?domain=open.com.cn
// @grant unsafeWindow
// ==/UserScript==
'use strict';
(function () {
var rate = 16; //倍速调节,最多16
var autoNext = true; //是否自动下一个 true为自动,false为不自动
//可能会出现不自动下一个,重播的情况,需要退出账号后重新登录。请确保网络质量!!
//----------------------以下为逻辑代码-----------------------------------
let hookSetInterval = unsafeWindow.setInterval;
unsafeWindow.setInterval = function (a, b) {
return hookSetInterval(a, b / rate);
}
function addCookie(objName, objValue, objHours) {
var str = objName + "=" + escape(objValue);
if (objHours > 0) {
var date = new Date();
var ms = objHours * 3600 * 1000;
date.setTime(date.getTime() + ms);
str += "; expires=" + date.toGMTString();
}
document.cookie = str;
}
unsafeWindow.onload = function () {
//去除暂停广告
addCookie("qrcode_show_s", 0, 0);
let iframe = unsafeWindow.document.getElementById('ifr');
let iframeUrl = iframe.src;
iframe.onload = function () {
let videoObj;
let videoLoad = unsafeWindow.setInterval(function () {
videoObj = iframe.contentWindow.document.querySelector('video');
if (videoObj) {
videoObj.volume = 0;
videoObj.onloadedmetadata = function () {
videoObj.playbackRate = rate;
videoObj.volume = 0;
console.log("资源加载完成,开始播放!");
videoObj.play();
unsafeWindow.clearInterval(videoLoad);
videoObj.addEventListener('pause', () => {
if (videoObj.ended) {
if (autoNext) {
document.getElementsByClassName('icon-open-next')[0].click();
console.log("自动播放下一个!");
} else {
console.log("当前视频已完成学习!");
}
} else if (videoObj.paused) {
videoObj.play();
console.log('暂停后继续播放!');
}
});
};
videoObj.load();
}
}, 3000 * rate);
}
iframe.src = iframeUrl;
}
})();