forked from SuperMonster003/Ant-Forest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Ant_Forest_Launcher.js
7558 lines (6559 loc) · 378 KB
/
Ant_Forest_Launcher.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
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* @description alipay ant forest intelligent collection script
*
* @since May 12, 2020
* @version 1.9.19 Beta
* @author SuperMonster003 {@link https://github.com/SuperMonster003}
*
* @see {@link https://github.com/SuperMonster003/Ant_Forest}
*/
let {
$$sel, $$app, $$cfg, $$sto, $$dev, $$flag, $$acc,
images, device, auto, selector, context, dialogs,
floaty, colors, toast, files, idMatches, engines,
events, timers, swipe, sleep, exit, app, threads,
ui, android, className, currentPackage, storages,
id, setText, click,
} = global;
let $$init = {
check: function () {
checkAlipayPackage();
checkModulesMap();
checkSdkAndAJVer();
checkRootAccess();
checkAccessibility();
// `return this;` wasn't adopted here
// considering the location of codes with
// a chaining source jump for IDE like WebStorm
return $$init;
// tool function(s) //
function checkAlipayPackage() {
$$app = $$app || {};
let _pkg = "com.eg.android.AlipayGphone";
if (!app.getAppName(_pkg)) {
messageAction('此设备可能未安装"支付宝"应用', 9, 1, 0, "both");
}
return $$app.pkg_name = _pkg;
}
function checkModulesMap() {
let _map = [
"MODULE_MONSTER_FUNC", "MODULE_STORAGE",
"MODULE_DEFAULT_CONFIG", "MODULE_PWMAP",
"MODULE_TREASURY_VAULT", "MODULE_UNLOCK",
"EXT_DIALOGS", "EXT_TIMERS", "EXT_DEVICE",
"EXT_APP", "EXT_IMAGES", "EXT_ENGINES"
];
let _wanted = [];
for (let i = 0, len = _map.length; i < len; i += 1) {
let _mod = _map[i];
let _path = "./Modules/" + _mod + ".js";
_path = _path.replace(/(\.js){2,}/, ".js");
files.exists(_path) || _wanted.push(_mod);
}
let _wanted_len = _wanted.length;
if (_wanted_len) {
let [line, msg] = [showSplitLineRaw, messageActionRaw];
let _str = "";
void function () {
_str += "脚本无法继续|以下模块缺失或路径错误:|";
_str += "- - - - - - - - - - - - - - - - -|";
_wanted.forEach(n => _str += '-> "' + n + '.js"|');
_str += "- - - - - - - - - - - - - - - - -|";
_str += "请检查或重新放置模块";
}();
line();
_str.split("|").forEach(s => msg(s, 4));
line();
toast("模块缺失或路径错误", "Long");
exit();
}
}
function checkSdkAndAJVer() {
// do not `require()` before `checkModulesMap()`
let _mod = require("./Modules/MODULE_MONSTER_FUNC");
return _mod.checkSdkAndAJVer();
}
function checkRootAccess() {
try {
let {ProcessShell: PS} = com.stardust.autojs.core.util;
let _res = PS.execCommand("date", true).code === 0;
return $$flag.autojs_has_root = _res;
} catch (e) {
}
}
function checkAccessibility() {
let _line = showSplitLineRaw;
let _msg = messageActionRaw;
_checkSvc();
_checkFunc();
// tool function(s) //
function _checkSvc() {
// do not `require()` before `checkModulesMap()`
let _a11y = require("./Modules/EXT_DEVICE").a11y;
let $_func = x => typeof x === "function";
let _pkg = context.packageName;
let _perm = "android.permission.WRITE_SECURE_SETTINGS";
if (_a11y.state()) {
return true;
}
let _mod_sto = require("./Modules/MODULE_STORAGE");
let _mod_mon = require("./Modules/MODULE_MONSTER_FUNC");
let $_cfg = _mod_sto.create("af_cfg").get("config", {});
if ($_cfg.auto_enable_a11y_svc === "ON") {
let _max = 2;
while (_max--) {
if (!_max) {
if ($$flag.autojs_has_root) {
global["shell"]("pm grant " + _pkg + " " + _perm, true);
} else {
break;
}
}
if (_a11y.enable(true)) {
_line();
_msg("已自动开启无障碍服务", 1);
_msg("尝试一次项目重启操作", 1);
_line();
_mod_mon.restartThisEngine({
debug_info_flag: "forcible",
max_restart_engine_times: 1,
});
return sleep(1e4);
}
}
_autoHint();
}
let _hint = "\n即将自动跳转到无障碍服务设置\n" +
"请手动开启Auto.js无障碍服务\n";
if ($_func(auto.waitFor)) {
alert(_hint + "开启后脚本将自动继续");
let _thd = threads.start(function () {
// waitFor: script will continue running rather than stop
// when accessibility service switched on by user
auto.waitFor();
});
_thd.join(6e4);
if (_thd.isAlive()) {
_line();
_msg("等待用户开启无障碍服务超时", 4, 1);
_line();
exit();
}
} else {
alert(_hint + "开启后请再次尝试运行项目");
try {
auto();
} catch (e) {
// consume errors msg from auto()
}
exit();
}
// tool function(s) {
function _autoHint() {
let _shell_sc = "adb shell pm grant " + _pkg + " " + _perm;
_line();
_msg("自动开启无障碍服务失败", 4);
_line();
_msg("可能是Auto.js缺少以下权限:", 4);
_msg("WRITE_SECURE_SETTINGS", 4);
_line();
_msg("可尝试使用ADB工具连接手机", 3);
_msg("并执行以下Shell指令(无换行):\n" +
"\n" + _shell_sc + "\n", 3);
_msg("Shell指令已复制到剪切板", 3);
_msg("重启设备后授权不会失效", 3);
global["setClip"](_shell_sc);
}
}
function _checkFunc() {
let _max = 3;
while (!swipe(1e4, 0, 1e4, 0, 1) && _max--) {
sleep(300);
}
if (_max < 0) {
_line();
void (
"脚本无法继续|无障碍服务状态异常|或基于服务的方法无法使用" +
"|- - - - - - - - - - - - - - - - -|" +
"可尝试以下解决方案:" +
"|- - - - - - - - - - - - - - - - -|" +
'a. 卸载并重新安装"Auto.js"|b. 安装后重启设备|' +
'c. 运行"Auto.js"并拉出侧边栏|d. 开启无障碍服务|' +
"e. 再次尝试运行本项目"
).split("|").forEach(s => _msg(s, 4));
_line();
toast("无障碍服务方法无法使用", "Long");
exit();
}
}
}
// raw function(s) //
function messageActionRaw(msg, lv, if_toast) {
let _s = msg || " ";
if (lv && lv.toString().match(/^t(itle)?$/)) {
let _par = ["[ " + msg + " ]", 1, if_toast];
return messageActionRaw.apply({}, _par);
}
let _lv = +lv;
if (if_toast) {
toast(_s);
}
if (_lv >= 3) {
if (_lv >= 4) {
console.error(_s);
if (_lv >= 8) {
exit();
}
} else {
console.warn(_s);
}
return;
}
if (_lv === 0) {
console.verbose(_s);
} else if (_lv === 1) {
console.log(_s);
} else if (_lv === 2) {
console.info(_s);
}
return true;
}
function showSplitLineRaw(extra_str, style) {
let _extra_str = extra_str || "";
let _split_line = "";
if (style === "dash") {
for (let i = 0; i < 17; i += 1) _split_line += "- ";
_split_line += "-";
} else {
for (let i = 0; i < 33; i += 1) _split_line += "-";
}
return ~console.log(_split_line + _extra_str);
}
},
global: function () {
setGlobalFunctions(); // MONSTER MODULE
setGlobalExtensions(); // EXT MODULES
setGlobalDollarVars(); // `$$xxx`
$$dev.getDisplay(true);
Object.assign($$dev, require("./Modules/MODULE_UNLOCK"));
let _mod_sto = require("./Modules/MODULE_STORAGE");
$$sto.af = _mod_sto.create("af");
$$sto.af_cfg = _mod_sto.create("af_cfg");
$$sto.treas = require("./Modules/MODULE_TREASURY_VAULT");
$$sel = getSelector();
let _def_af = require("./Modules/MODULE_DEFAULT_CONFIG").af || {};
Object.assign($$cfg, _def_af, $$sto.af_cfg.get("config", {}));
setFlags();
function setFlags() {
let _cnsl_detail = $$cfg.console_log_details;
let _dbg_info_sw = $$cfg.debug_info_switch;
let _msg_show_sw = $$cfg.message_showing_switch;
$$flag.msg_details = _cnsl_detail || _dbg_info_sw;
$$flag.debug_info_avail = _dbg_info_sw && _msg_show_sw;
$$flag.no_msg_act_flag = !_msg_show_sw;
try {
let _arg = (engines.execArgvJs() || {}).debug_info_flag;
if (typeof _arg === "undefined" ||
typeof _arg === "string" && _arg === "forcible"
) {
$$flag.debug_info_avail = true;
} else if (!_arg) {
$$flag.debug_info_avail = false;
}
} catch (e) {
// engines is not set as global Object
}
}
appSetter().setEngine().setTask().setParams().setBlist().setTools().setDb().init();
accSetter().setParams().setMain();
debugInfo("开发者测试日志已启用", "both_dash_Up");
debugInfo("Auto.js版本: " + $$app.autojs_ver);
debugInfo("项目版本: " + $$app.project_ver);
debugInfo("安卓系统SDK版本: " + $$app.sdk_ver);
debugInfo("Root权限: " + ($$app.has_root ? "有效" : "无效"));
return $$init;
// tool function(s) //
function setGlobalFunctions() {
// any better ideas ?
let {
clickAction, swipeAndShow, setIntervalBySetTimeout, keycode,
getSelector, equalObjects, waitForAndClickAction, runJsFile,
messageAction, debugInfo, killThisApp, clickActionsPipeline,
waitForAction, baiduOcr, launchThisApp, observeToastMessage,
showSplitLine, classof, timeRecorder, surroundWith,
} = require("./Modules/MODULE_MONSTER_FUNC");
Object.assign(global, {
baiduOcr: baiduOcr,
classof: classof,
clickAction: clickAction,
clickActionsPipeline: clickActionsPipeline,
debugInfo: debugInfo,
equalObjects: equalObjects,
getSelector: getSelector,
keycode: keycode,
killThisApp: killThisApp,
launchThisApp: launchThisApp,
messageAction: messageAction,
messageAct: function () {
return $$flag.msg_details
? messageAction.apply({}, Object.values(arguments))
: (m, lv) => ![3, 4].includes(lv);
},
observeToastMessage: observeToastMessage,
runJsFile: runJsFile,
setIntervalBySetTimeout: setIntervalBySetTimeout,
showSplitLine: showSplitLine,
surroundWith: surroundWith,
swipeAndShow: swipeAndShow,
timeRecorder: timeRecorder,
waitForAction: waitForAction,
waitForAndClickAction: waitForAndClickAction,
});
}
function setGlobalExtensions() {
require("./Modules/EXT_GLOBAL_OBJ").load();
require("./Modules/EXT_DEVICE").load();
require("./Modules/EXT_TIMERS").load();
require("./Modules/EXT_DIALOGS").load();
require("./Modules/EXT_APP").load();
require("./Modules/EXT_IMAGES").load();
require("./Modules/EXT_THREADS").load();
require("./Modules/EXT_ENGINES").load();
}
function setGlobalDollarVars() {
// not `$$a = $$b = $$c = {};`
// they shouldn't be assigned
// the same address pointer
$$sel = $$sel || {};
$$app = $$app || {};
$$cfg = $$cfg || {};
$$sto = $$sto || {};
$$flag = $$flag || {};
$$acc = $$acc || {};
$$dev = device || {};
}
function appSetter() {
let _setter = {
setEngine: function () {
let _my_engine = engines.myEngine();
let _e_argv = engines.execArgvJs() || {};
let _getCwp = (e) => {
let _cwp = e.source.toString();
let _defPath = () => e.cwd() + "/Ant_Forest_Launcher.js";
return _cwp.match(/\[remote]/) ? _defPath() : _cwp;
};
void Object.defineProperties($$app, {
cur_pkg: {get: () => currentPackage()},
now: {get: () => new Date()},
ts: {get: () => +new Date()},
ts_sec: {
get: () => {
// java.time.Instant.now().getEpochSecond()
// is incompatible with Android 7.x
return Date.now() / 1e3 >> 0;
}
},
});
void Object.assign($$app, {
my_engine: _my_engine,
my_engine_id: _my_engine.id,
my_engine_argv: _e_argv,
cwd: _my_engine.cwd(), // `files.cwd()` also fine
init_scr_on: _e_argv.init_scr_on || $$dev.is_screen_on,
init_fg_pkg: _e_argv.init_fg_pkg || currentPackage(),
cwp: _getCwp(_my_engine),
exit: function (msg_fg) {
if (msg_fg !== false) {
let _s = $$app.task_name + "任务结束";
messageAction(_s, 1, 0, 0, "both_n");
}
return ui.post(exit);
},
});
return _setter;
},
setTask: function () {
$$app.setPostponedTask = (du, if_toast) => {
if ($$flag.task_deploying) {
return;
}
threads.starts(function () {
$$flag.task_deploying = true;
let _task_s = $$app.task_name + "任务";
let _du_s = du + "分钟";
if (!$$F(if_toast)) {
toast(_task_s + "推迟 " + _du_s);
}
messageAction("推迟" + _task_s, 1, 0, 0, -1);
messageAction("推迟时长: " + _du_s, 1, 0, 0, 1);
let _ts = $$app.ts + du * 60e3;
let _par = {path: $$app.cwp, date: _ts};
let _task = timers.addDisposableTask(_par);
let _suff = "";
if ($$sto.af.get("fg_blist_ctr")) {
_suff = "_auto";
}
$$sto.af.put("next_auto_task", {
task_id: _task.id,
timestamp: _ts,
type: "postponed" + _suff,
});
ui.post(exit);
});
};
return _setter;
},
setParams: function () {
// _unESC says, like me if you also enjoy unicode games :)
let _unESC = s => unescape(s.replace(/(\w{4})/g, "%u$1"));
let _local_pics_path = files.getSdcardPath() + "/.local/Pics/";
void files.createWithDirs(_local_pics_path);
void Object.assign($$app, {
task_name: surroundWith(_unESC("8682868168EE6797")),
rl_title: _unESC("2615FE0F0020597D53CB6392884C699C"),
local_pics_path: _local_pics_path,
rex_energy_amt: /^\s*\d+(\.\d+)?(k?g|t)\s*$/,
has_root: $$flag.autojs_has_root,
});
void Object.assign($$app, {
intent: {
home: {
action: "VIEW",
data: _encURIPar("alipays://platformapi/startapp", {
saId: 20000067,
url: "https://60000002.h5app.alipay.com/www/home.html",
__webview_options__: {
startMultApp: "YES",
appClearTop: "YES",
enableCubeView: "NO",
enableScrollBar: "NO",
backgroundColor: "-1",
},
}),
},
rl: {
action: "VIEW",
data: _encURIPar("alipays://platformapi/startapp", {
saId: 20000067,
url: "https://60000002.h5app.alipay.com/www/listRank.html",
__webview_options__: {
appClearTop: "YES",
startMultApp: "YES",
showOptionMenu: "YES",
gestureBack: "YES",
backBehavior: "back",
enableCubeView: "NO",
enableScrollBar: "NO",
backgroundColor: "-1",
defaultTitle: $$app.rl_title,
transparentTitle: "none",
},
}),
},
acc_man: {
action: "VIEW",
data: "alipays://platformapi/startapp?appId=20000027",
},
acc_login: {
action: "VIEW",
data: "alipays://platformapi/startapp?appId=20000008",
},
},
fri_drop_by: {
_pool: [],
_max: 5,
ic: function (name) {
let _ctr = this._pool[name] || 0;
if (_ctr === this._max) {
debugInfo("发送排行榜复查停止信号");
debugInfo(">已达连续好友访问最大阈值");
$$flag.rl_review_stop = true;
}
this._pool[name] = ++_ctr;
},
dc: function (name) {
let _ctr = this._pool[name] || 0;
this._pool[name] = _ctr > 1 ? --_ctr : 0;
},
},
});
void _addSelectors();
return _setter;
// tool function(s) //
function _addSelectors() {
let _acc_logged_out = new RegExp(".*(" +
/在其他设备登录|logged +in +on +another/.source + "|" +
/.*账号于.*通过.*登录.*|account +logged +on +to/.source +
").*");
let _login_err_msg = (type) => {
type = type || "txt";
return $$sel.pickup(id("com.alipay.mobile.antui:id/message"), type)
|| $$sel.pickup([$$sel.get("login_err_ensure"), "p2c0c0c0"], type);
};
$$sel.add("af", "蚂蚁森林")
.add("alipay_home", [/首页|Homepage/, {
boundsInside: [0, cY(0.7), W, H],
}])
.add("af_title", [/蚂蚁森林|Ant Forest/, {
boundsInside: [0, 0, cX(0.4), cY(0.2)],
}])
.add("af_home", /合种|背包|通知|攻略|任务|.*大树养成.*/)
.add("rl_title", $$app.rl_title)
.add("rl_ent", /查看更多好友|View more friends/)
.add("rl_end_idt", /.*没有更多.*/)
.add("list", className("ListView"))
.add("fri_frst_tt", /.+的蚂蚁森林/)
.add("cover_used", /.*使用了保护罩.*/)
.add("wait_awhile", /.*稍等片刻.*/)
.add("reload_fst_page", "重新加载")
.add("close_btn", /关闭|Close/)
.add("acc_logged_out", _acc_logged_out)
.add("acc_sw_pg_ident", /账号切换|Accounts/)
.add("login_btn", /登录|Log in|.*loginButton/)
.add("login_new_acc", /换个新账号登录|[Aa]dd [Aa]ccount/)
.add("login_other_acc", /换个账号登录|.*switchAccount/)
.add("login_other_mthd_init_pg", /其他登录方式|Other accounts/)
.add("login_other_mthd", /换个方式登录|.*[Ss]w.+[Ll]og.+thod/)
.add("login_by_code", /密码登录|Log ?in with password/)
.add("login_next_step", /下一步|Next|.*nextButton/)
.add("login_err_ensure", idMatches(/.*ensure/))
.add("login_err_msg", _login_err_msg)
.add("input_lbl_acc", /账号|Account/)
.add("input_lbl_code", /密码|Password/)
;
}
function _encURIPar(pref, par) {
let _par = par || {};
let _sep = pref.match(/\?/) ? "&" : "?";
let _parseObj = (o) => {
let _res = [];
Object.keys(o).forEach((key) => {
let _val = o[key];
_val = $$obj(_val) ? "&" + _parseObj(_val) : _val;
let _enc_val = $$app.rl_title === _val ? _val : encodeURI(_val);
_res.push(key + "=" + _enc_val);
});
return _res.join("&");
};
return pref + _sep + _parseObj(_par);
}
},
setBlist: function () {
$$app.blist = {
_expired: {
trigger: function (ts) {
if ($$und(ts) || $$inf(ts)) {
return false;
}
let _now = this.now = new Date(); // Date{}
let _du_ts = this.du_ts = ts - +_now;
return _du_ts <= 0;
},
message: function () {
if (!$$flag.msg_details) {
return;
}
let _date_str = this.now.toDateString();
let _date_ts = Date.parse(_date_str); // num
let _du_o = new Date(_date_ts + this.du_ts);
let _d_unit = 24 * 3.6e6;
let _d = Math.trunc(this.du_ts / _d_unit);
let _h = _du_o.getHours();
let _m = _du_o.getMinutes();
let _s = _du_o.getSeconds();
let _pad = num => ("0" + num).slice(-2);
let _d_str = _d ? _d + "天" : "";
let _h_str = _h ? _pad(_h) + "时" : "";
let _m_str = _h || _m ? _pad(_m) + "分" : "";
let _s_str = (_h || _m ? _pad(_s) : _s) + "秒";
return _d_str + _h_str + _m_str + _s_str + "后解除";
}
},
_showMsg: function (type, data) {
let _this = this;
if (type === "add") {
messageAct("已加入黑名单", 1, 0, 1);
} else if (type === "exists") {
messageAct("黑名单好友", 1, 0, 1);
messageAct("已跳过收取", 1, 0, 1);
}
let _rsn_o = {
"protect_cover": "好友使用能量保护罩",
"by_user": "用户自行设置",
};
let _rsn = _rsn_o[data.reason];
let _str = _getExpiredStr(data.timestamp);
messageAction(_rsn, 1, 0, 2);
$$str(_str) && messageAct(_str, 1, 0, 2);
// tool function(s) //
function _getExpiredStr(ts) {
if (_this._expired.trigger(ts)) {
return _this._expired.message();
}
}
},
get: function (name, ref) {
if (!name) {
return ref;
}
let _len = this.data.length;
let _name = name.trimBoth();
for (let i = 0; i < _len; i += 1) {
if (_name === this.data[i].name.trimBoth()) {
this._showMsg("exists", this.data[i]);
return true;
}
}
return ref;
},
save: function () {
$$sto.af.put("blacklist", this.data);
return this;
},
add: function (data_par) {
if ($$len(arguments, 3)) {
data_par = {
name: arguments[0],
timestamp: arguments[1],
reason: arguments[2],
};
}
let _nick = data_par.name;
let _len = this.data.length;
for (let i = 0; i < _len; i += 1) {
let _o = this.data[i];
let _name = _o.name;
let _rsn = _o.reason;
if (_nick === _name && _rsn === "protect_cover") {
delete this.data[i];
break;
}
}
this.data.push(data_par);
this._showMsg("add", data_par);
return this;
},
data: [],
init: function () {
let _blist_setter = this;
blistInitializer().get().clean().message().assign();
return _blist_setter;
// tool function(s) //
function blistInitializer() {
let _blist_data = [];
return {
get: function () {
// legacy: {name: {timestamp::, reason::}}
// modern: [{name::, reason::, timestamp::}]
_blist_data = $$sto.af.get("blacklist", []);
if ($$obj(_blist_data)) {
let _data = [];
Object.keys(_blist_data).forEach((name) => {
_data.push(Object.assign(
{name: name}, _blist_data[name]
));
});
_blist_data = _data;
}
return this;
},
clean: function () {
this.deleted = [];
let _expired = (ts) => {
return _blist_setter._expired.trigger(ts);
};
for (let i = 0; i < _blist_data.length; i += 1) {
let _o = _blist_data[i];
if (!$$obj(_o)) {
_blist_data.splice(i--, 1);
continue;
}
let _name = _o.name;
let _ts = _o.timestamp;
if (!_ts || _expired(_ts)) {
this.deleted.push(_name);
_blist_data.splice(i--, 1);
}
}
return this;
},
message: function () {
let _len = this.deleted.length;
if (_len && $$flag.msg_details) {
let _msg = "移除黑名单记录: " + _len + "项";
messageAct(_msg, 1, 0, 0, "both");
this.deleted.forEach(n => messageAct(n, 1, 0, 1));
}
return this;
},
assign: function () {
_blist_setter.data = _blist_data;
return this;
},
};
}
},
}.init().save();
return _setter;
},
setTools: function () {
$$app.page = {
_plans: {
back: (() => {
let _text = () => {
return $$sel.pickup(["返回", "c0", {clickable: true}])
|| $$sel.pickup(["返回", {clickable: true}]);
};
let _id = () => {
$$sel.pickup(idMatches(/.*h5.+nav.back|.*back.button/));
};
let _bak = [0, 0, cX(100), cYx(200)];
return [_text, _id, _bak];
})(),
close: (() => {
let _text = () => {
return $$sel.pickup([/关闭|Close/, "c0", {clickable: true}])
|| $$sel.pickup([/关闭|Close/, {clickable: true}]);
};
let _id = () => null; // so far
let _bak = [cX(0.8), 0, -1, cYx(200)];
return [_text, _id, _bak];
})(),
launch: {
af: {
_launcher: function (trigger, par) {
delete $$flag.launch_necessary;
delete $$flag.launch_optional;
return launchThisApp(trigger, Object.assign({}, {
task_name: $$app.task_name,
package_name: $$app.pkg_name,
no_message_flag: true,
condition_launch: () => {
// noinspection JSIncompatibleTypesComparison
let _cA = () => $$app.cur_pkg === $$app.pkg_name;
let _cB = function () {
return $$sel.get("rl_ent")
|| $$sel.get("af_home")
|| $$sel.get("wait_awhile");
};
return _cA() || _cB();
},
condition_ready: () => {
let _nec_sel_key = "af_title";
let _opt_sel_keys = ["af_home", "rl_ent"];
return _necessary() && _optional();
// tool function(s) //
function _necessary() {
if ($$flag.launch_necessary) {
return true;
}
if (!$$bool($$flag.launch_necessary)) {
debugInfo("等待启动必要条件");
}
if ($$sel.get(_nec_sel_key)) {
debugInfo(["已满足启动必要条件:", _nec_sel_key]);
$$flag.launch_necessary = true;
return true;
}
$$flag.launch_necessary = false;
}
function _optional() {
if (!$$bool($$flag.launch_optional)) {
debugInfo("等待启动可选条件");
}
let _len = _opt_sel_keys.length;
for (let i = 0; i < _len; i += 1) {
let _key_sel = _opt_sel_keys[i];
if ($$sel.get(_key_sel)) {
debugInfo(["已满足启动可选条件", ">" + _key_sel]);
delete $$flag.launch_necessary;
delete $$flag.launch_optional;
return true;
}
}
$$flag.launch_optional = false;
}
},
disturbance: () => {
clickAction($$sel.pickup("打开"), "w");
$$app.page.disPermissionDiag();
},
screen_orientation: 0,
}, par || {}));
},
intent: function () {
let _i = $$app.intent.home;
if (app.checkActivity(_i)) {
return this._launcher(_i);
}
this._showActHint();
},
click_btn: function () {
let _this = this;
let _node_af_btn = null;
let _sel_af_btn = () => _node_af_btn = $$sel.get("af");
return _alipayHome() && _clickAFBtn();
// tool function(s) //
function _alipayHome() {
let _cA = $$app.page.alipay.home;
let _cB = () => waitForAction(_sel_af_btn, 1.5e3, 80);
return _cA() && _cB();
}
function _clickAFBtn() {
let _trigger = () => clickAction(_node_af_btn, "w");
return _this._launcher(_trigger);
}
},
search_kw: function () {
let _this = this;
let _node_search_aim = null;
return _alipayHome() && _search() && _launch();
// tool function(s) //
function _alipayHome() {
let _cA = $$app.page.alipay.home;
let _cB = () => {
let _kw_af_btn = idMatches(/.*home.+search.but.*/);
let _par = {click_strategy: "w"};
return waitForAndClickAction(_kw_af_btn, 1.5e3, 80, _par);
};
return _cA() && _cB();
}
function _search() {
let _text = "蚂蚁森林小程序";
let _kw_inp_box = idMatches(/.*search.input.box/);
let _kw_search_confirm = idMatches(/.*search.confirm/);
let _sel_inp_box = () => $$sel.pickup(_kw_inp_box);
let _sel_search_aim = () => _node_search_aim = $$sel.get("af");
if (!waitForAction(_sel_inp_box, 5e3, 80)) {
return;
}
setText(_text);
waitForAction(() => $$sel.pickup(_text), 3e3, 80);
return clickAction(_kw_search_confirm, "w", {
condition_success: _sel_search_aim,
max_check_times: 10,
check_time_once: 300,
});
}
function _launch() {
let _max = 8;
let _b = _node_search_aim.bounds();
while (_max--) {
if (_node_search_aim.clickable()) {
break;
}
_node_search_aim = _node_search_aim.parent();
}
let _cx = _b.centerX();
let _cy = _b.centerY();
let _click_o = _max < 0 ? [_cx, _cy] : _node_search_aim;
let _stg = _max < 0 ? "click" : "widget";
return _this._launcher(() => clickAction(_click_o, _stg));
}
},
},
rl: {
_launcher: function (trigger, par) {
return launchThisApp(trigger, Object.assign({}, {
task_name: "好友排行榜",
package_name: $$app.pkg_name,
no_message_flag: true,
condition_launch: () => true,
condition_ready: () => {
let _rl = $$app.page.rl;
let _inPage = () => _rl.isInPage();
let _loading = () => $$sel.pickup(/加载中.*/);
let _cA = () => !_loading();
let _cB = () => !waitForAction(_loading, 360, 120);
let _listLoaded = () => _cA() && _cB();
return _inPage() && _listLoaded();
},
disturbance: () => {
clickAction($$sel.pickup(/再试一次|打开/), "w");
},
screen_orientation: 0,
}, par || {}));
},
intent: function () {
let _i = $$app.intent.rl;
if (app.checkActivity(_i)) {
return this._launcher(_i);
}
this._showActHint();
},
click_btn: function () {
let _node_rl_ent = null;
let _sel_rl_ent = () => _node_rl_ent = $$sel.get("rl_ent");
return _locateBtn() && _launch();