From b28d415a51747594ac1eeda1d62a1169d3b46132 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=BA=81=E5=8A=A8=E7=9A=84=E6=B0=A8=E6=B0=94?= <131591012+zaodonganqi@users.noreply.github.com> Date: Mon, 22 Dec 2025 21:03:34 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8D=83=E6=98=9F=E6=B7=BB=E5=8A=A0=E5=91=A8?= =?UTF-8?q?=E5=88=A4=E6=96=AD=20(#2547)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- repo/js/WeeklyThousandStarRealm/README.md | 2 +- repo/js/WeeklyThousandStarRealm/main.js | 57 ++++++++++++++++--- repo/js/WeeklyThousandStarRealm/manifest.json | 2 +- 3 files changed, 50 insertions(+), 11 deletions(-) diff --git a/repo/js/WeeklyThousandStarRealm/README.md b/repo/js/WeeklyThousandStarRealm/README.md index 54f5276a5..12219c7f4 100644 --- a/repo/js/WeeklyThousandStarRealm/README.md +++ b/repo/js/WeeklyThousandStarRealm/README.md @@ -8,7 +8,7 @@ ## ❗ 使用前重要说明(免责声明) -本脚本依赖“**删除奇域地图存档**”来实现重复获取成就经验。 +本脚本依赖“**删除第一个奇域地图存档**”来实现重复获取成就经验。 这意味着: diff --git a/repo/js/WeeklyThousandStarRealm/main.js b/repo/js/WeeklyThousandStarRealm/main.js index d3883a628..08f46c2b4 100644 --- a/repo/js/WeeklyThousandStarRealm/main.js +++ b/repo/js/WeeklyThousandStarRealm/main.js @@ -34,35 +34,74 @@ function saveWeekData(data) { file.writeTextSync(storePath, JSON.stringify(data)); } +// 判断两个时间是否属于同一周 +function isSameWeek(t1, t2) { + const getMonday = (time) => { + const d = new Date(time); + const day = d.getDay(); // 0=周日 + const diff = day === 0 ? -6 : 1 - day; + d.setDate(d.getDate() + diff); + d.setHours(0, 0, 0, 0); + return d.getTime(); + }; + + return getMonday(t1) === getMonday(t2); +} + // 初始化或更新 weekTotal function initWeekTotal() { const stored = loadWeekData(); const calculated = Math.ceil(weekMaxExp / singleExp); + const now = Date.now(); - // 首次 OR 配置变化 → 重写 + // 无存档 -> 初始化 + if (!stored) { + const data = { + weekMaxExp, + singleExp, + weekTotal: calculated, + lastRunTime: now + }; + saveWeekData(data); + return calculated; + } + + // 跨周 -> 重置次数 + if (!isSameWeek(stored.lastRunTime, now)) { + stored.weekTotal = calculated; + stored.lastRunTime = now; + saveWeekData(stored); + log.info("检测到跨周,已重置每周次数"); + return calculated; + } + + // 配置变化 -> 重算 if ( - !stored || stored.weekMaxExp !== weekMaxExp || stored.singleExp !== singleExp ) { - const newData = { - weekMaxExp, - singleExp, - weekTotal: calculated - }; - saveWeekData(newData); + stored.weekMaxExp = weekMaxExp; + stored.singleExp = singleExp; + stored.weekTotal = calculated; + stored.lastRunTime = now; + saveWeekData(stored); return calculated; } + // 正常情况,仅更新时间 + stored.lastRunTime = now; + saveWeekData(stored); + return stored.weekTotal; } -// 刷完一次 → 计数 -1 +// 刷完一次 -> 计数 -1 function decreaseWeekTotal() { const stored = loadWeekData(); if (!stored) return; stored.weekTotal = Math.max(stored.weekTotal - 1, 0); + stored.lastRunTime = Date.now(); saveWeekData(stored); weekTotal = stored.weekTotal; } diff --git a/repo/js/WeeklyThousandStarRealm/manifest.json b/repo/js/WeeklyThousandStarRealm/manifest.json index a6ddc4e85..88c10e495 100644 --- a/repo/js/WeeklyThousandStarRealm/manifest.json +++ b/repo/js/WeeklyThousandStarRealm/manifest.json @@ -1,7 +1,7 @@ { "manifest_version": 1, "name": "千星奇域每周成就经验刷取", - "version": "2.2", + "version": "2.3", "bgi_version": "0.54.0", "description": "可用于利用成就高经验值刷取经验,默认配置每周刷满需要24分钟", "authors": [