|
执行 jq 的时候自动把倒计时的任务和任务的时间加到主界面的右下角
通过 action 把任务名称和倒计时的中文名称获取到,然后调用一个函数把中文的时间改成数字秒,最后设置4个倒计时计算器的第一个
let self = this;
api.action(/│主\s+│([\u4e00-\u9fa5+).+?│仍需([\u4e00-\u9fa5+)才能接到下个任务/, function (arg) {
api.echo(arg[1] + ' ' + arg[2] + ' ' + self.chineseToSeconds(arg[2]))
api.timer(1, arg[1], self.chineseToSeconds(arg[2]), true, 'ss')
})
- parseChineseNumber: function (str) {
- const digits = { "零": 0, "一": 1, "二": 2, "三": 3, "四": 4, "五": 5, "六": 6, "七": 7, "八": 8, "九": 9 };
- let result = 0;
- let temp = 0;
-
- if (str.includes("十")) {
- const parts = str.split("十");
- const tens = parts[0] === "" ? 1 : digits[parts[0]];
- const ones = parts[1] ? digits[parts[1]] : 0;
- result = tens * 10 + ones;
- } else {
- for (let i = 0; i < str.length; i++) {
- if (digits[str[i]] !== undefined) {
- temp = temp * 10 + digits[str[i]];
- }
- }
- result = temp;
- }
-
- return result;
- },
- chineseToSeconds: function (timeStr) {
- const timeUnits = {
- "秒": 1,
- "分钟": 60,
- "分": 60,
- "小时": 3600,
- "时": 3600
- };
-
- let totalSeconds = 0;
- let buffer = "";
-
- for (let i = 0; i < timeStr.length; i++) {
- let char = timeStr[i];
- let unit = char;
-
- if (i + 1 < timeStr.length) {
- const twoCharUnit = char + timeStr[i + 1];
- if (timeUnits[twoCharUnit]) {
- unit = twoCharUnit;
- i++;
- }
- }
-
- if (timeUnits[unit]) {
- const num = this.parseChineseNumber(buffer);
- totalSeconds += (num || 1) * timeUnits[unit];
- buffer = "";
- } else {
- buffer += char;
- }
- }
-
- if (buffer.length > 0) {
- totalSeconds += this.parseChineseNumber(buffer);
- }
-
- return totalSeconds;
- }
复制代码
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?注册
x
|