From 1cb0aadcd47257481efbefb1569afaadf41f0a0c Mon Sep 17 00:00:00 2001 From: RiceXi <100351162+RiceXi@users.noreply.github.com> Date: Thu, 18 Jun 2026 21:35:48 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=BA=86=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E9=87=8D=E7=99=BB=E5=BD=95=E5=AE=9A=E6=97=B6=E5=99=A8=EF=BC=88?= =?UTF-8?q?Implement=20auto=20relogin=20feature=20with=20timer=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 添加了自动重登录定时器以防止因登陆过期失效而影响程序运行——无法正常提交选课申请(Added auto relogin functionality with a timer that triggers every 2 hours.) --- public/js/main.js | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/public/js/main.js b/public/js/main.js index 678ac91..b2e64b0 100644 --- a/public/js/main.js +++ b/public/js/main.js @@ -6,7 +6,8 @@ let checkIfFull = true let particlesLoaded = false let particlesPaused = false let studentId - +let autoReloginTimer = null +const AUTO_RELOGIN_INTERVAL = 7200000 // 2小时 = 7200000毫秒 // 导轨 !(function () { @@ -73,6 +74,8 @@ var targetList = JSON.parse(localStorage.getItem("DLSF_target")) || [] targetListRender() // 如果 cookie 失效,尝试使用用户名密码登录 if (!await checkCookie()) { buttonSaveUser() } + // 启动自动重新登录定时器 + startAutoRelogin() })() @@ -145,6 +148,37 @@ async function loginUser() { } } +// 启动自动重新登录定时器 +function startAutoRelogin() { + const username = localStorage.getItem("DLSF_username") + const password = localStorage.getItem("DLSF_password") + + // 只有当用户名和密码都存在时才启动定时器 + if (!username || !password) { + console.log("[自动重登录] 用户名或密码未设置,不启动自动重登录") + return + } + + // 避免重复创建定时器 + if (autoReloginTimer) { + clearInterval(autoReloginTimer) + console.log("[自动重登录] 清除旧的定时器") + } + + // 启动新的定时器 + autoReloginTimer = setInterval(async () => { + console.log("[自动重登录] 开始执行自动重新登录...") + const success = await loginUser() + if (success) { + console.log("[自动重登录] 重新登录成功") + } else { + console.log("[自动重登录] 重新登录失败") + } + }, AUTO_RELOGIN_INTERVAL) + + console.log(`[自动重登录] 定时器已启动,间隔 ${AUTO_RELOGIN_INTERVAL / 1000 / 60} 分钟`) +} + // 获取某门课的全部教学班信息 async function getAccData(courseCode, requestKey = "") { // 给并发请求加区分标识,避免不同 worker 互相取消请求