一些js更新 (#890)

* 一些js更新

* Update repo/js/自动小怪锄地规划/main.js

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Update repo/js/自动精英锄地规划/main.js

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
mno
2025-05-20 23:43:14 +08:00
committed by GitHub
parent 6a5f7b2587
commit 64610ae0eb
11 changed files with 588 additions and 141 deletions

View File

@@ -1,3 +1,89 @@
// fakeLog 函数,使用方法:将本函数放在主函数前,调用时请务必使用await否则可能出现v8白框报错
//在js开头处伪造该js结束运行的日志信息如 await fakeLog("js脚本", true, true, 0);
//在js结尾处伪造该js开始运行的日志信息如 await fakeLog("js脚本", true, false, 2333);(可以不加)
//duration项目仅在伪造结束信息时有效且无实际作用可以任意填写当你需要在日志中输出特定值时才需要单位为毫秒
//在调用地图追踪前伪造该地图追踪开始运行的日志信息,如 await fakeLog(`地图追踪.json`, false, true, 0);
//在调用地图追踪后伪造该地图追踪结束运行的日志信息,如 await fakeLog(`地图追踪.json`, false, false, 0);
//如此便可以在js运行过程中伪造地图追踪的日志信息可以在日志分析等中查看
async function fakeLog(name, isJs, isStart, duration) {
await sleep(10);
const currentTime = Date.now();
// 参数检查
if (typeof name !== 'string') {
log.error("参数 'name' 必须是字符串类型!");
return;
}
if (typeof isJs !== 'boolean') {
log.error("参数 'isJs' 必须是布尔型!");
return;
}
if (typeof isStart !== 'boolean') {
log.error("参数 'isStart' 必须是布尔型!");
return;
}
if (typeof currentTime !== 'number' || !Number.isInteger(currentTime)) {
log.error("参数 'currentTime' 必须是整数!");
return;
}
if (typeof duration !== 'number' || !Number.isInteger(duration)) {
log.error("参数 'duration' 必须是整数!");
return;
}
// 将 currentTime 转换为 Date 对象并格式化为 HH:mm:ss.sss
const date = new Date(currentTime);
const hours = String(date.getHours()).padStart(2, '0');
const minutes = String(date.getMinutes()).padStart(2, '0');
const seconds = String(date.getSeconds()).padStart(2, '0');
const milliseconds = String(date.getMilliseconds()).padStart(3, '0');
const formattedTime = `${hours}:${minutes}:${seconds}.${milliseconds}`;
// 将 duration 转换为分钟和秒,并保留三位小数
const durationInSeconds = duration / 1000; // 转换为秒
const durationMinutes = Math.floor(durationInSeconds / 60);
const durationSeconds = (durationInSeconds % 60).toFixed(3); // 保留三位小数
// 使用四个独立的 if 语句处理四种情况
if (isJs && isStart) {
// 处理 isJs = true 且 isStart = true 的情况
const logMessage = `正在伪造js开始的日志记录\n\n` +
`[${formattedTime}] [INF] BetterGenshinImpact.Service.ScriptService\n` +
`------------------------------\n\n` +
`[${formattedTime}] [INF] BetterGenshinImpact.Service.ScriptService\n` +
`→ 开始执行JS脚本: "${name}"`;
log.info(logMessage);
}
if (isJs && !isStart) {
// 处理 isJs = true 且 isStart = false 的情况
const logMessage = `正在伪造js结束的日志记录\n\n` +
`[${formattedTime}] [INF] BetterGenshinImpact.Service.ScriptService\n` +
`→ 脚本执行结束: "${name}", 耗时: ${durationMinutes}${durationSeconds}\n\n` +
`[${formattedTime}] [INF] BetterGenshinImpact.Service.ScriptService\n` +
`------------------------------`;
log.info(logMessage);
}
if (!isJs && isStart) {
// 处理 isJs = false 且 isStart = true 的情况
const logMessage = `正在伪造地图追踪开始的日志记录\n\n` +
`[${formattedTime}] [INF] BetterGenshinImpact.Service.ScriptService\n` +
`------------------------------\n\n` +
`[${formattedTime}] [INF] BetterGenshinImpact.Service.ScriptService\n` +
`→ 开始执行地图追踪任务: "${name}"`;
log.info(logMessage);
}
if (!isJs && !isStart) {
// 处理 isJs = false 且 isStart = false 的情况
const logMessage = `正在伪造地图追踪结束的日志记录\n\n` +
`[${formattedTime}] [INF] BetterGenshinImpact.Service.ScriptService\n` +
`→ 脚本执行结束: "${name}", 耗时: ${durationMinutes}${durationSeconds}\n\n` +
`[${formattedTime}] [INF] BetterGenshinImpact.Service.ScriptService\n` +
`------------------------------`;
log.info(logMessage);
}
}
(async function () {
// 初始化所有用到的参数
const operationMode = settings.operationMode || "生成路径文件"; // 默认值为“生成路径文件”
@@ -11,6 +97,11 @@
const pathingDir = 'pathing/'; // 初始化pathingDir参数
const enableCooldownCheck = !disableCooldownCheck; // 如果 disableCooldownCheck 未设置或为 false则 enableCooldownCheck 为 true
// 初始化全局排除关键词配置
let globalExclusionKeywords = settings.globalExclusionKeywords || "不跑"; // 默认为不跑
const exclusionKeywordsArray = globalExclusionKeywords.split("").map(keyword => keyword.trim()).filter(Boolean); // 使用中文分号分隔,并去除空格和空字符串
// 初始化用于计数的变量
let outputFolderName = accountName; // 初始化为空
let totalMonsterCount = 0; // 筛选出的怪物总数
@@ -19,15 +110,6 @@
let failCount = 0; // 失败复制的文件数量
let routeIndex = 0; // 当前筛选的路线序号
// 定义六个运行时变量,初始值分别为 2000、1000、0、0、0、0
let runtime1 = 2000;
let runtime2 = 1000;
let runtime3 = 0;
let runtime4 = 0;
let runtime5 = 0;
let runtime6 = 0;
// 日志输出配置参数
log.info(
`自动小怪锄地规划 - 配置信息:` +
@@ -41,6 +123,9 @@
`账户名=${accountName}`
);
// 在日志中输出全局排除关键词配置信息
log.info(`全局排除关键词=${globalExclusionKeywords ? exclusionKeywordsArray.join("") : "无"}`);
// 检查是否所有配置都是默认状态
const isDefaultConfig = (
operationMode === "生成路径文件" &&
@@ -82,6 +167,8 @@
// 判断操作模式是否为“执行路径文件”,若是则执行路径文件
if (operationMode === "执行路径文件") {
try {
//伪造js已经结束的记录
await fakeLog("自动小怪锄地规划", true, false, 1);
// 定义路径组文件的路径,使用 outputFolderName
const pathGroupFilePath = `route/${outputFolderName}.txt`;
@@ -90,45 +177,43 @@
for (let i = 0; i < savedRoutes.length; i++) {
const routeWithTimestamp = savedRoutes[i].trim();
const [routeName, routeTimestamp] = routeWithTimestamp.split('::');
log.info(`当前任务为第 ${i + 1}/${savedRoutes.length}`);
log.info(`当前进度:${routeName}为第 ${i + 1}/${savedRoutes.length}`);
const now = new Date(); // 获取开始时间
const startTime = now.toISOString();
// 更新 runtime 变量
runtime6 = runtime5;
runtime5 = runtime4;
runtime4 = runtime3;
runtime3 = runtime2;
runtime2 = runtime1;
runtime1 = now.getTime();
// 检查时间差条件
if ((runtime1 - runtime2) < 500 &&
(runtime2 - runtime3) < 500 &&
(runtime3 - runtime4) < 500 &&
(runtime4 - runtime5) < 500 &&
(runtime5 - runtime6) < 500) {
log.info(`连续五次时间差小于 500 毫秒,循环终止。`);
break; // 如果连续五次时间差小于 500 毫秒,退出循环
}
if (enableCooldownCheck && startTime < routeTimestamp) {
log.info(`当前路线 ${routeName} 未刷新,跳过任务`);
await sleep(500);
await sleep(10);
continue; // 跳过当前循环
}
log.info(`当前路线 ${routeName} 已刷新或未启用CD检测执行任务`);
// 拼接路径文件的完整路径
const pathingFilePath = `pathing/${routeName}.json`;
//伪造地图追踪开始的日志记录
await fakeLog(routeName + ".json", false, true, 0); // 开始时 duration 通常为 0
// 执行路径文件
await pathingScript.runFile(pathingFilePath);
// 如果启用了CD检测获取结束时间并判断时间差
const endTime = new Date(); // 获取结束时间
const timeDiff = endTime - now; // 计算时间差(单位:毫秒)
//伪造地图追踪结束的日志记录
await fakeLog(routeName + ".json", false, false, timeDiff);
//尝试捕获任务取消的错误,捕获后终止循环
try {
await sleep(10);
} catch (error) {
log.error(`发生错误: ${error}`);
return; // 终止循环
}
// 如果启用了CD检测
if (enableCooldownCheck) {
const endTime = new Date(); // 获取结束时间
const timeDiff = endTime - now; // 计算时间差(单位:毫秒)
if (timeDiff > 10000) { // 如果时间差大于10秒10000毫秒
if (timeDiff > 3000) { // 如果时间差大于3秒3000毫秒
// 计算新的时间戳增加12小时
const newTimestamp = new Date(startTime).getTime() + 12 * 60 * 60 * 1000;
const formattedNewTimestamp = new Date(newTimestamp).toISOString();
@@ -148,6 +233,10 @@
} catch (error) {
log.error(`读取或写入路径组文件时出错: ${error}`);
}
//伪造一个js开始的记录实际上没必要
//await fakeLog("自动精英锄地规划", true, true, 0);
return;
}
// 筛选、排序并选取路线
@@ -173,13 +262,14 @@
for (const route of sortedPathingFiles) {
routeIndex++; // 每次循环时递增
const meetsKeywordCondition = exclusionKeywordsArray.every(keyword => !route.name.toLowerCase().includes(keyword));
const meetsWaterFreeCondition = !excludeWaterFree || !route.isWaterFree;
const meetsHighRiskCondition = !excludeHighRisk || !route.isHighRisk;
// 修改后的日志输出,增加当前路线的序号
//log.debug(`筛选路线 ${routeIndex}${route.name}):水免条件 ${meetsWaterFreeCondition},高危条件 ${meetsHighRiskCondition}`);
log.debug(`筛选路线 ${routeIndex}${route.name}):关键词条件 ${meetsKeywordCondition},水免条件 ${meetsWaterFreeCondition},高危条件 ${meetsHighRiskCondition}`);
if (meetsWaterFreeCondition && meetsHighRiskCondition) {
if (meetsKeywordCondition && meetsWaterFreeCondition && meetsHighRiskCondition) {
totalMonsterCount += route.monsterCount;
route.selected = 1;
selectedRoutes.push(route.name);
@@ -187,6 +277,7 @@
}
}
if (totalMonsterCount < requiredMonsterCount) {
log.warn(`数量不足,最多可以包含 ${totalMonsterCount} 只怪物,不满足所需的 ${requiredMonsterCount} 只怪物`);
}