From d61fc68cbe2f2eb2ecd33895b69212e951684c3c Mon Sep 17 00:00:00 2001 From: skyflag2022 <107539971+skyflag2022@users.noreply.github.com> Date: Thu, 9 Oct 2025 18:56:11 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=A4=9A=E8=B4=A6=E6=88=B7?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=20(#2102)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 添加多账户功能 参考autocode脚本 * Update manifest.json * Update manifest.json * Update manifest.json * Update repo/js/PurchaseArtifacts/main.js Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: 躁动的氨气 <131591012+zaodonganqi@users.noreply.github.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- repo/js/PurchaseArtifacts/README.md | 1 + repo/js/PurchaseArtifacts/main.js | 20 +++++++++++++++++--- repo/js/PurchaseArtifacts/manifest.json | 7 +++++-- repo/js/PurchaseArtifacts/settings.json | 6 ++++++ 4 files changed, 29 insertions(+), 5 deletions(-) diff --git a/repo/js/PurchaseArtifacts/README.md b/repo/js/PurchaseArtifacts/README.md index 111f768d0..712786641 100644 --- a/repo/js/PurchaseArtifacts/README.md +++ b/repo/js/PurchaseArtifacts/README.md @@ -6,3 +6,4 @@ 此外脚本完整运行后会记录本次的时间,没有刷新时运行脚本会自动跳过。 +账户名只允许使用数字,中英文,同时长度在20个字符以内。 \ No newline at end of file diff --git a/repo/js/PurchaseArtifacts/main.js b/repo/js/PurchaseArtifacts/main.js index abdc74f45..0d1b21f0d 100644 --- a/repo/js/PurchaseArtifacts/main.js +++ b/repo/js/PurchaseArtifacts/main.js @@ -1,3 +1,4 @@ +let userName = settings.userName || "默认账户"; (async function () { async function Purchase(locationName) { @@ -5,6 +6,17 @@ await pathingScript.runFile(filePath); } +//检验账户名 +function getUserName() { + userName = userName.trim(); +//数字,中英文,长度在20个字符以内 + if (!userName || !/^[\u4e00-\u9fa5A-Za-z0-9]{1,20}$/.test(userName)) { + log.error(`账户名${userName}违规,暂时使用默认账户名,请查看readme后修改`) + userName = "默认账户"; + } + return userName; +} + /** * 在指定区域内查找并点击指定文字 * @param {string} targetText - 要点击的目标文字 @@ -305,13 +317,15 @@ async function isTaskRefreshed(filePath, options = {}) { await Shopping(); } - await file.writeText("assets/weekly.txt", new Date().toISOString()); + await file.writeText(recordPath, new Date().toISOString()); } +userName = getUserName(); +const recordPath = `assets/${userName}.txt`; //每周四4点刷新 -if( await isTaskRefreshed("assets/weekly.txt", { +if( await isTaskRefreshed(recordPath, { refreshType: 'weekly', - weeklyDay: 4, // 周一 + weeklyDay: 4, // 周四 weeklyHour: 4 // 凌晨4点 })){ await main(); diff --git a/repo/js/PurchaseArtifacts/manifest.json b/repo/js/PurchaseArtifacts/manifest.json index 04740e0d2..f38199e6c 100644 --- a/repo/js/PurchaseArtifacts/manifest.json +++ b/repo/js/PurchaseArtifacts/manifest.json @@ -1,7 +1,7 @@ { "manifest_version": 1, "name": "自动购买狗粮(8点位)", - "version": "2.0", + "version": "2.1", "bgi_version": "0.50", "description": "自动购买狗粮", "authors": [ @@ -15,5 +15,8 @@ } ], "settings_ui": "settings.json", - "main": "main.js" + "main": "main.js", + "saved_files": [ + "assets/*.txt" + ] } diff --git a/repo/js/PurchaseArtifacts/settings.json b/repo/js/PurchaseArtifacts/settings.json index d614be8af..58e631b7c 100644 --- a/repo/js/PurchaseArtifacts/settings.json +++ b/repo/js/PurchaseArtifacts/settings.json @@ -1,4 +1,10 @@ [ + { + "name": "userName", + "type": "input-text", + "label": "账户名称\n用于多账户运行时区分不同账户", + "default": "默认账户" + }, { "name": "select1", "type": "checkbox",