forked from evilbutcher/Scriptables
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dler Cloud.js
347 lines (333 loc) · 11.3 KB
/
Dler Cloud.js
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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
// Variables used by Scriptable.
// These must be at the very top of the file. Do not edit.
// icon-color: purple; icon-glyph: plane-departure;
/*
* Author: evilbutcher Neurogram
* Github: https://github.com/evilbutcher
* 本脚本使用了@Gideon_Senku的Env.scriptable,感谢!
* 感谢@MuTu88帮忙测试!
* 自动更新打开后会运行覆盖脚本内已有修改,多种解决方案:
* 一、配置Config文件,请参考https://github.com/evilbutcher/Scriptables/blob/master/Config.js,下载后导入Scriptable,脚本运行会❗️优先❗️调取Config文件中信息,此方法只能显示❗️一个❗️机场。
* 二、【推荐】Scriptable的iCloud文件夹内,配置checkin.json文件(注意文件名),具体格式参考https://github.com/evilbutcher/Scriptables/blob/master/checkin_example.json,可以通过创建桌面小组件时填入不同参数如“c1”、“c2”等实现读取多个机场信息。
* 三、脚本内配置,在下方注释写有填写签到标题的引号内,填写对应的签到信息,注意,此方法一旦更新脚本,所做的更改就会被远程文件覆盖。
* 脚本运行后,会在iCloud/Scriptable文件夹内写入一个recordcheckintime.txt,用于记录签到时间,脚本逻辑每天签到一次。
*/
const goupdate = false; //默认关闭,需要时打开,更新后会覆盖脚本已有的签到信息,建议使用Config或Scriptable的iCloud文件夹存入checkin.json文件的方式
const $ = importModule("Env");
$.autoLogout = false; //退出登录后再签到
try {
const para = args.widgetParameter || "c1";
const fileName = "checkin.json";
const res = JSON.parse($.read(fileName));
var checkintitle = res[para].title || ""; //填写签到标题
var checkinloginurl = res[para].url || ""; //填写签到登陆链接
var checkinemail = res[para].email || ""; //填写签到邮箱
var checkinpwd = res[para].password || ""; //填写签到密码
} catch (e) {
log("获取JSON文件失败");
}
const size = 12; //字体大小
const isDark = Device.isUsingDarkAppearance();
const bgColor = new LinearGradient();
bgColor.colors = isDark
? [new Color("#030079"), new Color("#000000")]
: [new Color("#a18cd1"), new Color("#fbc2eb")];
bgColor.locations = [0.0, 1.0];
function addTextToListWidget(text, listWidget) {
let item = listWidget.addText(text);
item.textColor = isDark ? Color.white() : Color.black();
item.font = new Font('SF Mono', size);
}
function addTitleTextToListWidget(text, listWidget) {
let item = listWidget.addText(text);
item.textColor = isDark ? Color.white() : Color.black();
try {
item.font = Font.boldSystemFont(18);
} catch(e) {
item.font = new Font('SF Mono', 18);
}
}
const scripts = [
{
moduleName: "Checkin",
url:
"https://raw.githubusercontent.com/evilbutcher/Scriptables/master/Dler%20Cloud.js",
},
];
!(async () => {
init();
getinfo();
await launch();
log($.checkintitle);
log($.checkinMsg);
log($.todayUsed);
log($.usedData);
log($.restData);
let widget = createWidget(
$.checkintitle,
$.checkinMsg,
$.todayUsed,
$.usedData,
$.restData
);
Script.setWidget(widget);
Script.complete();
})()
.catch((err) => {
$.msg("Checkin运行出现错误❌\n" + err);
})
.finally(update());
function getinfo() {
try {
const con = importModule("Config");
$.checkintitle = con.checkintitle();
$.checkinloginurl = con.checkinloginurl();
$.checkinemail = con.checkinemail();
$.checkinpwd = con.checkinpwd();
if (
$.checkintitle == "" ||
$.checkinloginurl == "" ||
$.checkinemail == "" ||
$.checkinpwd == ""
) {
log("配置文件内签到信息不完整");
throw new Error(err);
}
log("将使用配置文件内签到信息");
} catch (err) {
$.checkintitle = checkintitle;
$.checkinloginurl = checkinloginurl;
$.checkinemail = checkinemail;
$.checkinpwd = checkinpwd;
log("将使用脚本内签到信息");
if (
$.checkintitle == "" ||
$.checkinloginurl == "" ||
$.checkinemail == "" ||
$.checkinpwd == ""
) {
$.msg("请检查填入的签到信息是否完整");
}
}
}
function init() {
$.nowtime = new Date().getTime();
log($.nowtime);
if ($.isFileExists("recordcheckintime.txt") == true) {
var recordtime = $.read("recordcheckintime.txt");
log(recordtime);
if ($.nowtime - recordtime > 86400000) {
$.cancheckin = true;
$.write("recordcheckintime.txt", JSON.stringify($.nowtime));
} else {
$.cancheckin = false;
}
} else {
$.write("recordcheckintime.txt", JSON.stringify($.nowtime));
log("初始时间已写入");
$.cancheckin = true;
}
}
async function launch() {
let title = $.checkintitle;
let url = $.checkinloginurl;
let email = $.checkinemail;
let password = $.checkinpwd;
if ($.autoLogout == true) {
let logoutPath =
url.indexOf("auth/login") != -1 ? "user/logout" : "user/logout.php";
var logouturl = {
url: url.replace(/(auth|user)\/login(.php)*/g, "") + logoutPath,
};
log(logouturl);
await $.getStr(logouturl);
await login(url, email, password, title);
if ($.loginok == true) {
if ($.cancheckin == true) {
await checkin(url, email, password, title);
if ($.checkinok == true) {
await dataResults(url, $.checkindatamsg, title);
}
} else {
await dataResults(url, "签到完成🎉", title);
}
}
} else {
if ($.cancheckin == true) {
await checkin(url, email, password, title);
if ($.checkinok == true) {
await dataResults(url, $.checkindatamsg, title);
} else {
await login(url, email, password, title);
if ($.loginok == true) {
await checkin(url, email, password, title);
await dataResults(url, "签到完成🎉", title);
}
}
} else {
await dataResults(url, "签到完成🎉", title);
if ($.getdata == false) {
await login(url, email, password, title);
if ($.loginok == true) {
await dataResults(url, "签到完成🎉", title);
}
}
}
}
}
async function login(url, email, password, title) {
let loginPath =
url.indexOf("auth/login") != -1 ? "auth/login" : "user/_login.php";
let table = {
url:
url.replace(/(auth|user)\/login(.php)*/g, "") +
loginPath +
`?email=${email}&passwd=${password}&rumber-me=week`,
};
log(table);
await $.post(table, async (response, data) => {
if (
JSON.parse(data).msg.match(
/邮箱不存在|邮箱或者密码错误|Mail or password is incorrect/
)
) {
$.msg(title + "邮箱或者密码错误");
$.loginok = false;
log("登陆失败");
} else {
$.loginok = true;
log("登陆成功");
}
});
}
async function checkin(url, email, password, title) {
let checkinPath =
url.indexOf("auth/login") != -1 ? "user/checkin" : "user/_checkin.php";
var checkinreqest = {
url: url.replace(/(auth|user)\/login(.php)*/g, "") + checkinPath,
};
log(checkinreqest);
await $.post(checkinreqest, async (response, data) => {
if (data.match(/\"msg\"\:/)) {
$.checkinok = true;
$.checkindatamsg = JSON.parse(data).msg;
log("签到成功");
} else {
$.checkinok = false;
log("签到失败");
}
});
}
async function dataResults(url, checkinMsg, title) {
let userPath = url.indexOf("auth/login") != -1 ? "user" : "user/index.php";
var datarequest = {
url: url.replace(/(auth|user)\/login(.php)*/g, "") + userPath,
};
log(datarequest);
await $.getStr(datarequest, async (response, data) => {
if (data.match(/login|请填写邮箱|登陆/)) {
$.getdata = false;
} else {
let resultData = "";
let result = [];
if (data.match(/theme\/malio/)) {
let flowInfo = data.match(/trafficDountChat\s*\(([^\)]+)/);
if (flowInfo) {
let flowData = flowInfo[1].match(/\d[^\']+/g);
let usedData = flowData[0];
let todatUsed = flowData[1];
let restData = flowData[2];
$.todayUsed = `今日已用:${flowData[1]}`;
$.usedData = `本月已用:${flowData[0]}`;
$.restData = `剩余流量:${flowData[2]}`;
result.push(
`今日:${todatUsed}\n已用:${usedData}\n剩余:${restData}`
);
}
let userInfo = data.match(/ChatraIntegration\s*=\s*({[^}]+)/);
if (userInfo) {
let user_name = userInfo[1].match(/name.+'(.+)'/)[1];
let user_class = userInfo[1].match(/Class.+'(.+)'/)[1];
let class_expire = userInfo[1].match(/Class_Expire.+'(.+)'/)[1];
let money = userInfo[1].match(/Money.+'(.+)'/)[1];
result.push(
`用户名:${user_name}\n用户等级:lv${user_class}\n余额:${money}\n到期时间:${class_expire}`
);
}
if (result.length != 0) {
resultData = result.join("\n\n");
}
} else {
let todayUsed = data.match(/expire\"\,\s\".*?\"/);
if (todayUsed) {
var day = JSON.stringify(todayUsed).slice(14, -4);
var time = day.replace(/-/g, "/");
var expire = new Date(time).getTime();
var left = ((expire - $.nowtime) / 86400000).toFixed(0);
result.push(`剩余天数:${left}天`);
$.todayUsed = `剩余天数:${left}天`;
} else {
$.todayUsed = `剩余天数获取失败`;
result.push(`剩余天数获取失败`);
}
let usedData = data.match(
/(Used Transfer|>过去已用|>已用|>总已用|\"已用)[^B]+/
);
if (usedData) {
usedData = flowFormat(usedData[0]);
result.push(`已用:${usedData}`);
$.usedData = `本月已用:${usedData}`;
} else {
$.usedData = `本月已用获取失败`;
result.push(`本月已用获取失败`);
}
let restData = data.match(
/(Remaining Transfer|>剩余流量|>流量剩余|>可用|\"剩余)[^B]+/
);
if (restData) {
restData = flowFormat(restData[0]);
result.push(`剩余:${restData}`);
$.restData = `剩余流量:${restData}`;
} else {
$.restData = `剩余流量获取失败`;
result.push(`剩余流量获取失败`);
}
resultData = result.join("\n");
}
$.checkinMsg = checkinMsg;
log(title + "\n" + checkinMsg + "\n" + resultData);
}
});
}
function flowFormat(data) {
data = data.replace(/\d+(\.\d+)*%/, "");
let flow = data.match(/\d+(\.\d+)*\w*/);
return flow[0] + "B";
}
function createWidget(checkintitle, checkinMsg, todayUsed, usedData, restData) {
const w = new ListWidget();
w.backgroundGradient = bgColor;
w.addSpacer();
w.spacing = 5;
const emoji = w.addText(`🪐`);
emoji.font = new Font('SF Mono', 30);
addTitleTextToListWidget(checkintitle, w);
addTextToListWidget(checkinMsg, w);
addTextToListWidget(todayUsed, w);
addTextToListWidget(usedData, w);
addTextToListWidget(restData, w);
w.addSpacer();
w.spacing = 5;
w.presentSmall();
return w;
}
//更新代码
function update() {
if (goupdate == true) {
log("🔔更新脚本开始!");
scripts.forEach(async (script) => {
await $.getFile(script);
});
log("🔔更新脚本结束!");
}
}