更新脚本版本号至2026-06-10.1,优化配置菜单的显示逻辑,简化代码结构

This commit is contained in:
竟康 2026-06-10 13:12:41 +08:00
parent 26d41ae4d8
commit 8c48de9be0
1 changed files with 79 additions and 51 deletions

View File

@ -1,7 +1,7 @@
// ==UserScript== // ==UserScript==
// @name 平顶山学院(青书学堂)自动学习脚本 // @name 平顶山学院(青书学堂)自动学习脚本
// @namespace http://tampermonkey.net/ // @namespace http://tampermonkey.net/
// @version 2026-06-05.8 // @version 2026-06-10.1
// @description 自动进入青书学堂未完成课件,支持视频播放、文本课件停留和运行状态提示 // @description 自动进入青书学堂未完成课件,支持视频播放、文本课件停留和运行状态提示
// @author JK // @author JK
// @license MIT // @license MIT
@ -179,7 +179,10 @@
}; };
const promptNumberConfig = (label, key, unit, currentValue, toStoredValue) => { const promptNumberConfig = (label, key, unit, currentValue, toStoredValue) => {
const input = prompt(label + "(当前:" + currentValue + unit + "", currentValue); const input = prompt(
label + "(当前:" + currentValue + unit + "",
currentValue
);
if (input === null) { if (input === null) {
return; return;
@ -200,16 +203,24 @@
// 在 Tampermonkey 菜单里提供配置入口。 // 在 Tampermonkey 菜单里提供配置入口。
// 这些值保存在脚本存储区,脚本更新不会覆盖它们。 // 这些值保存在脚本存储区,脚本更新不会覆盖它们。
const registerConfigMenus = () => { const registerConfigMenus = () => {
GM_registerMenuCommand("设置视频倍速", () => { const menuTitle = (label, value, unit) =>
label + "(当前:" + value + unit + "";
GM_registerMenuCommand(
menuTitle("设置视频倍速", CONFIG.videoPlaybackRate, "倍"),
() => {
promptNumberConfig( promptNumberConfig(
"设置视频倍速", "设置视频倍速",
"videoPlaybackRate", "videoPlaybackRate",
"倍", "倍",
CONFIG.videoPlaybackRate CONFIG.videoPlaybackRate
); );
}); }
);
GM_registerMenuCommand("设置课件最小学习时间", () => { GM_registerMenuCommand(
menuTitle("设置课件最小学习时间", CONFIG.minStudySeconds / 60, "分钟"),
() => {
promptNumberConfig( promptNumberConfig(
"设置课件最小学习时间", "设置课件最小学习时间",
"minStudySeconds", "minStudySeconds",
@ -217,27 +228,40 @@
CONFIG.minStudySeconds / 60, CONFIG.minStudySeconds / 60,
(value) => value * 60 (value) => value * 60
); );
}); }
);
GM_registerMenuCommand("设置运行提醒间隔", () => { GM_registerMenuCommand(
menuTitle("设置运行提醒间隔", CONFIG.heartbeatSeconds, "秒"),
() => {
promptNumberConfig( promptNumberConfig(
"设置运行提醒间隔", "设置运行提醒间隔",
"heartbeatSeconds", "heartbeatSeconds",
"秒", "秒",
CONFIG.heartbeatSeconds CONFIG.heartbeatSeconds
); );
}); }
);
GM_registerMenuCommand("设置课程列表等待时间", () => { GM_registerMenuCommand(
menuTitle("设置课程列表等待时间", CONFIG.courseListWaitSeconds, "秒"),
() => {
promptNumberConfig( promptNumberConfig(
"设置课程列表等待时间", "设置课程列表等待时间",
"courseListWaitSeconds", "courseListWaitSeconds",
"秒", "秒",
CONFIG.courseListWaitSeconds CONFIG.courseListWaitSeconds
); );
}); }
);
GM_registerMenuCommand("设置课程列表自动刷新次数", () => { GM_registerMenuCommand(
menuTitle(
"设置课程列表自动刷新次数",
CONFIG.maxCourseListRefreshCount,
"次"
),
() => {
promptNumberConfig( promptNumberConfig(
"设置课程列表自动刷新次数", "设置课程列表自动刷新次数",
"maxCourseListRefreshCount", "maxCourseListRefreshCount",
@ -245,9 +269,12 @@
CONFIG.maxCourseListRefreshCount, CONFIG.maxCourseListRefreshCount,
Math.floor Math.floor
); );
}); }
);
GM_registerMenuCommand("设置提示消息显示时间", () => { GM_registerMenuCommand(
menuTitle("设置提示消息显示时间", CONFIG.toastDefaultDuration / 1000, "秒"),
() => {
promptNumberConfig( promptNumberConfig(
"设置提示消息显示时间", "设置提示消息显示时间",
"toastDefaultDuration", "toastDefaultDuration",
@ -255,7 +282,8 @@
CONFIG.toastDefaultDuration / 1000, CONFIG.toastDefaultDuration / 1000,
(value) => value * 1000 (value) => value * 1000
); );
}); }
);
GM_registerMenuCommand("恢复默认设置", () => { GM_registerMenuCommand("恢复默认设置", () => {
GM_deleteValue(CONFIG_STORAGE_KEY); GM_deleteValue(CONFIG_STORAGE_KEY);