英华在线助手-自动静音连播-自动跳转到未完成视频-视频暂停超时播放提示音
Posted 明金同学
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了英华在线助手-自动静音连播-自动跳转到未完成视频-视频暂停超时播放提示音相关的知识,希望对你有一定的参考价值。
功能: 自动播放英华学堂的课。
1、自动静音连播
2、自动跳转到未完成视频
3、视频暂停超时播放提示音
注意: 请点击“学习记录”进入视频列表,再选择视频进行播放,否则脚本将不能正确运行。
放到控制台或者油猴脚本管理器:
class OcTip {
/**
* 类名: OcTip
* 说明: 提示框类. 可同时显示一些顺序排列的提示框.
* 初始化参数:
* parent: 父元素
**/
constructor(parent) {
this.parent = parent;
this.html = document.createElement("div");
this.queue = [];
this.mainTimer = 0;
this.paused = false;
this.mtID = null;
this.init();
}
init() {
this.HTML.className = 'oc-container';
this.parent.appendChild(this.HTML);
//绑定事件
this.HTML.onmouseover = () => {this.paused = true;};
this.HTML.onmouseleave = () => {this.paused = false;};
//添加公共样式
var elStyle = document.createElement("style");
elStyle.innerHTML = '.oc-container {z-index: 9999;position: relative;top: calc((100% - var(--height, 32px)) / 2);left: calc((100% - var(--width, 64px)) / 2);overflow: hidden;}.oc-tip {outline: 3px solid #ffff00;margin: 9px;border: 2px dashed #ffaa00;padding: 6px;background-color: #ffff00;overflow: hidden;transition: opacity 1s;}.oc-tip:hover {transition: opacity 0s;}.oc-tip .title,.oc-tip .content {margin: 0;vertical-align: middle;overflow: auto;}.oc-tip .title {overflow: hidden;text-overflow: ellipsis;white-space: nowrap;}';
this.HTML.appendChild(elStyle);
//设置主时钟
!this.mtID && (this.mtID = setInterval(() => {
this._handleQueue();
//刷新大小及位置
{
let maxWidth = parseInt(this.parent.offsetWidth * 0.8);
let maxHeight = parseInt(this.parent.offsetHeight * 0.8);
this.HTML.style.maxWidth = (maxWidth >= 64 ? maxWidth : 64) + 'px';
this.HTML.style.maxHeight = (maxHeight >= 64 ? maxHeight : 64) + 'px';
}
this.HTML.style.setProperty("--width", this.HTML.offsetWidth + "px");
this.HTML.style.setProperty("--height", this.HTML.offsetHeight + "px");
//刷新时钟
(!this.paused) && (this.mainTimer += 100);
}, 100));
}
append(text, title = null, delay = 1200) {
/**
* 成员函数名: append()
* 说明: 显示一个显示 3s 的提示性文本框, 可包含标题及文本.
* 参数:
* text: 显示文本
* title: 标题(默认不显示)
**/
var elTip = document.createElement('div');
var elContent = document.createElement("p");
elTip.className = "oc-tip";
elContent.className = 'content';
//设置标题
if (title) {
let elTitle = document.createElement("h3");
elTitle.className = 'title';
elTitle.innerHTML = title;
elTitle.title = title;
elTip.appendChild(elTitle);
}
//设置内容
elContent.innerHTML = text;
elContent.title = text;
elTip.appendChild(elContent);
//添加悬停事件
elTip.onmouseover = () => {elTip.style.opacity = 1;};
this._insertQueue(elTip, delay);
return true;
}
destroy() {
/**
* 成员函数名: destroy()
* 说明: 清除成员内容, 释放内存.
* 参数:
* parent: 父元素
* text: 显示文本
* title: 标题(默认不显示)
**/
this.HTML && this.parent.removeChild(this.HTML);
this.HTML = null;
this.queue = [];
this.mtID && clearInterval(this.mtID);
return true;
}
_insertQueue(elTip, duration) {
duration = parseInt(duration / 100) * 100;
this.queue.push({
inTime: this.mainTimer,
outTime: this.mainTimer + duration,
display: false,
elTip: elTip
});
}
_handleQueue() {
this.queue.forEach((obj, index, queue) => {
if(!obj.display && obj.inTime >= this.mainTimer) {
this.HTML.appendChild(obj.elTip);
obj.display = true;
}
else if(obj.display && this.mainTimer == obj.outTime) {
//淡出效果
obj.elTip.style.opacity = 0;
}
else if(obj.display && this.mainTimer >= obj.outTime + 1000) {
this.HTML.removeChild(obj.elTip);
obj.display = false;
obj.elTip = null;
queue.splice(index, 1);
}
});
}
}
class Course {
constructor(courseId) {
this.prefixURL1 = 'https://mooc.yinghuaonline.com';
this.prefixURL2 = 'https://mooc.yinghuaonline.com/user/study_record.json?courseId=';
this.index = -1; //本视频索引
this.nodeId = "";
this.chapterId = "";
this.courseId = courseId;
this.title = ""; //课程名
this.name = ""; //json 视频名
this.viewCount = 0; //json 观看次数
this.duration = 0; //json 视频播放时长
this.videoDuration = 0; //json 视频总时长
this.state = "";
this.finished = false; //是否完成播放
this.url = ""; //json 本页面地址
this.pageInfo = {
keyName: null,
page: -1,
pageCount: -1,
recordsCount: -1,
onlyCount: -1,
pageSize: -1
}
this.errCode = 0;
this.errMsg = "";
this._urls = []; //本次所有视频 HTML a 对象
this._json = null; //请求的课程 json
this._tID = Math.floor(Math.random() * (1622097000000 - 1622097888888)) + 1622097000000; //请求 json 所用 ID
this.init();
}
init() {
//单独获取标题
this.title = document.querySelector('#wrapper > div.curPlace > div.center > a:nth-child(3)').innerText;
this.parseIndex();
this.requireJson();
this._updateProperty();
}
parseIndex() { //分析当前视频索引
if(this.index != -1) return;
//解析本地 HTML 列表
var obj = document.querySelectorAll("div.nwrap > div > div.detmain-navs > div.detmain-navlist > div.group.two > div.list > div > a");
for(let [k, v] of obj.entries()) {
if(v.innerText == "章节测验") continue;
else {
v.href = `https://mooc.yinghuaonline.com/user/node?courseId=${this.courseId}&chapterId=${this.chapterId}&nodeId=${/nodeId=(\\d+)/.exec(v.href)[1]}`;
this._urls.push(v);
}
}
//获取视频索引
for(let i = 0; i < this._urls.length; i++) {
if(this._urls[i].className == "on") {
this.index = i;
return i;
}
}
this.index = -1;
return -1;
}
requireJson() { //请求视频列表
var xhttp = new XMLHttpRequest();
var page = 0;
page = parseInt((this.index + 20) / 20);
xhttp.onreadystatechange = () => {
if(xhttp.readyState == 4 && xhttp.status == 200) {
this._json = JSON.parse(xhttp.response);
}
else if(xhttp.readyState == 4 && xhttp.status == 0) {
this.errorCode = 404;
if(this._json.status && this._json.status == false) {
this.errorMsg = `Error: [${this.errorCode}] ${JSON.parse(xhttp.response).msg}`;
}
else {
this.errorMsg = `Error: [${this.errorCode}] 课程信息请求失败!}`;
}
}
};
xhttp.open("GET", this.prefixURL2 + this.courseId + "&page=" + page + "&_=" + this._tID++, false);
xhttp.send();
return this._json;
}
refresh() { //刷新当前课程信息
var json = null;
if(this.parseIndex() != -1 && this.requireJson()) {
this._updateProperty();
return true;
}
else {
return false;
}
}
_updateProperty() { //设置属性
this.id = this._json.list[this.index % 20].id;
this.chapterId = this._json.list[this.index % 20].chapterId;
this.courseId = this._json.list[this.index % 20].courseId;
this.name = this._json.list[this.index % 20].name;
this.viewCount = parseInt(this._json.list[this.index % 20].viewCount);
this.duration = parseInt(this._json.list[this.index % 20].duration);
this.videoDuration = parseSec(this._json.list[this.index % 20].videoDuration);
this.state = /(未学完|未学|已学)/.exec(this._json.list[this.index % 20].state)[0];
if(this.state == "已学") this.finished = true;
this.url = this.prefixURL1 + this._json.list[this.index % 20].url;
this.pageInfo = this._json.pageInfo;
// 保存 json 至本地(SKM_courseId_page_recordsCount_pageSize)
writeSessionStorage(`SKM_${this.courseId}_${this._json.pageInfo.page}_${this._json.pageInfo.recordsCount}_${this._json.pageInfo.pageSize}`, JSON.stringify(this._json), true);
}
}
class YHAssistant {
constructor() {
this.HTML = document.createElement("div");
this.baseInfo = null;
this.mainTimer = 0; //主时钟
this.currentDuration = -1; //观看时长
this.countdown = -1; //倒计时
this.course = null; //自定义课程对象
this.elTable = null; //HTML 表格对象
this.video = null; //HTML 视频对象
this.autoplay = true;
this.onduty = false; //是否值守
this.ocTip = null;
this._timer1 = 0; //值守计时器
this._timer2 = 0; //播放时长计时器(非Interval)
this._mtID = null; //主时钟 ID
this<以上是关于英华在线助手-自动静音连播-自动跳转到未完成视频-视频暂停超时播放提示音的主要内容,如果未能解决你的问题,请参考以下文章