forked from SuperMonster003/Ant-Forest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAnt_Forest_Launcher.js
6451 lines (5525 loc) · 323 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
/**
* @overview alipay ant forest energy intelligent collection script
*
* @last_modified Jan 2, 2020
* @version 1.9.11
* @author SuperMonster003
*
* @tutorial {@link https://github.com/SuperMonster003/Auto.js_Projects/tree/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();
checkAccessibility();
checkModulesMap();
checkSdkAndAJVer();
// `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 checkAccessibility() {
let [line, msg] = [showSplitLineRaw, messageActionRaw];
let _max = 3;
while (!swipe(10000, 0, 10000, 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("无障碍服务方法无法使用");
exit();
}
}
function checkModulesMap() {
let _map = [
"MODULE_MONSTER_FUNC", "MODULE_DEFAULT_CONFIG",
"MODULE_PWMAP", "MODULE_UNLOCK", "MODULE_STORAGE",
"EXT_DIALOGS", "EXT_TIMERS", "EXT_DEVICE",
"EXT_APP", "EXT_IMAGES",
];
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("模块缺失或路径错误");
exit();
}
}
function checkSdkAndAJVer() {
// do not `require()` before `checkModulesMap()`
let _mod = require("./Modules/MODULE_MONSTER_FUNC");
return _mod.checkSdkAndAJVer();
}
// raw function(s) //
function messageActionRaw(msg, msg_level, toast_flag) {
let _msg = msg || " ";
if (msg_level && msg_level.toString().match(/^t(itle)?$/)) {
return messageActionRaw("[ " + msg + " ]", 1, toast_flag);
}
let _msg_level = +msg_level;
toast_flag && toast(_msg);
if (_msg_level === 0) return console.verbose(_msg) || true;
if (_msg_level === 1) return console.log(_msg) || true;
if (_msg_level === 2) return console.info(_msg) || true;
if (_msg_level === 3) return console.warn(_msg) || false;
if (_msg_level >= 4) {
console.error(_msg);
_msg_level >= 8 && exit();
}
}
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`
getDisplayParams({global_assign: true});
// waitFor: script will continue running rather than stop
// when accessibility service switched on by user
$$func(auto.waitFor) ? auto.waitFor() : auto();
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");
$$sel = getSelector();
let _default_af = require("./Modules/MODULE_DEFAULT_CONFIG").af || {};
Object.assign($$cfg, _default_af, $$sto.af_cfg.get("config", {}));
$$flag.msg_details = $$cfg.console_log_details || $$cfg.debug_info_switch;
$$flag.debug_info_avail = $$cfg.debug_info_switch && $$cfg.message_showing_switch;
$$flag.no_msg_act_flag = !$$cfg.message_showing_switch;
appSetter().setEngine().setTask().setParams().setBlist().setTools().init();
accSetter().setParams().setMain();
debugInfo("开发者测试日志已启用", "both_dash_Up");
debugInfo("Auto.js版本: " + $$app.autojs_ver);
debugInfo("项目版本: " + $$app.project_ver);
debugInfo("安卓系统SDK版本: " + $$app.sdk_ver);
return $$init;
// tool function(s) //
function setGlobalFunctions() {
// any better ideas ?
let {
getDisplayParams, classof, setIntervalBySetTimeout, keycode,
equalObjects, getSelector, waitForAndClickAction, runJsFile,
debugInfo, killThisApp, vibrateDevice, clickActionsPipeline,
clickAction, phoneCallingState, swipeAndShow, showSplitLine,
waitForAction, baiduOcr, launchThisApp, observeToastMessage,
messageAction, timeRecorder, surroundWith,
} = require("./Modules/MODULE_MONSTER_FUNC");
Object.assign(global, {
baiduOcr: baiduOcr,
classof: classof,
clickAction: clickAction,
clickActionsPipeline: clickActionsPipeline,
debugInfo: debugInfo,
equalObjects: equalObjects,
getDisplayParams: getDisplayParams,
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].indexOf(lv);
},
observeToastMessage: observeToastMessage,
phoneCallingState: phoneCallingState,
runJsFile: runJsFile,
setIntervalBySetTimeout: setIntervalBySetTimeout,
showSplitLine: showSplitLine,
surroundWith: surroundWith,
swipeAndShow: swipeAndShow,
timeRecorder: timeRecorder,
vibrateDevice: vibrateDevice,
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();
}
function setGlobalDollarVars() {
// do not `$$a = $$b = $$c = {};`
// they shouldn't be assigned
// the same address pointer
$$sel = $$sel || {};
$$app = $$app || {};
$$cfg = $$cfg || {};
$$sto = $$sto || {};
$$dev = $$dev || {};
$$flag = $$flag || {};
$$acc = $$acc || {};
}
function appSetter() {
let _setter = {
setEngine: function () {
let _my_engine = engines.myEngine();
let _my_engine_argv = _my_engine.execArgv || {};
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()},
});
void Object.assign($$app, {
my_engine: _my_engine,
my_engine_id: _my_engine.id,
my_engine_argv: _my_engine_argv,
cwd: _my_engine.cwd(), // `files.cwd()` also fine
init_scr_on: _my_engine_argv.init_scr_on || $$dev.is_screen_on,
init_fg_pkg: _my_engine_argv.init_fg_pkg || currentPackage(),
cwp: _getCwp(_my_engine),
exit: function () {
let _s = $$app.task_name + "任务结束";
messageAction(_s, 1, 0, 0, "both_n");
return ui.post(exit);
},
});
return _setter;
},
setTask: function () {
Object.defineProperties($$app, {
setPostponedTask: {
value: function (duration, toast_flag) {
$$flag.task_deploying || threads.starts(function () {
$$flag.task_deploying = true;
let _task_str = surroundWith($$app.task_name) + "任务";
let _du_str = duration + "分钟";
toast_flag === false || toast(_task_str + "推迟 " + _du_str);
messageAction("推迟" + _task_str, 1, 0, 0, -1);
messageAction("推迟时长: " + _du_str, 1, 0, 0, 1);
let _ts = $$app.ts + duration * 60000;
let _task = timers.addDisposableTask({path: $$app.cwp, date: _ts});
let _type_suffix = $$sto.af.get("fg_blist_ctr") ? "_auto" : "";
$$sto.af.put("next_auto_task", {
task_id: _task.id,
timestamp: _ts,
type: "postponed" + _type_suffix,
});
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*$/,
});
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",
},
}),
// data: encURIPar("alipays://platformapi/startapp", {
// appId: 60000002,
// startMultApp: "YES",
// ...
// }),
},
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",
className: "com.alipay.mobile" +
".security.accountmanager" +
".ui.AccountManagerActivity_",
packageName: $$app.pkg_name,
},
acc_login: {
action: "VIEW",
className: "com.alipay.mobile.security.login" +
".ui.RecommandAlipayUserLoginActivity",
packageName: "com.eg.android.AlipayGphone",
},
},
fri_drop_by: {},
});
void Object.defineProperties($$app.fri_drop_by, {
_pool: {value: []},
_max: {value: 5},
ic: {
get: () => function (name) {
let _ctr = this._pool[name] || 0;
if (_ctr === this._max) {
debugInfo("发送排行榜复查停止信号");
debugInfo(">已达连续好友访问最大阈值");
$$flag.rl_review_stop = true;
}
this._pool[name] = ++_ctr;
},
},
dc: {
get: () => 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/) // rank list entrance
.add("rl_end_idt", /.*没有更多.*/) // TODO to replace
.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 * 3600 * 1000;
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, nick) {
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 _nick = nick || $$af.nick;
let _black = $$app.blist.data[_nick];
let _rsn = _rsn_o[_black.reason];
let _str = _getExpiredStr(_black.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) {
let _res = name && this.data[name];
_res && this._showMsg("exists", name);
return _res || ref;
},
save: function () {
$$sto.af.put("blacklist", this.data);
return this;
},
add: function (data) {
let _nick;
if ($$obj(data)) {
_nick = Object.keys(data)[0];
Object.assign(this.data, data);
} else if ($$len(arguments, 3)) {
let _data = {};
let _args = arguments;
_nick = _args[0];
_data[_nick] = {
timestamp: _args[1],
reason: _args[2],
};
Object.assign(this.data, _data);
} else {
messageAction("黑名单添加方法参数不合法", 9, 1, 0, "both");
}
this._showMsg("add", _nick);
return this;
},
data: {},
init: function () {
let _blist_setter = this;
blistInitializer().get().clean().message().assign();
return _blist_setter;
// tool function(s) //
function blistInitializer() {
return {
get: function () {
// {%name%: {timestamp::, reason::}}
this.blist_data = $$sto.af.get("blacklist", {});
return this;
},
clean: function () {
this.deleted = [];
Object.keys(this.blist_data).forEach((name) => {
let _ts = this.blist_data[name].timestamp;
let _expired = (ts) => {
if (_blist_setter._expired.trigger(ts)) {
this.deleted.push(name);
return true;
}
};
if (!_ts || _expired(_ts)) {
delete this.blist_data[name];
}
});
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));
showSplitLine();
}
return this;
},
assign: function () {
_blist_setter.data = this.blist_data;
return this;
},
};
}
},
}.init().save();
$$app.cover_capt = {
pool: [],
_limit: 3,
get len() {
return this.pool.length;
},
get filled_up() {
return this.len >= this._limit;
},
add: function (capt) {
capt = capt || images.capt();
this.filled_up && this.reclaimLast();
let _img_name = images.getName(capt);
debugInfo("添加能量罩采集样本: " + _img_name);
this.pool.unshift(capt);
},
reclaimLast: function () {
let _last = this.pool.pop();
let _img_name = images.getName(_last);
debugInfo("能量罩采集样本已达阈值: " + this._limit);
debugInfo(">移除并回收最旧样本: " + _img_name);
images.reclaim(_last);
_last = null;
},
reclaimAll: function () {
if (!this.len) return;
debugInfo("回收全部能量罩采集样本");
this.pool.forEach(capt => {
let _img_name = images.getName(capt);
images.reclaim(capt);
debugInfo(">已回收: " + _img_name);
capt = null;
});
this.clear();
debugInfo("能量罩采集样本已清空");
},
clear: function () {
this.pool.splice(0, this.len);
},
detect: function () {
let [_l, _t] = [cX(288), cY(210, -1)];
let [_w, _h] = [cX(142), cY(44, -1)];
let _clip = (img) => {
return images.clip(img, _l, _t, _w, _h);
};
let _len = this.len;
let _pool = this.pool;
let _clo = $$cfg.protect_cover_ident_color;
let _thrd = $$cfg.protect_cover_ident_threshold;
let _par = {threshold: _thrd};
for (let i = 0; i < _len; i += 1) {
let _clp = _clip(_pool[i]);
if (images.findColor(_clp, _clo, _par)) {
return true;
}
}
},
};
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), cY(200, -1)];
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, cY(200, -1)];
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: () => {
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("等待启动可选条件");
}
for (let i = 0, len = _opt_sel_keys.length; 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();
},
}, 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, 1500, 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, 1500, 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, 5000, 80)) return;
setText(_text);
waitForAction(() => $$sel.pickup(_text), 3000, 80); // just in case
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");
},
}, 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();
// tool function(s) //
function _locateBtn() {
let _max = 8;
while (_max--) {
if (waitForAction(_sel_rl_ent, 1500)) return true;
if ($$sel.get("alipay_home")) {
debugInfo(["检测到支付宝主页页面", "尝试进入蚂蚁森林主页"]);
$$app.page.af.home();
} else if ($$sel.get("rl_title")) {
debugInfo(["检测到好友排行榜页面", "尝试关闭当前页面"]);
$$app.page.back();
} else {
debugInfo(["未知页面", "尝试关闭当前页面"]);
keycode(4, "double");
}
}
if (_max >= 0) {
debugInfo("定位到\"查看更多好友\"按钮");
return true;
}
messageAction("定位\"查看更多好友\"超时", 3, 1, 0, 1);
}
function _launch() {
let _trig = () => widgetClick() || swipeClick();
return this._launcher(_trig);
// tool function(s) //
function widgetClick() {
let _cA = () => clickAction(_node_rl_ent, "w");
let _cB = () => waitForAction(() => !_sel_rl_ent(), 800);
return _cA() && _cB();
}
function swipeClick() {
debugInfo("备份方案点击\"查看更多好友\"");
return swipeAndShow(_node_rl_ent, {
swipe_time: 200,
check_interval: 100,
if_click: "click",
});
}
}
},
},
_showActHint() {
// TODO ...
let _msg = "Activity在设备系统中不存在";
messageAction(_msg, 3, 0, 0, "both");
},
},
},
_getClickable: function (coord) {
let _sel = selector();
coord = coord.map((x, i) => !~x ? i % 2 ? W : H : x);
let _sel_b = _sel.boundsInside.apply(_sel, coord);
return _sel_b.clickable().findOnce();
},
_implement: function (fs, no_bak) {
for (let i = 0, len = fs.length; i < len; i += 1) {
let _checker = fs[i];
if ($$arr(_checker)) {
if (no_bak) continue;
_checker = () => this._getClickable(fs[i]);
}
let _node = _checker();
if (_node) return clickAction(_node, "w");
}
},
_plansLauncher: function (aim, plans_arr, shared_opt) {
let _aim = $$app.page._plans.launch[aim];
let _share = shared_opt || {};
for (let i = 0, len = plans_arr.length; i < len; i += 1) {
let _ele = plans_arr[i];
let _key = $$str(_ele) ? _ele : Object.keys(_ele)[0];
let _func = _aim[_key];
if (!$$func(_func)) {
messageAction("启动器计划方案无效", 4, 1, 0, -1);
messageAction("计划: " + aim, 4, 0, 1);
messageAction("方案: " + _key, 9, 0, 1, 1);
}
let _params = $$str(_ele) ? {} : _ele[_key];
Object.assign(_params, _share);
if (_func.bind(_aim)(_params)) return true;
}
},
autojs: {
_pickupTitle: (rex) => $$sel.pickup([rex, {
className: "TextView",
boundsInside: [cX(0.12), cY(0.03, -1), halfW, cY(0.12, -1)],
}]),
get is_log() {
return this._pickupTitle(/日志|Log/);
},
get is_settings() {
return this._pickupTitle(/设置|Settings?/);
},
get is_home() {
return $$sel.pickup(idMatches(/.*action_(log|search)/));
},
get is_fg() {
return $$sel.pickup(["Navigate up", {className: "ImageButton"}])
|| this.is_home || this.is_log || this.is_settings
|| $$sel.pickup(idMatches(/.*md_\w+/));
},
spring_board: {
on: () => $$cfg.app_launch_springboard === "ON",
employ: function () {
if (!this.on()) return false;
debugInfo("开始部署启动跳板");
let _aj_name = $$app.cur_autojs_name;
let _res = launchThisApp($$app.cur_autojs_pkg, {
app_name: _aj_name,
debug_info_flag: false,
no_message_flag: true,
first_time_run_message_flag: false,