更新脚本版本号,增加文本课件学习进度通知功能,优化视频播放状态心跳提示
This commit is contained in:
parent
5404d5fc7c
commit
4f0302bc07
|
|
@ -1,7 +1,7 @@
|
||||||
// ==UserScript==
|
// ==UserScript==
|
||||||
// @name 平顶山学院(青书学堂)自动学习脚本
|
// @name 平顶山学院(青书学堂)自动学习脚本
|
||||||
// @namespace http://tampermonkey.net/
|
// @namespace http://tampermonkey.net/
|
||||||
// @version 2026-06-03.1
|
// @version 2026-06-03.2
|
||||||
// @description try to take over the world!
|
// @description try to take over the world!
|
||||||
// @author You
|
// @author You
|
||||||
// @match https://degree.qingshuxuetang.com/pdsu/Student/Course/CourseStudy*
|
// @match https://degree.qingshuxuetang.com/pdsu/Student/Course/CourseStudy*
|
||||||
|
|
@ -22,6 +22,7 @@
|
||||||
const TOAST_CONTAINER_ID = "qingshu-auto-toast-container";
|
const TOAST_CONTAINER_ID = "qingshu-auto-toast-container";
|
||||||
const TOAST_STYLE_ID = "qingshu-auto-toast-style";
|
const TOAST_STYLE_ID = "qingshu-auto-toast-style";
|
||||||
const TOAST_DEFAULT_DURATION = 4000;
|
const TOAST_DEFAULT_DURATION = 4000;
|
||||||
|
const HEARTBEAT_SECONDS = 10;
|
||||||
|
|
||||||
// 创建右下角 toast 容器和样式。
|
// 创建右下角 toast 容器和样式。
|
||||||
// 每次通知都会创建一个新的 toast,所以多个通知会一起堆叠显示。
|
// 每次通知都会创建一个新的 toast,所以多个通知会一起堆叠显示。
|
||||||
|
|
@ -200,6 +201,18 @@
|
||||||
document.querySelector(TEXT_SELECTOR)
|
document.querySelector(TEXT_SELECTOR)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// 把秒数格式化成“x分x秒”,用于心跳提示。
|
||||||
|
const formatSeconds = (seconds) => {
|
||||||
|
if (!Number.isFinite(seconds) || seconds < 0) {
|
||||||
|
return "未知";
|
||||||
|
}
|
||||||
|
|
||||||
|
const minutes = Math.floor(seconds / 60);
|
||||||
|
const remainingSeconds = seconds % 60;
|
||||||
|
|
||||||
|
return minutes + "分" + remainingSeconds + "秒";
|
||||||
|
};
|
||||||
|
|
||||||
const onPageLoad = async () => {
|
const onPageLoad = async () => {
|
||||||
notify("页面加载完成,开始执行脚本", "info");
|
notify("页面加载完成,开始执行脚本", "info");
|
||||||
|
|
||||||
|
|
@ -244,15 +257,39 @@
|
||||||
// 文本课件没有 video 标签,不需要播放;停留 5 分钟后返回列表页。
|
// 文本课件没有 video 标签,不需要播放;停留 5 分钟后返回列表页。
|
||||||
if (coursewareElement.matches(TEXT_SELECTOR)) {
|
if (coursewareElement.matches(TEXT_SELECTOR)) {
|
||||||
notify("检测到文本课件,等待5分钟后返回准备页面", "warning", 6000);
|
notify("检测到文本课件,等待5分钟后返回准备页面", "warning", 6000);
|
||||||
setTimeout(() => {
|
const textStartedAt = Date.now();
|
||||||
notify("文本课件等待完成,返回准备页面", "success");
|
let textInterval;
|
||||||
returnToStudyPage();
|
|
||||||
}, MIN_STUDY_SECONDS * 1000);
|
const notifyTextProgress = () => {
|
||||||
|
const studiedSeconds = Math.floor((Date.now() - textStartedAt) / 1000);
|
||||||
|
|
||||||
|
if (studiedSeconds >= MIN_STUDY_SECONDS) {
|
||||||
|
clearInterval(textInterval);
|
||||||
|
notify("文本课件等待完成,返回准备页面", "success");
|
||||||
|
returnToStudyPage();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
notify(
|
||||||
|
"文本课件学习中,已等待:" +
|
||||||
|
formatSeconds(studiedSeconds) +
|
||||||
|
",剩余:" +
|
||||||
|
formatSeconds(MIN_STUDY_SECONDS - studiedSeconds),
|
||||||
|
"info"
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
textInterval = setInterval(
|
||||||
|
notifyTextProgress,
|
||||||
|
HEARTBEAT_SECONDS * 1000
|
||||||
|
);
|
||||||
|
notifyTextProgress();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 视频课件需要周期性检查播放状态:启动播放、设置倍速、播完返回。
|
// 视频课件需要周期性检查播放状态:启动播放、设置倍速、播完返回。
|
||||||
let videoMissingNotified = false;
|
let videoMissingNotified = false;
|
||||||
|
let lastVideoHeartbeatAt = 0;
|
||||||
const videoInterval = setInterval(() => {
|
const videoInterval = setInterval(() => {
|
||||||
const video = document.querySelector(VIDEO_SELECTOR);
|
const video = document.querySelector(VIDEO_SELECTOR);
|
||||||
|
|
||||||
|
|
@ -283,6 +320,17 @@
|
||||||
video.playbackRate = 2;
|
video.playbackRate = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (Date.now() - lastVideoHeartbeatAt >= HEARTBEAT_SECONDS * 1000) {
|
||||||
|
lastVideoHeartbeatAt = Date.now();
|
||||||
|
notify(
|
||||||
|
"视频正在播放,当前:" +
|
||||||
|
formatSeconds(Math.floor(video.currentTime)) +
|
||||||
|
" / 总时长:" +
|
||||||
|
formatSeconds(Math.floor(video.duration || 0)),
|
||||||
|
"info"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
console.log("视频正在播放,当前时间:" + video.currentTime);
|
console.log("视频正在播放,当前时间:" + video.currentTime);
|
||||||
}, 3000);
|
}, 3000);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue