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",