From 4f0302bc07126c2b8fa8279bbb1745a090ec5b85 Mon Sep 17 00:00:00 2001 From: jinglekang Date: Wed, 3 Jun 2026 15:29:59 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E8=84=9A=E6=9C=AC=E7=89=88?= =?UTF-8?q?=E6=9C=AC=E5=8F=B7=EF=BC=8C=E5=A2=9E=E5=8A=A0=E6=96=87=E6=9C=AC?= =?UTF-8?q?=E8=AF=BE=E4=BB=B6=E5=AD=A6=E4=B9=A0=E8=BF=9B=E5=BA=A6=E9=80=9A?= =?UTF-8?q?=E7=9F=A5=E5=8A=9F=E8=83=BD=EF=BC=8C=E4=BC=98=E5=8C=96=E8=A7=86?= =?UTF-8?q?=E9=A2=91=E6=92=AD=E6=94=BE=E7=8A=B6=E6=80=81=E5=BF=83=E8=B7=B3?= =?UTF-8?q?=E6=8F=90=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- qingshuxuetang_auto_play.user.js | 58 +++++++++++++++++++++++++++++--- 1 file changed, 53 insertions(+), 5 deletions(-) diff --git a/qingshuxuetang_auto_play.user.js b/qingshuxuetang_auto_play.user.js index 1581922..78f2bdc 100644 --- a/qingshuxuetang_auto_play.user.js +++ b/qingshuxuetang_auto_play.user.js @@ -1,7 +1,7 @@ // ==UserScript== // @name 平顶山学院(青书学堂)自动学习脚本 // @namespace http://tampermonkey.net/ -// @version 2026-06-03.1 +// @version 2026-06-03.2 // @description try to take over the world! // @author You // @match https://degree.qingshuxuetang.com/pdsu/Student/Course/CourseStudy* @@ -22,6 +22,7 @@ const TOAST_CONTAINER_ID = "qingshu-auto-toast-container"; const TOAST_STYLE_ID = "qingshu-auto-toast-style"; const TOAST_DEFAULT_DURATION = 4000; + const HEARTBEAT_SECONDS = 10; // 创建右下角 toast 容器和样式。 // 每次通知都会创建一个新的 toast,所以多个通知会一起堆叠显示。 @@ -200,6 +201,18 @@ 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 () => { notify("页面加载完成,开始执行脚本", "info"); @@ -244,15 +257,39 @@ // 文本课件没有 video 标签,不需要播放;停留 5 分钟后返回列表页。 if (coursewareElement.matches(TEXT_SELECTOR)) { notify("检测到文本课件,等待5分钟后返回准备页面", "warning", 6000); - setTimeout(() => { - notify("文本课件等待完成,返回准备页面", "success"); - returnToStudyPage(); - }, MIN_STUDY_SECONDS * 1000); + const textStartedAt = Date.now(); + let textInterval; + + 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; } // 视频课件需要周期性检查播放状态:启动播放、设置倍速、播完返回。 let videoMissingNotified = false; + let lastVideoHeartbeatAt = 0; const videoInterval = setInterval(() => { const video = document.querySelector(VIDEO_SELECTOR); @@ -283,6 +320,17 @@ 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); }, 3000); }