优化学习阶段逻辑,增加文本课件检测和返回准备页面功能
This commit is contained in:
parent
3a570ed375
commit
4aed339bfc
|
|
@ -15,6 +15,8 @@
|
||||||
|
|
||||||
const url = window.location.href;
|
const url = window.location.href;
|
||||||
const MIN_STUDY_SECONDS = 5 * 60;
|
const MIN_STUDY_SECONDS = 5 * 60;
|
||||||
|
const COURSEWARE_DETECT_TIMEOUT_SECONDS = 60;
|
||||||
|
const TEXT_COURSEWARE_SELECTOR = "#easyXDM_default2872_provider";
|
||||||
console.log("插件加载完成,等待界面渲染");
|
console.log("插件加载完成,等待界面渲染");
|
||||||
|
|
||||||
const parseStudySeconds = (text) => {
|
const parseStudySeconds = (text) => {
|
||||||
|
|
@ -39,6 +41,17 @@
|
||||||
const studiedSeconds = parseStudySeconds(mark.innerText);
|
const studiedSeconds = parseStudySeconds(mark.innerText);
|
||||||
return studiedSeconds < MIN_STUDY_SECONDS;
|
return studiedSeconds < MIN_STUDY_SECONDS;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const returnToStudyPage = () => {
|
||||||
|
const backLink = document.querySelector(".back-link");
|
||||||
|
|
||||||
|
if (backLink) {
|
||||||
|
backLink.click();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
history.back();
|
||||||
|
};
|
||||||
|
|
||||||
const onPageLoad = () => {
|
const onPageLoad = () => {
|
||||||
console.log("页面加载完成,开始执行脚本");
|
console.log("页面加载完成,开始执行脚本");
|
||||||
|
|
@ -77,17 +90,38 @@
|
||||||
}
|
}
|
||||||
console.log("所有视频均已播放完毕,结束脚本");
|
console.log("所有视频均已播放完毕,结束脚本");
|
||||||
}, 3000);
|
}, 3000);
|
||||||
} else if (url.includes("CourseShow")) {
|
} else if (url.includes("CourseShow")) {
|
||||||
console.log("进入学习阶段");
|
console.log("进入学习阶段");
|
||||||
// 学习阶段
|
// 学习阶段
|
||||||
const videoInterval = setInterval(() => {
|
const showPageStartedAt = Date.now();
|
||||||
const video = document.querySelector("#vjs_video_3_html5_api");
|
const videoInterval = setInterval(() => {
|
||||||
|
const video = document.querySelector("#vjs_video_3_html5_api");
|
||||||
if (!video) {
|
|
||||||
console.error("视频元素未找到,结束脚本");
|
if (!video) {
|
||||||
clearInterval(videoInterval);
|
const textCourseware = document.querySelector(TEXT_COURSEWARE_SELECTOR);
|
||||||
return;
|
|
||||||
}
|
if (textCourseware) {
|
||||||
|
console.log("检测到文本课件,等待5分钟后返回准备页面");
|
||||||
|
clearInterval(videoInterval);
|
||||||
|
setTimeout(() => {
|
||||||
|
console.log("文本课件等待完成,返回准备页面");
|
||||||
|
returnToStudyPage();
|
||||||
|
}, MIN_STUDY_SECONDS * 1000);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
Date.now() - showPageStartedAt >
|
||||||
|
COURSEWARE_DETECT_TIMEOUT_SECONDS * 1000
|
||||||
|
) {
|
||||||
|
console.error("视频和文本课件元素均未找到,结束脚本");
|
||||||
|
clearInterval(videoInterval);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log("课件元素尚未渲染完成,继续等待");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (video.paused && video.currentTime === 0) {
|
if (video.paused && video.currentTime === 0) {
|
||||||
video.play();
|
video.play();
|
||||||
|
|
@ -95,11 +129,11 @@
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (video.currentTime >= video.duration - 1) {
|
if (video.currentTime >= video.duration - 1) {
|
||||||
console.log("视频播放结束,返回准备页面");
|
console.log("视频播放结束,返回准备页面");
|
||||||
clearInterval(videoInterval);
|
clearInterval(videoInterval);
|
||||||
document.querySelector(".back-link").click();
|
returnToStudyPage();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (video.playbackRate === 1) {
|
if (video.playbackRate === 1) {
|
||||||
console.log("将视频倍速设置为2倍速");
|
console.log("将视频倍速设置为2倍速");
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue