添加多账户功能 (#2102)

* 添加多账户功能

参考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>
This commit is contained in:
skyflag2022
2025-10-09 18:56:11 +08:00
committed by GitHub
parent afd01e8ac6
commit d61fc68cbe
4 changed files with 29 additions and 5 deletions

View File

@@ -6,3 +6,4 @@
此外脚本完整运行后会记录本次的时间,没有刷新时运行脚本会自动跳过。
账户名只允许使用数字中英文同时长度在20个字符以内。

View File

@@ -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();

View File

@@ -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"
]
}

View File

@@ -1,4 +1,10 @@
[
{
"name": "userName",
"type": "input-text",
"label": "账户名称\n用于多账户运行时区分不同账户",
"default": "默认账户"
},
{
"name": "select1",
"type": "checkbox",