等待到指定时间(默认凌晨4点) (#364)
* Revert "等到4點 (#363)"
This reverts commit 50f79211ff.
* 等待到指定时间(默认凌晨4点)
等待到指定时间(默认凌晨4点),适用于等到第二天4点执行其他任务
This commit is contained in:
@@ -1,29 +0,0 @@
|
||||
(async function () {
|
||||
setGameMetrics(1920, 1080, 2);
|
||||
|
||||
function getTimeUntilNext4AM() {
|
||||
const now = new Date();
|
||||
const next4AM = new Date(
|
||||
now.getFullYear(),
|
||||
now.getMonth(),
|
||||
now.getDate(),
|
||||
4, 0, 0, 0
|
||||
);
|
||||
|
||||
// 如果現在時間已經過了今天的 4 點,則計算明天的 4 點
|
||||
if (now >= next4AM) {
|
||||
next4AM.setDate(next4AM.getDate() + 1);
|
||||
}
|
||||
|
||||
return next4AM - now;
|
||||
}
|
||||
|
||||
// 執行
|
||||
const timeUntilNext4AM = getTimeUntilNext4AM();
|
||||
log.info(`等待 ${timeUntilNext4AM / 60000} 分鐘直到下一個 4 點…`);
|
||||
// 多等待1分鐘
|
||||
await sleep(timeUntilNext4AM + 60000);
|
||||
log.info("時間到了!現在是 4 點。");
|
||||
|
||||
//1 分鐘 = 60000 毫秒
|
||||
})();
|
||||
@@ -1,16 +0,0 @@
|
||||
{
|
||||
"manifest_version": 1,
|
||||
"name": "等到4點", // 名称
|
||||
"version": "1.0", // 版本
|
||||
"bgi_version": "1.0", // 适用于 BetterGI 的最低版本,BetterGI低于此版本会提示
|
||||
"description": "等到4點,用於等到第二天4點執行其他任務", // 描述
|
||||
// 作者信息
|
||||
"authors": [
|
||||
{
|
||||
"name": "蜜柑魚"
|
||||
}
|
||||
],
|
||||
// 入口文件
|
||||
"main": "main.js"
|
||||
}
|
||||
|
||||
66
repo/js/等待到指定时间(默认凌晨4点)/main.js
Normal file
66
repo/js/等待到指定时间(默认凌晨4点)/main.js
Normal file
@@ -0,0 +1,66 @@
|
||||
(async function () {
|
||||
|
||||
const defaultHours = 4;
|
||||
const defaultMinutes = 0;
|
||||
|
||||
function validateAndSetDefaults(specifyHours, specifyMinutes) {
|
||||
if (isNaN(specifyHours) || specifyHours > 23) {
|
||||
if (specifyHours > 23) {
|
||||
log.warn("设置指定时间错误,请使用 0~23 时,将使用默认值:4时");
|
||||
} else {
|
||||
log.warn("你没有设置指定时,将使用默认值:4时");
|
||||
}
|
||||
specifyHours = defaultHours;
|
||||
}
|
||||
if (isNaN(specifyMinutes) || specifyMinutes > 59) {
|
||||
if (specifyMinutes > 59) {
|
||||
log.warn("设置指定时间错误,请使用 0~59 分,将使用默认值:0分");
|
||||
} else {
|
||||
log.warn("你没有设置指定分钟,将使用默认值:0分");
|
||||
}
|
||||
specifyMinutes = defaultMinutes;
|
||||
}
|
||||
log.info(`---------------将等待至 ${specifyHours}:${specifyMinutes} ---------------`)
|
||||
return { specifyHours, specifyMinutes };
|
||||
}
|
||||
|
||||
// 計算相差時間微秒
|
||||
function getTimeUntilNextTime(validatedHours, validatedMinutes) {
|
||||
const now = new Date();
|
||||
const nextTime = new Date(
|
||||
now.getFullYear(),
|
||||
now.getMonth(),
|
||||
now.getDate(),
|
||||
validatedHours, validatedMinutes, 0, 0
|
||||
);
|
||||
|
||||
// 如果現在時間已經過了今天的 4 點,則計算明天的 4 點
|
||||
if (now >= nextTime) {
|
||||
nextTime.setDate(nextTime.getDate() + 1);
|
||||
}
|
||||
|
||||
return nextTime - now;
|
||||
}
|
||||
|
||||
setGameMetrics(1920, 1080, 2);
|
||||
// 启用自动拾取的实时任务
|
||||
dispatcher.addTimer(new RealtimeTimer("AutoPick"));
|
||||
// 启用自动剧情的实时任务
|
||||
dispatcher.addTimer(new RealtimeTimer("AutoSkip"));
|
||||
// 讀取參數
|
||||
let specifyHours = Number(settings.specifyHours);
|
||||
let specifyMinutes = Number(settings.specifyMinutes);
|
||||
|
||||
const { specifyHours: validatedHours, specifyMinutes: validatedMinutes } = validateAndSetDefaults(specifyHours, specifyMinutes);
|
||||
|
||||
// 計算相差時間微秒
|
||||
const timeUntilNextTime = getTimeUntilNextTime(validatedHours, validatedMinutes);
|
||||
log.info(`等待 ${Math.floor((timeUntilNextTime / 60000/60))} 小时 ${(timeUntilNextTime / 60000%60).toFixed(0)} 分 ,直到下一个 ${validatedHours} : ${validatedMinutes}`);
|
||||
// 多等待10秒
|
||||
await sleep(timeUntilNextTime + 10000);
|
||||
log.info(`时间到了!现在是 ${specifyHours}:${specifyMinutes}`);
|
||||
|
||||
//1秒 = 1000 毫秒
|
||||
//10秒 = 10000 毫秒
|
||||
//1分鐘 = 60000 毫秒
|
||||
})();
|
||||
16
repo/js/等待到指定时间(默认凌晨4点)/manifest.json
Normal file
16
repo/js/等待到指定时间(默认凌晨4点)/manifest.json
Normal file
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"manifest_version": 1,
|
||||
"name": "等待到指定时间(默认凌晨4点)",
|
||||
"version": "1.0",
|
||||
"bgi_version": "0.42.0",
|
||||
"description": "等待到指定时间(默认凌晨4点),适用于等到第二天4点执行其他任务",
|
||||
"authors": [
|
||||
{
|
||||
"name": "蜜柑魚",
|
||||
"link": "https://github.com/this-Fish"
|
||||
}
|
||||
],
|
||||
"settings_ui": "settings.json",
|
||||
"main": "main.js"
|
||||
}
|
||||
|
||||
12
repo/js/等待到指定时间(默认凌晨4点)/settings.json
Normal file
12
repo/js/等待到指定时间(默认凌晨4点)/settings.json
Normal file
@@ -0,0 +1,12 @@
|
||||
[
|
||||
{
|
||||
"name": "specifyHours",
|
||||
"type": "input-text",
|
||||
"label": "指定等待直到下一个 HH:MM 的时(默认:4)"
|
||||
},
|
||||
{
|
||||
"name": "specifyMinutes",
|
||||
"type": "input-text",
|
||||
"label": "指定等待直到下一个 HH:MM 的分钟(默认:0)"
|
||||
}
|
||||
]
|
||||
Reference in New Issue
Block a user