js:等待到指定时间 (#1306)
This commit is contained in:
22
repo/js/等待到指定时间/README.md
Normal file
22
repo/js/等待到指定时间/README.md
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
# 等待到指定时间
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 一、使用方法及配置建议
|
||||||
|
|
||||||
|
1. 在配置组中点击 **+ 添加**,搜索并选择「等待到指定时间.js」后加入该组。
|
||||||
|
|
||||||
|
2. 在配置组界面中,对该脚本点击右键,选择 **修改 js 脚本自定义配置**,设置停止运行时间。
|
||||||
|
- 请务必先设置停止运行时间,否则脚本不会正常运行。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 二、注意事项
|
||||||
|
|
||||||
|
- 运行时间必须早于停止运行时间,否则无法正常触发。
|
||||||
|
- 若设置的停止运行时间已过(即早于当前时间),系统会自动等待至次日相同时间再执行。
|
||||||
|
- 示例:
|
||||||
|
- 当前时间:4:00
|
||||||
|
- 停止运行时间:3:55
|
||||||
|
- 则实际等待:23 小时 55 分后触发
|
||||||
|
|
||||||
55
repo/js/等待到指定时间/main.js
Normal file
55
repo/js/等待到指定时间/main.js
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
(async function () {
|
||||||
|
/**
|
||||||
|
* 計算從「現在」到下一次指定時分的毫秒差
|
||||||
|
*
|
||||||
|
* @param {number} validatedHours 小時(0–23)
|
||||||
|
* @param {number} validatedMinutes 分鐘(0–59)
|
||||||
|
* @returns {number} 下一次指定時分與目前時間的毫秒差
|
||||||
|
*/
|
||||||
|
function getTimeUntilNextTime(validatedHours, validatedMinutes) {
|
||||||
|
const now = new Date();
|
||||||
|
const nextTime = new Date(
|
||||||
|
now.getFullYear(),
|
||||||
|
now.getMonth(),
|
||||||
|
now.getDate(),
|
||||||
|
validatedHours, validatedMinutes, 0, 0
|
||||||
|
);
|
||||||
|
|
||||||
|
// 如果目前時間已經到達或超過今天指定的時刻,就把 nextTime 設為明天的同一時間
|
||||||
|
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);
|
||||||
|
|
||||||
|
if (isNaN(specifyHours) || isNaN(specifyMinutes)) {
|
||||||
|
log.warn(`⚠️先請设置停止运行的时间⚠️\n
|
||||||
|
⚠️⚠️先請设置停止运行的时间⚠️⚠️\n
|
||||||
|
⚠️⚠️⚠️先請设置停止运行的时间⚠️⚠️⚠️\n`);
|
||||||
|
} else {
|
||||||
|
|
||||||
|
log.info(`---------------将等待至 ${specifyHours}:${specifyMinutes} ---------------`)
|
||||||
|
|
||||||
|
// 計算相差時間微秒
|
||||||
|
const timeUntilNextTime = getTimeUntilNextTime(specifyHours, specifyMinutes);
|
||||||
|
log.info(`等待 ${Math.floor((timeUntilNextTime / 60000 / 60))} 小时 ${(timeUntilNextTime / 60000 % 60).toFixed(0)} 分 ,直至 ${specifyHours} : ${specifyMinutes}`);
|
||||||
|
// 多等待10秒
|
||||||
|
await sleep(timeUntilNextTime + 10000);
|
||||||
|
log.info(`时间到了!现在是 ${specifyHours}:${specifyMinutes}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
//1秒 = 1000 毫秒
|
||||||
|
//10秒 = 10000 毫秒
|
||||||
|
//1分鐘 = 60000 毫秒
|
||||||
|
})();
|
||||||
16
repo/js/等待到指定时间/manifest.json
Normal file
16
repo/js/等待到指定时间/manifest.json
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
{
|
||||||
|
"manifest_version": 1,
|
||||||
|
"name": "等待到指定时间",
|
||||||
|
"version": "1.1",
|
||||||
|
"bgi_version": "0.42.0",
|
||||||
|
"description": "等待到指定时间:\n可用于等到第二天4点执行其他任务\n使用时務必先設定停止運行時間,否則腳本不會正常運行\n詳見README.md",
|
||||||
|
"authors": [
|
||||||
|
{
|
||||||
|
"name": "蜜柑魚",
|
||||||
|
"link": "https://github.com/this-Fish"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"settings_ui": "settings.json",
|
||||||
|
"main": "main.js"
|
||||||
|
}
|
||||||
|
|
||||||
100
repo/js/等待到指定时间/settings.json
Normal file
100
repo/js/等待到指定时间/settings.json
Normal file
@@ -0,0 +1,100 @@
|
|||||||
|
[
|
||||||
|
{
|
||||||
|
"name": "specifyHours",
|
||||||
|
"type": "select",
|
||||||
|
"label": "设置停止运行的时间(24小时制)\n请同时设置“小时”和“分钟”,否则该配置不会生效。\n\n小时",
|
||||||
|
"options": [
|
||||||
|
"0",
|
||||||
|
"1",
|
||||||
|
"2",
|
||||||
|
"3",
|
||||||
|
"4",
|
||||||
|
"5",
|
||||||
|
"6",
|
||||||
|
"7",
|
||||||
|
"8",
|
||||||
|
"9",
|
||||||
|
"10",
|
||||||
|
"11",
|
||||||
|
"12",
|
||||||
|
"13",
|
||||||
|
"14",
|
||||||
|
"15",
|
||||||
|
"16",
|
||||||
|
"17",
|
||||||
|
"18",
|
||||||
|
"19",
|
||||||
|
"20",
|
||||||
|
"21",
|
||||||
|
"22",
|
||||||
|
"23"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "specifyMinutes",
|
||||||
|
"type": "select",
|
||||||
|
"label": "分钟",
|
||||||
|
"options": [
|
||||||
|
"0",
|
||||||
|
"1",
|
||||||
|
"2",
|
||||||
|
"3",
|
||||||
|
"4",
|
||||||
|
"5",
|
||||||
|
"6",
|
||||||
|
"7",
|
||||||
|
"8",
|
||||||
|
"9",
|
||||||
|
"10",
|
||||||
|
"11",
|
||||||
|
"12",
|
||||||
|
"13",
|
||||||
|
"14",
|
||||||
|
"15",
|
||||||
|
"16",
|
||||||
|
"17",
|
||||||
|
"18",
|
||||||
|
"19",
|
||||||
|
"20",
|
||||||
|
"21",
|
||||||
|
"22",
|
||||||
|
"23",
|
||||||
|
"24",
|
||||||
|
"25",
|
||||||
|
"26",
|
||||||
|
"27",
|
||||||
|
"28",
|
||||||
|
"29",
|
||||||
|
"30",
|
||||||
|
"31",
|
||||||
|
"32",
|
||||||
|
"33",
|
||||||
|
"34",
|
||||||
|
"35",
|
||||||
|
"36",
|
||||||
|
"37",
|
||||||
|
"38",
|
||||||
|
"39",
|
||||||
|
"40",
|
||||||
|
"41",
|
||||||
|
"42",
|
||||||
|
"43",
|
||||||
|
"44",
|
||||||
|
"45",
|
||||||
|
"46",
|
||||||
|
"47",
|
||||||
|
"48",
|
||||||
|
"49",
|
||||||
|
"50",
|
||||||
|
"51",
|
||||||
|
"52",
|
||||||
|
"53",
|
||||||
|
"54",
|
||||||
|
"55",
|
||||||
|
"56",
|
||||||
|
"57",
|
||||||
|
"58",
|
||||||
|
"59"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
Reference in New Issue
Block a user