lint js code (#2295)

This commit is contained in:
Jamis
2025-11-02 17:05:40 +08:00
committed by GitHub
parent 49bfd959fd
commit 44794d2e6f

View File

@@ -1,7 +1,7 @@
function forge_pathing_start_log(name) {
const t = new Date();
const timestamp = t.toTimeString().slice(0, 8) + "." + String(t.getMilliseconds()).padStart(3, "0");
var c = "Forging start log\n\n";
let c = "Forging start log\n\n";
c += `[${timestamp}] [INF] BetterGenshinImpact.Service.ScriptService\n------------------------------\n\n`;
c += `[${timestamp}] [INF] BetterGenshinImpact.Service.ScriptService\n→ 开始执行地图追踪任务: "${name}"`;
log.debug(c);
@@ -12,14 +12,14 @@ function forge_pathing_end_log(name, elapsed_time) {
const elapsed_sec = (elapsed_time / 1000 % 60).toFixed(3);
const t = new Date();
const timestamp = t.toTimeString().slice(0, 8) + "." + String(t.getMilliseconds()).padStart(3, "0");
var c = "Forging end log\n\n";
let c = "Forging end log\n\n";
c += `[${timestamp}] [INF] BetterGenshinImpact.Service.ScriptService\n→ 脚本执行结束: "${name}", 耗时: ${elapsed_min}${elapsed_sec}\n\n`;
c += `[${timestamp}] [INF] BetterGenshinImpact.Service.ScriptService\n------------------------------`;
log.debug(c);
}
function get_exclude_tags() {
var tags = [];
let tags = [];
if (settings.fight_option === "全跳过") {
tags.push("fight");
} else if (settings.fight_option === "只跳过与精英怪战斗的路线") {
@@ -77,7 +77,7 @@ function get_profile_name() {
const filename_to_path_map = {};
function load_filename_to_path_map() {
var all_paths = [];
let all_paths = [];
const read_dir = (path) => {
for (const i of file.readPathSync(path)) {
if (file.isFolder(i)) {
@@ -94,11 +94,11 @@ function load_filename_to_path_map() {
}
}
var persistent_data = {};
let persistent_data = {};
const in_memory_skip_tasks = new Set();
function load_persistent_data() {
var file_content = "";
let file_content = "";
try {
file_content = file.readTextSync("local/persistent_data.json");
} catch (error) {}
@@ -111,11 +111,11 @@ const disabled_paths = new Set();
function load_disabled_paths() {
for (const path of ["assets/disabled_paths.conf", "local/disabled_paths.txt"]) {
var file_content = "";
let file_content = "";
try {
file_content = file.readTextSync(path);
} catch (error) {}
for (var l of file_content.split("\n")) {
for (let l of file_content.split("\n")) {
l = l.trim();
if (l.length === 0) {
continue;
@@ -128,7 +128,7 @@ function load_disabled_paths() {
}
}
var statistics = {};
let statistics = {};
function load_statistics_data() {
statistics = JSON.parse(file.readTextSync("assets/statistics.json")).data;
@@ -158,7 +158,7 @@ function get_task_last_run_time(task_name) {
function is_ore_respawned(t) {
t /= 1000;
var t0 = Math.floor(t / 86400) * 86400 + 57600;
let t0 = Math.floor(t / 86400) * 86400 + 57600;
if (t0 > t) {
t0 -= 86400;
}
@@ -175,7 +175,7 @@ function get_some_tasks(hints) {
log.debug("Schedule with target runnning seconds {a}", hints.target_running_seconds);
}
const exclude_tags = new Set(get_exclude_tags());
var filtered_statistics = [];
let filtered_statistics = [];
for (const [key, value] of Object.entries(statistics)) {
if (in_memory_skip_tasks.has(key)) {
continue;
@@ -205,9 +205,9 @@ function get_some_tasks(hints) {
filtered_statistics.sort((a, b) =>
b[1].statistics.avg_yield_per_min - a[1].statistics.avg_yield_per_min
);
var candidates = [];
var sum_yield = 0;
var sum_running_seconds = 0;
let candidates = [];
let sum_yield = 0;
let sum_running_seconds = 0;
for (const [key, value] of filtered_statistics) {
candidates.push([key, value]);
sum_yield += value.statistics.avg_yield;
@@ -239,7 +239,7 @@ function get_some_tasks(hints) {
i.tasks.sort();
}
const tasks = Array.from(Object.values(candidate_groups)).sort((a, b) => b.avg_yield_per_min - a.avg_yield_per_min).map(i => i.tasks).flat();
var log_content = "";
let log_content = "";
sum_yield = 0;
sum_running_seconds = 0;
for (const i of tasks) {
@@ -306,7 +306,7 @@ async function get_inventory() {
return inventory_result;
}
var last_script_end_pos = [null, null];
let last_script_end_pos = [null, null];
async function run_pathing_script(name, path_state_change, current_states) {
path_state_change ||= {};
@@ -329,10 +329,10 @@ async function run_pathing_script(name, path_state_change, current_states) {
}
}
log.info("运行 {name}", name);
var json_content = await file.readText(filename_to_path_map[name]);
let json_content = await file.readText(filename_to_path_map[name]);
{
const json_obj = JSON.parse(json_content);
var modified = false;
let modified = false;
for (const i of json_obj.positions) {
if (use_global_mining_action) {
if (settings.custom_mining_action && i.action === "combat_script" && i.action_params.includes("诺艾尔 ")) {
@@ -371,7 +371,7 @@ async function run_pathing_script(name, path_state_change, current_states) {
} catch (e) {}
return [null, null];
})();
var character_moved = false;
let character_moved = false;
if (curr_pos[0] === null || last_script_end_pos[0] === null) {
character_moved = curr_pos[0] !== last_script_end_pos[0] || curr_pos[1] !== last_script_end_pos[1];
log.debug("Character {action}", character_moved ? "moved" : "not moved");
@@ -421,7 +421,7 @@ async function main() {
}
const get_current_cst_hour = () => (Date.now() / 1000 + 8 * 3600) % 86400 / 3600;
var run_until_unix_time = settings.target_running_minutes ? (Date.now() + Number(settings.target_running_minutes) * 60 * 1000) : null;
let run_until_unix_time = settings.target_running_minutes ? (Date.now() + Number(settings.target_running_minutes) * 60 * 1000) : null;
if (settings.time_range) {
const time_range = settings.time_range.replace("", "~").replace("", ":");
if (time_range.includes("~")) {
@@ -469,12 +469,12 @@ async function main() {
}
const start_time = Date.now();
var last_log_progress_time = 0;
var accurate_yield = 0;
var estimated_yield = 0;
var cached_inventory_data = original_inventory;
let last_log_progress_time = 0;
let accurate_yield = 0;
let estimated_yield = 0;
let cached_inventory_data = original_inventory;
var finished = false;
let finished = false;
const current_states = new Set();
while (!finished) {
const hints = {
@@ -483,7 +483,7 @@ async function main() {
};
{
const now = Math.floor(Date.now() / 1000);
var next_refresh_unix_time = Math.floor(now / 86400) * 86400 + 16 * 3600;
let next_refresh_unix_time = Math.floor(now / 86400) * 86400 + 16 * 3600;
next_refresh_unix_time += 180; // to avoid the effect of clock skew
if (next_refresh_unix_time < now) {
next_refresh_unix_time += 86400;
@@ -547,7 +547,7 @@ async function main() {
const end_time = Date.now();
const running_minutes = (end_time - start_time) / 1000 / 60;
var total_yield_str = [];
let total_yield_str = [];
const latest_inventory = cached_inventory_data ? cached_inventory_data : (await get_inventory());
if (latest_inventory.crystal_chunks - original_inventory.crystal_chunks) {
total_yield_str.push(`${latest_inventory.crystal_chunks - original_inventory.crystal_chunks}水晶块`);