更新脚本版本号,优化视频倍速设置逻辑,增加代码注释以提升可读性

This commit is contained in:
竟康 2026-06-05 14:11:44 +08:00
parent e73d0b4698
commit 47ebe38c30
1 changed files with 27 additions and 4 deletions

View File

@ -1,7 +1,7 @@
// ==UserScript== // ==UserScript==
// @name 平顶山学院(青书学堂)自动学习脚本 // @name 平顶山学院(青书学堂)自动学习脚本
// @namespace http://tampermonkey.net/ // @namespace http://tampermonkey.net/
// @version 2026-06-04.1 // @version 2026-06-05.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*
@ -15,16 +15,39 @@
(function () { (function () {
"use strict"; "use strict";
// 当前页面地址,用来判断是在课程列表页还是课件播放页。
const url = window.location.href; const url = window.location.href;
// 课件至少需要学习多少秒;默认 5 分钟。
const MIN_STUDY_SECONDS = 5 * 60; const MIN_STUDY_SECONDS = 5 * 60;
// 视频课件的 video 标签选择器;如果网站改版导致找不到视频,优先检查这里。
const VIDEO_SELECTOR = "#vjs_video_3_html5_api"; const VIDEO_SELECTOR = "#vjs_video_3_html5_api";
// 视频默认播放倍速;想改成 1.5 倍、3 倍就改这个值。
const VIDEO_PLAYBACK_RATE = 2;
// 文本课件容器选择器easyXDM 中间的数字会变,所以这里用开头和结尾匹配。
const TEXT_SELECTOR = "[id^='easyXDM_default'][id$='_provider']"; const TEXT_SELECTOR = "[id^='easyXDM_default'][id$='_provider']";
// toast 容器和样式标签的 id通常不用改除非和页面元素冲突。
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";
// toast 默认显示时长单位毫秒4000 表示 4 秒后自动隐藏。
const TOAST_DEFAULT_DURATION = 4000; const TOAST_DEFAULT_DURATION = 4000;
// 运行心跳提示间隔,单位秒;视频播放中、文本课件等待中都会按这个间隔提醒。
const HEARTBEAT_SECONDS = 10; const HEARTBEAT_SECONDS = 10;
// 课程列表最多等待多少秒;超过后认为可能请求失败,触发刷新。
const COURSE_LIST_WAIT_SECONDS = 60; const COURSE_LIST_WAIT_SECONDS = 60;
// 课程列表加载失败时最多自动刷新几次。
const MAX_COURSE_LIST_REFRESH_COUNT = 3; const MAX_COURSE_LIST_REFRESH_COUNT = 3;
// 记录课程列表自动刷新次数的 sessionStorage key。
// 带上 pathname/search避免不同课程页面之间互相影响。
const COURSE_LIST_REFRESH_KEY = const COURSE_LIST_REFRESH_KEY =
"qingshu_auto_course_list_refresh_count:" + "qingshu_auto_course_list_refresh_count:" +
location.pathname + location.pathname +
@ -380,9 +403,9 @@
returnToStudyPage(); returnToStudyPage();
} }
if (video.playbackRate === 1) { if (video.playbackRate !== VIDEO_PLAYBACK_RATE) {
notify("将视频倍速设置为2倍速", "success"); notify("将视频倍速设置为" + VIDEO_PLAYBACK_RATE + "倍速", "success");
video.playbackRate = 2; video.playbackRate = VIDEO_PLAYBACK_RATE;
} }
if (Date.now() - lastVideoHeartbeatAt >= HEARTBEAT_SECONDS * 1000) { if (Date.now() - lastVideoHeartbeatAt >= HEARTBEAT_SECONDS * 1000) {