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