-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmonitor.js
More file actions
169 lines (145 loc) · 5.04 KB
/
monitor.js
File metadata and controls
169 lines (145 loc) · 5.04 KB
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
/*
* Yeelovo 开放账号监控脚本
*
* 功能:定时检查开放账号,有新账号时通知
* 更新:2026-01-31
*
* Surge 配置:
* [Script]
* yeelovo_monitor = type=cron,cronexp="* * * * *",wake-system=1,timeout=20,script-path=https://raw.githubusercontent.com/br7roy/nc-script/refs/heads/master/monitor.js,script-update-interval=0
*/
const $ = new Env('Yeelovo监控');
// 配置项(从 BoxJS 读取)
const CONFIG = {
token: $.getdata('yeelovo_token') || '',
apiUrl: 'https://team.yeelovo.com/api/open-accounts',
targetUrl: 'https://team.yeelovo.com/redeem/open-accounts',
checkInterval: $.getdata('yeelovo_interval') || '1', // 检查间隔(分钟)
yeelovo_check_size: $.getdata('yeelovo_check_size') || '1',
alwaysNotify: $.getdata('yeelovo_always_notify') !== 'false', // 总是通知(默认 true)
};
// 主函数
async function main() {
try {
// 验证配置
if (!CONFIG.token) {
console.log('❌ 未配置 Token,请在 BoxJS 中设置');
$.msg('Yeelovo监控', '配置错误', '请先在 BoxJS 中配置 Token');
return;
}
console.log('🔍 开始检查开放账号...');
// 发起请求
const response = await fetchOpenAccounts();
// 解析响应
if (!response || response.error) {
throw new Error(response?.error || '请求失败');
}
const data = typeof response === 'string' ? JSON.parse(response) : response;
// 检查 items 字段
const items = data.items || [];
const total = data.total || 0;
const rules = data.rules || {};
console.log(`📊 检查结果: items数量=${items.length}, total=${total}`);
console.log(`📋 规则: 今日剩余次数=${rules.userDailyLimitRemaining}, 积分消耗=${rules.creditCost}`);
// 判断是否有新账号
if (items.length > CONFIG.yeelovo_check_size) {
// ✅ 有新账号 - 发送通知并跳转
const message = `发现 ${items.length} 个开放账号!\n剩余兑换次数: ${rules.userDailyLimitRemaining || 0}`;
console.log(`✅ ${message}`);
$.msg(
'Yeelovo 开放账号',
'🎉 有新账号可兑换!',
message,
{
'url': CONFIG.targetUrl,
'media-url': 'https://team.yeelovo.com/favicon.ico'
}
);
} else {
// ❌ 暂无账号
const message = `暂无开放账号\n剩余次数: ${rules.userDailyLimitRemaining || 0}`;
console.log(`ℹ️ ${message}`);
// 根据配置决定是否通知
if (CONFIG.alwaysNotify) {
$.msg('Yeelovo 开放账号', '暂无新账号', message);
}
}
// 检查是否在禁止兑换时段
if (rules.redeemBlockedNow) {
console.log(`⏰ ${rules.redeemBlockedMessage}`);
}
} catch (error) {
console.log(`❌ 错误: ${error.message}`);
// $.msg('Yeelovo监控', '运行出错', error.message);
} finally {
$.done();
}
}
// 请求开放账号 API
function fetchOpenAccounts() {
return new Promise((resolve, reject) => {
const options = {
url: CONFIG.apiUrl,
headers: {
'authority': 'team.yeelovo.com',
'accept': 'application/json, text/plain, */*',
'accept-language': 'zh-CN,zh-Hans;q=0.9',
'accept-encoding': 'gzip, deflate, br',
'cache-control': 'no-cache',
'pragma': 'no-cache',
'sec-fetch-site': 'same-origin',
'sec-fetch-mode': 'cors',
'sec-fetch-dest': 'empty',
'user-agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 16_3_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148',
'referer': 'https://team.yeelovo.com/redeem/open-accounts',
'x-linuxdo-token': CONFIG.token
}
};
$.get(options, (error, response, body) => {
if (error) {
reject(error);
} else {
resolve(body);
}
});
});
}
// Surge/Loon/QuantumultX 兼容环境
function Env(name) {
const isLoon = typeof $loon !== 'undefined';
const isQuanX = typeof $task !== 'undefined';
const isSurge = typeof $httpClient !== 'undefined' && !isLoon;
const log = (...args) => console.log(args.join(' '));
const msg = (title, subtitle, message, options = {}) => {
if (isSurge || isLoon) {
$notification.post(title, subtitle, message, options);
} else if (isQuanX) {
$notify(title, subtitle, message, options);
}
};
const getdata = (key) => {
if (isSurge || isLoon) {
return $persistentStore.read(key);
} else if (isQuanX) {
return $prefs.valueForKey(key);
}
};
const get = (options, callback) => {
if (isSurge || isLoon) {
$httpClient.get(options, callback);
} else if (isQuanX) {
options.method = 'GET';
$task.fetch(options).then(
(response) => callback(null, response, response.body),
(reason) => callback(reason.error, null, null)
);
}
};
const done = (value = {}) => {
if (isQuanX) return $done(value);
if (isSurge || isLoon) return $done();
};
return { name, log, msg, getdata, get, done };
}
// 执行主函数
main();