优化学习阶段逻辑,增加文本课件检测和返回准备页面功能

This commit is contained in:
竟康 2026-06-03 15:03:35 +08:00
parent 3a570ed375
commit 4aed339bfc
1 changed files with 50 additions and 16 deletions

View File

@ -15,6 +15,8 @@
const url = window.location.href;
const MIN_STUDY_SECONDS = 5 * 60;
const COURSEWARE_DETECT_TIMEOUT_SECONDS = 60;
const TEXT_COURSEWARE_SELECTOR = "#easyXDM_default2872_provider";
console.log("插件加载完成,等待界面渲染");
const parseStudySeconds = (text) => {
@ -40,6 +42,17 @@
return studiedSeconds < MIN_STUDY_SECONDS;
};
const returnToStudyPage = () => {
const backLink = document.querySelector(".back-link");
if (backLink) {
backLink.click();
return;
}
history.back();
};
const onPageLoad = () => {
console.log("页面加载完成,开始执行脚本");
@ -80,12 +93,33 @@
} else if (url.includes("CourseShow")) {
console.log("进入学习阶段");
// 学习阶段
const showPageStartedAt = Date.now();
const videoInterval = setInterval(() => {
const video = document.querySelector("#vjs_video_3_html5_api");
if (!video) {
console.error("视频元素未找到,结束脚本");
clearInterval(videoInterval);
const textCourseware = document.querySelector(TEXT_COURSEWARE_SELECTOR);
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;
}
@ -98,7 +132,7 @@
if (video.currentTime >= video.duration - 1) {
console.log("视频播放结束,返回准备页面");
clearInterval(videoInterval);
document.querySelector(".back-link").click();
returnToStudyPage();
}
if (video.playbackRate === 1) {