forked from SuperMonster003/Ant-Forest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ant-forest-launcher.js
6915 lines (6237 loc) · 336 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
/**
* Alipay ant forest intelligent collection script launcher
* @since Oct 26, 2021
* @version 2.2.0
* @author SuperMonster003
* @see https://github.com/SuperMonster003/Ant-Forest
*/
let {
requirex, $$toast, $$und, $$obj, $$arr, $$cvt, $$bool,
$$func, $$num, $$sleep, $$impeded, $$str, $$link, isNullish,
} = require('./modules/ext-global');
let {uix} = require('./modules/ext-ui');
let {dbx} = require('./modules/ext-database');
let {appx} = require('./modules/ext-app');
let {filesx} = require('./modules/ext-files');
let {autojsx} = require('./modules/ext-autojs');
let {imagesx} = require('./modules/ext-images');
let {timersx} = require('./modules/ext-timers');
let {alipayx} = require('./modules/ext-alipay');
let {cryptox} = require('./modules/ext-crypto');
let {colorsx} = require('./modules/ext-colors');
let {eventsx} = require('./modules/ext-events');
let {dialogsx} = require('./modules/ext-dialogs');
let {threadsx} = require('./modules/ext-threads');
let {enginesx} = require('./modules/ext-engines');
let {consolex} = require('./modules/ext-console');
let {projectx} = require('./modules/ext-project');
let {storagesx} = require('./modules/ext-storages');
let {a11yx, $$sel} = require('./modules/ext-a11y');
let {devicex, $$disp} = require('./modules/ext-device');
let $$init = {
check() {
appx.checkAlipayPackage();
appx.checkSdkAndAJVer();
appx.checkScreenOffTimeout();
appx.checkAccessibility();
return $$init;
},
global() {
setGlobalObjects();
setGlobalFlags();
setGlobalLog();
consolex.__();
consolex._('开发者测试日志已启用', 0, 0, -2);
consolex._('设备型号: ' + device.brand + '\x20' + device.product);
$$disp.debug();
appSetter().setTask().setBlist().setPages().setLayout().setIntent();
accSetter().setParams().setMain();
consolex._('Auto.js版本: ' + $$app.autojs_ver_name);
consolex._('项目版本: ' + $$app.project_ver_name);
consolex._('安卓SDK版本: ' + device.sdkInt);
consolex._('安卓系统版本: ' + device.release);
consolex._('Root权限: ' + ($$app.has_root ? '已获取' : '未获取'));
return $$init;
// tool function(s) //
function setGlobalObjects() {
global.$$flag = {
autojs_has_root: appx.hasRoot(),
autojs_has_secure: appx.hasSecure(),
};
global.$$cfg = Object.assign({},
storagesx['@default'].af,
storagesx.af_cfg.get('config'));
global.$$db = dbx.create('af', {alter_type: 'union'});
global.$$app = {
developer: String.unTap('434535154232343343441542000003'),
rl_title: String.unEsc('2615FE0F0020597D53CB6392884C699C'),
task_name: String.unEsc('8682868168EE6797').surround('"'),
autojs_name: autojsx.getAppName(),
autojs_pkg: autojsx.getPkgName(),
autojs_ver_name: autojsx.getVerName(),
project_ver_name: projectx.getLocalVerName(),
init_scr_on: devicex.is_init_screen_on,
init_fg_pkg: currentPackage(),
engines_exec_argv: enginesx.my_engine_exec_argv,
cwd: enginesx.cwd,
cwp: enginesx.cwp,
has_root: $$flag.autojs_has_root,
root_fxs: $$cfg.root_access_functions,
fri_drop_by: {
_pool: [],
_max: 5,
ic(name) {
let _ctr = this._pool[name] || 0;
if (_ctr === this._max) {
consolex._('发送排行榜复查停止信号');
consolex._('已达连续好友访问最大阈值');
$$flag.rl_review_stop = true;
}
this._pool[name] = ++_ctr;
},
dc(name) {
let _ctr = this._pool[name] || 0;
this._pool[name] = _ctr > 1 ? --_ctr : 0;
},
},
get now() {
return new Date();
},
get ts() {
return Date.now();
},
get ts_sec() {
return Date.now() / 1e3 >> 0;
},
exit() {
try {
this.layout.closeAll();
floaty.closeAll(); // just in case
if (this.queue.excl_tasks_all_len > 1) {
consolex._('移除当前脚本广播监听器');
events.broadcast.removeAllListeners();
consolex._('发送初始屏幕开关状态广播');
events.broadcast.emit('init_scr_on_state_change', this.init_scr_on);
}
} catch (e) {
console.error(e + '\n' + e.stack);
} finally {
consolex.$((this.task_name || '"Unknown"') + '任务结束', 1, 0, 0, '2n');
// exit() might cause ScriptInterruptedException
// as $$app.exit might invoked within Promise
ui.post(exit);
}
},
/**
* @param {*} [status] - a truthy value indicates abnormal termination
*/
tidy(status) {
let _status = status ? 1 : 0;
this.monitor.insurance.finish(_status);
dialogsx.clearPool();
imagesx.clearPool();
$$db.close();
$$flag.glob_e_scr_privilege = true;
},
};
$$sel.add('af', '蚂蚁森林')
.add('alipay_home', [/首页|Homepage/, {bi$: [0, cY(0.7), W, H]}])
.add('af_title', [/蚂蚁森林|Ant Forest/, {bi$: [0, 0, cX(0.4), cY(0.2)]}])
.add('af_home', /合种|背包|通知|攻略|任务|.*大树养成.*/)
.add('energy_amt', /^\s*\d+(\.\d+)?(k?g|t)\s*$/)
.add('rl_title', $$app.rl_title)
.add('rl_ent', /查看更多好友|View more friends/)
.add('rl_end_idt', /.*没有更多.*/)
.add('list', className('ListView'))
.add('fri_tt', [/.+的蚂蚁森林/, {bi$: [0, 0, cX(0.95), cY(0.2)]}])
.add('cover_used', /.*使用了.*保护罩.*/)
.add('wait_awhile', /.*稍等片刻.*/)
.add('reload_frst_page', '重新加载')
.add('close_btn', /关闭|Close/)
.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('input_lbl_acc', /账号|Account/)
.add('input_lbl_code', /密码|Password/)
.add('input_username', {
className: 'EditText',
filter: w => /(会员|用户)名|手机|邮箱/.test($$sel.pickup(w, 'txt')),
})
.add('input_password', () => {
if ($$sel.pickup(/.*(忘记密码|输入.*密码).*/)) {
let wc = $$sel.pickup({className: 'EditText'}, 'wc');
return wc.length ? wc[wc.length - 1] : null;
}
return null;
})
.add('switch_to_other_acc', idMatches(/.+_item_account/))
.add('login_err_ensure', idMatches(/.*ensure/))
.add('login_err_msg', (type) => {
let _t = type || 'txt';
return $$sel.pickup(id('com.alipay.mobile.antui:id/message'), _t)
|| $$sel.pickup([$$sel.get('login_err_ensure'), 'p2c0>0>0'], _t);
})
.add('acc_logged_out', new RegExp('.*('
+ /在其他设备登录|logged +in +on +another/.source + '|'
+ /.*账号于.*通过.*登录.*|account +logged +on +to/.source + ').*'));
}
function setGlobalFlags() {
let _dbg_info_sw = $$cfg.debug_info_switch;
let _msg_sw = $$cfg.message_showing_switch;
let _console_msg_sw = _msg_sw && $$cfg.console_log_switch;
$$flag.show_debug_info = _dbg_info_sw && _console_msg_sw;
$$flag.show_energy_result = _msg_sw && $$cfg.result_showing_switch;
$$flag.show_floaty_result = $$cfg.floaty_result_switch;
_console_msg_sw ? consolex.print.enable() : consolex.print.disable();
let _e_argv = $$app.engines_exec_argv;
if (Object.size(_e_argv, {exclude: 'intent'}) > 0) {
if (!$$und(_e_argv.is_debug)) {
$$flag.show_debug_info = Boolean(_e_argv.is_debug);
}
if ($$und(_e_argv.is_instant_running)) {
_e_argv.is_instant_running = true;
}
if ($$und(_e_argv.no_insurance)) {
_e_argv.no_insurance = true;
}
}
}
function setGlobalLog() {
$$cfg.aj_global_log_switch && consolex.setGlobalLogConfig({
file: $$cfg.aj_global_log_cfg_path + 'auto.js-log.log',
filePattern: $$cfg.aj_global_log_cfg_file_pattern,
maxBackupSize: $$cfg.aj_global_log_cfg_max_backup_size,
maxFileSize: $$cfg.aj_global_log_cfg_max_file_size << 10,
});
consolex.debug.switchSet($$flag.show_debug_info);
}
function appSetter() {
return {
setTask() {
/**
* @param {number} du_minute
* @param {{is_toast?: boolean, is_async?: boolean}} [options]
*/
$$app.setPostponedTask = function (du_minute, options) {
if ($$flag.postponed_task_deploying) {
return;
}
$$flag.postponed_task_deploying = true;
let _opt = options || {};
let _is_async = _opt.is_async === undefined || _opt.is_async === true;
let _is_toast = _opt.is_toast === undefined || _opt.is_toast === true;
let _task_s = this.task_name + '任务';
let _du_str = du_minute + '分钟';
_is_toast && toast(_task_s + '推迟 ' + _du_str);
consolex.$(['推迟' + _task_s, '推迟时长: ' + _du_str], 1, 0, 0, 2);
let _this = this;
let _ts = this.ts + du_minute * 60e3;
let _suff = storagesx.af.get('fg_blist_ctr') ? '_auto' : '';
timersx.addDisposableTask({
path: _this.cwp,
date: _ts,
is_async: _is_async,
callback: (task) => _this.setStoAutoTask({
task: task,
next_ts: _ts,
next_type: 'postponed' + _suff,
}, () => _this.exit()),
});
};
/**
* @param {Object} auto_task
* @param {org.autojs.autojs.timing.TimedTask} auto_task.task
* @param {number} auto_task.next_ts
* @param {NextAutoTaskType} auto_task.next_type
* @param {function(task:org.autojs.autojs.timing.TimedTask)} [callback]
* @return {org.autojs.autojs.timing.TimedTask}
*/
$$app.setStoAutoTask = function (auto_task, callback) {
/**
* @typedef {
* 'uninterrupted'|'min_countdown'|'postponed'|'postponed_auto'
* } NextAutoTaskType
* @typedef {{
* task_id?: number,
* timestamp?: number,
* type?: NextAutoTaskType,
* }} NextAutoTaskInfo
*/
let _info = {
task_id: auto_task.task.id,
timestamp: auto_task.next_ts,
type: auto_task.next_type,
};
this.removeStoAutoTaskIFN(_info);
storagesx.af_auto.put('next_auto_task', _info);
if (typeof callback === 'function') {
callback(auto_task.task);
}
return auto_task.task;
};
/**
* @param {NextAutoTaskInfo} [def]
* @return {NextAutoTaskInfo}
*/
$$app.getStoAutoTask = function (def) {
return storagesx.af_auto.get('next_auto_task', def || {});
};
/**
* @param {NextAutoTaskInfo} task
* @return {boolean}
*/
$$app.removeStoAutoTaskIFN = function (task) {
let _sto_id = this.getStoAutoTask().task_id;
if (_sto_id > 0 && _sto_id !== task.task_id) {
consolex._(['移除旧的自动定时任务', '任务ID: ' + _sto_id]);
timersx.removeTimedTask(_sto_id, {is_async: true});
}
};
return this;
},
setBlist() {
$$app.blist = {
_expired: {
trigger(o) {
return o.timestamp < $$app.ts;
},
showMsg(o) {
let _du_ts = o.timestamp - $$app.ts;
let _0h_ts = Date.parse(new Date().toDateString());
let _du_date = new Date(_0h_ts + _du_ts);
let _d_unit = 24 * 3.6e6;
let _d = Math.trunc(_du_ts / _d_unit);
let _d_str = _d ? _d + '天' : '';
let _h = _du_date.getHours();
let _h_str = _h ? _h.padStart(2, 0) + '时' : '';
let _m = _du_date.getMinutes();
let _m_str = _h || _m ? _m.padStart(2, 0) + '分' : '';
let _s = _du_date.getSeconds();
let _s_str = (_h || _m ? _s.padStart(2, 0) : _s) + '秒';
consolex.$(_d_str + _h_str + _m_str + _s_str + '后解除', 1, 0, 1);
},
},
_msg: {
/**
* @param {...string[]} messages
*/
_msg(messages) {
[].slice.call(arguments).forEach((m) => {
consolex.$(m, 1, 0, 1);
});
},
get parent() {
return $$app.blist;
},
add(o) {
this._msg('已加入黑名单');
this.reason(o);
this.expired(o);
},
exists(o) {
this._msg('黑名单好友', '已跳过收取');
this.reason(o);
this.expired(o);
},
reason(o) {
this._msg({
protect_cover: '好友使用能量保护罩',
by_user: '用户自行设置',
}[o.reason]);
},
expired(o) {
if (Number.isFinite(o.timestamp)) {
this.parent._expired.showMsg(o);
}
},
},
_save() {
storagesx.af_blist.put('blacklist', this._data, {is_forcible: true});
},
reason: {
cover: 'protect_cover',
user: 'by_user',
},
contains(name) {
return this._data.some((o) => {
if (name.trim() === o.name.trim()) {
this._msg.exists(o);
return true;
}
});
},
add(name, ts, reason) {
let _member = arguments.length === 3
? {name: name, timestamp: ts, reason: reason}
: name;
for (let i = 0; i < this._data.length; i += 1) {
if (this._data[i].name === _member.name) {
if (this._data[i].reason === this.reason.cover) {
this._data.splice(i--, 1);
}
}
}
this._data.push(_member);
this._msg.add(_member);
this._save();
},
$legacyCompatible(data) {
let _old = storagesx.af.get('blacklist');
if (!$$und(_old)) {
// legacy: {name: {timestamp::, reason::}}
// modern: [{name::, reason::, timestamp::}]
if ($$obj(_old)) {
consolex._('转换传统黑名单数据格式');
_old = Object.keys(_old).map((n) => (
Object.assign({name: n}, _old[n])
));
}
if ($$arr(_old)) {
consolex._('转移并合并传统黑名单存储数据');
_old.forEach(o => data.push(o));
}
storagesx.af.remove('blacklist');
}
},
$removeExpired(data) {
for (let i = 0; i < data.length; i += 1) {
let _o = data[i];
if (!$$obj(_o) || !_o.name) {
data.splice(i--, 1);
} else if (!_o.timestamp || this._expired.trigger(_o)) {
consolex._('移除黑名单');
consolex._(_o.name);
consolex._($$cvt.date(_o.timestamp));
data.splice(i--, 1);
}
}
},
$init() {
this._data = storagesx.af_blist.get('blacklist', []);
this.$legacyCompatible(this._data);
this.$removeExpired(this._data);
this._save();
delete this.$legacyCompatible;
delete this.$removeExpired;
delete this.$init;
},
};
$$app.blist.$init();
return this;
},
setPages() {
$$app.page = {
_plans: {
back: (function $iiFe() {
let _text = () => {
return $$sel.pickup(['返回', {c$: true}, 'c0'])
|| $$sel.pickup(['返回', {c$: true}]);
};
let _id = () => {
return $$sel.pickup(idMatches(/.*h5.+nav.back|.*back.button/));
};
let _bak = [0, 0, cX(100), cYx(200)]; // backup plan
return [_text, _id, _bak];
})(),
close: (function $iiFe() {
let _text = () => {
return $$sel.pickup([/关闭|Close/, {c$: true}, 'c0'])
|| $$sel.pickup([/关闭|Close/, {c$: true}]);
};
let _id = () => null; // so far
let _bak = [cX(0.8), 0, -1, cYx(200)]; // backup plan
return [_text, _id, _bak];
})(),
launch: {
af: {
_launcher(trigger, shared_opt) {
$$app.monitor.launch_confirm.start();
$$app.monitor.permission_allow.start(0);
let _res = appx.launch(trigger, Object.assign({
task_name: $$app.task_name,
package_name: 'alipay',
screen_orientation: 0,
condition_launch() {
return $$app.page.af.isInPage();
},
condition_ready() {
let _nec_sel_key = 'af_title';
let _opt_sel_keys = ['af_home', 'rl_ent'];
if (_necessary() && _orientation() && _optional()) {
delete $$flag.launch_necessary;
delete $$flag.launch_optional;
return true;
}
// tool function(s) //
function _necessary() {
if ($$flag.launch_necessary) {
return true;
}
if (!$$bool($$flag.launch_necessary)) {
consolex._('等待启动必要条件');
}
if ($$sel.get(_nec_sel_key)) {
consolex._(['已满足启动必要条件:', _nec_sel_key]);
return $$flag.launch_necessary = true;
}
return $$flag.launch_necessary = false;
}
function _orientation() {
if ($$disp.is_display_rotation_landscape) {
if ($$flag.show_energy_result) {
consolex.$([
'当前设备屏幕为水平显示方向',
'悬浮窗结果展示方式已被禁用',
], 3, 0, 0, -2);
$$flag.show_floaty_result = false;
}
consolex._('重新获取当前设备屏幕显示信息');
$$disp.refresh();
}
return $$disp.is_display_rotation_portrait;
}
function _optional() {
if (!$$bool($$flag.launch_optional)) {
consolex._('等待启动可选条件');
}
return _opt_sel_keys.some((key) => {
if ($$sel.get(key)) {
consolex._(['已满足启动可选条件:', key]);
return true;
}
}) || ($$flag.launch_optional = false);
}
},
}, shared_opt || {}));
$$app.monitor.launch_confirm.interrupt();
$$app.monitor.permission_allow.interrupt();
return _res;
},
intent(shared_opt) {
return appx.checkActivity($$app.intent.home)
? this._launcher($$app.intent.home, shared_opt)
: this._showActHint();
},
click_btn(shared_opt) {
return $$app.page.alipay.home()
&& a11yx.wait(() => $$sel.get('af'), 1.5e3, 80, {
then: w => this._launcher(() => a11yx.click(w, 'w'), shared_opt),
});
},
search_kw(shared_opt) {
let _this = this;
let _w_item = null;
return _alipayHome() && _search() && _launch();
// tool function(s) //
function _alipayHome() {
return $$app.page.alipay.home()
&& a11yx.waitAndClick(() => {
return $$sel.pickup([idMatches(/.*InputBoxContainer/), 'c0']);
}, 1.5e3, 80, {cs$: 'w'});
}
function _search() {
if (a11yx.wait(idMatches(/.*search.input.box/), 5e3, 80)) {
let _text = '蚂蚁森林小程序';
setText(_text);
a11yx.wait(_text, 2e3, 80);
return a11yx.click(idMatches(/.*search.confirm/), 'w', {
condition: () => _w_item = $$sel.get('af'),
max_check_times: 8,
check_time_once: 2.4e3,
});
}
}
function _launch() {
return _this._launcher(() => a11yx.click($$sel.pickup(['蚂蚁森林', {
filter: (w) => {
return !!$$sel.traverse([w, 'p3'], (o) => {
return /官方/.test($$sel.pickup(o, 'txt'));
});
},
}]), 'w'), shared_opt);
}
},
},
rl: {
_launcher(trigger, shared_opt) {
return appx.launch(trigger, Object.assign({
task_name: '好友排行榜',
package_name: alipayx.package_name,
screen_orientation: android.view.Surface.ROTATION_0,
condition_launch: () => true,
condition_ready() {
let _loading = () => $$sel.pickup(/加载中.*/);
let _cA = () => !_loading();
let _cB = () => !a11yx.wait(_loading, 360, 120);
let _listLoaded = () => _cA() && _cB();
return $$app.page.rl.isInPage() && _listLoaded();
},
disturbance() {
a11yx.click($$sel.pickup(/再试一次|打开/), 'w');
},
}, shared_opt));
},
intent(shared_opt) {
return appx.checkActivity($$app.intent.rl)
? this._launcher($$app.intent.rl, shared_opt)
: this._showActHint();
},
click_btn(shared_opt) {
let _w_rl_ent = null;
let _sel_rl_ent = () => _w_rl_ent = $$sel.get('rl_ent');
return _locateBtn() && _launch();
// tool function(s) //
function _locateBtn() {
let _max = 8;
while (_max--) {
if (a11yx.wait(_sel_rl_ent, 1.5e3)) {
return true;
}
if ($$sel.get('alipay_home')) {
consolex._(['检测到支付宝主页页面', '尝试进入蚂蚁森林主页']);
$$app.page.af.launch();
} else if ($$sel.get('rl_title')) {
consolex._(['检测到好友排行榜页面', '尝试关闭当前页面']);
$$app.page.back();
} else {
consolex._(['未知页面', '尝试关闭当前页面']);
devicex.keycode(4, {rush: true});
}
}
if (_max >= 0) {
consolex._('定位到"查看更多好友"按钮');
return true;
}
consolex.$('定位"查看更多好友"超时', 3, 1, 0, 1);
}
function _launch() {
return this._launcher(function () {
return a11yx.click(_w_rl_ent, 'w')
&& a11yx.wait(() => !_sel_rl_ent(), 800);
}, shared_opt);
}
},
},
_showActHint() {
consolex.$('Activity在设备系统中不存在', 3, 0, 0, 2);
},
},
},
_getClickable(coord) {
let _sel = selector();
let _par = coord.map((x, i) => x !== -1 ? x : i % 2 ? W : H);
return _sel.boundsInside.apply(_sel, _par).clickable().findOnce();
},
_carry(fxs, no_bak) {
for (let i = 0, l = fxs.length; i < l; i += 1) {
let _checker = fxs[i];
if ($$arr(_checker)) {
if (no_bak) {
continue;
}
_checker = () => this._getClickable(fxs[i]);
}
let _w = _checker();
if (_w) {
return a11yx.click(_w, 'w');
}
}
},
_plansLauncher(aim, plans_arr, shared_opt) {
let _fxo = $$app.page._plans.launch[aim];
return plans_arr.some((stg) => {
let _f = _fxo[stg];
if (!$$func(_f)) {
consolex.$('启动器计划方案无效', 4, 1, 0, -1);
consolex.$('计划: ' + aim, 4, 0, 1);
consolex.$('方案: ' + stg, 8, 0, 1, 1);
}
if (_f.call(_fxo, shared_opt)) {
return true;
}
});
},
autojs: {
/** @param {RegExp} rex */
_pickupTitle: rex => $$sel.pickup([rex, {
cn$: 'TextView',
bi$: [cX(0.12), cYx(0.03), halfW, cYx(0.12)],
}]),
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', {cn$: 'ImageButton'}])
|| this.is_home || this.is_log || this.is_settings
|| $$sel.pickup(idMatches(/.*md_\w+/));
},
spring_board: {
on: () => $$cfg.app_launch_springboard === 'ON',
employ() {
if (!this.on()) {
return false;
}
consolex._('开始部署启动跳板');
let _aj_name = $$app.autojs_name;
let _res = appx.launch($$app.autojs_pkg, {
app_name: _aj_name,
is_debug: false,
condition_ready() {
return $$app.page.autojs.is_fg;
},
});
if (_res) {
consolex._('跳板启动成功');
return true;
}
consolex._('跳板启动失败', 3);
consolex._('打开' + _aj_name + '应用超时', 3);
},
remove() {
if (!this.on()) {
return;
}
if (!$$flag.alipay_closed) {
consolex._('跳过启动跳板移除操作');
consolex._('支付宝未关闭');
return;
}
if (a11yx.wait(_isFg, 9e3, 300)) {
return _checkInitState();
}
// language=JS
consolex._('`等待返回${$$app.autojs_name}应用页面超时`'.ts);
// tool function(s) //
function _isFg() {
return $$app.page.autojs.is_fg;
}
function _checkInitState() {
if (!$$app.init_autojs_state.init_fg) {
return _remove(_isFg, _back2);
}
if ($$app.init_autojs_state.init_home) {
consolex._('无需移除启动跳板');
return false;
}
if ($$app.init_autojs_state.init_log) {
return _restore('console');
}
if ($$app.init_autojs_state.init_settings) {
return _restore('settings');
}
return _remove(_isHome, _back2);
// tool function(s) //
function _back2() {
devicex.keycode(4, {rush: true});
sleep(400);
}
function _remove(condF, removeF) {
consolex._('移除启动跳板');
let _max = 5;
while (condF() && _max--) {
removeF();
}
if (_max > 0) {
consolex._('跳板移除成功');
return true;
}
consolex._('跳板移除可能未成功', 3);
}
function _restore(cmd) {
let _m = '恢复跳板 ' + cmd.toTitleCase() + ' 页面';
toast(_m);
consolex._(_m);
return appx.startActivity(cmd);
}
function _isHome() {
return $$app.page.autojs.is_home;
}
}
},
},
},
alipay: {
home(par) {
$$app.monitor.launch_confirm.start();
$$app.monitor.permission_allow.start(0);
let _res = appx.launch(alipayx.package_name, Object.assign({
app_name: '支付宝',
screen_orientation: 0,
condition_ready() {
$$app.page.close('no_bak') || $$app.page.back();
return $$app.page.alipay.isInPage();
},
}, par || {}));
$$app.monitor.launch_confirm.interrupt();
$$app.monitor.permission_allow.interrupt();
return _res;
},
close() {
consolex._('关闭支付宝');
if (appx.kill(alipayx.package_name, {
shell_acceptable: $$app.has_root && $$app.root_fxs.force_stop,
})) {
consolex._('支付宝关闭完毕');
return $$flag.alipay_closed = true;
}
consolex._('支付宝关闭超时', 3);
return false;
},
isInPage() {
return $$sel.get('alipay_home');
},
},
af: {
launch(shared_opt) {
$$app.page.autojs.spring_board.employ();
// TODO loadFromConfig
let _plans = ['intent', 'click_btn', 'search_kw'];
let _res = $$app.page._plansLauncher('af', _plans, shared_opt);
$$app.monitor.mask_layer.start();
if (a11yx.wait(() => $$flag.mask_layer_monitoring, 800, 50)) {
consolex._('检测到遮罩层监测器等待信号');
if (a11yx.wait(() => !$$flag.mask_layer_monitoring, 3e3, 50)) {
consolex._('放弃等待监测器结束信号', 3);
} else {
consolex._('监测器信号返回正常');
}
}
return _res;
},
close() {
let _tOut = () => timersx.rec.gt('close_af_win', 10e3);
let _cond = () => {
return $$sel.get('af_title')
|| $$sel.get('rl_title')
|| $$sel.pickup([/浇水|发消息/, {cn$: 'Button'}])
|| $$sel.get('login_new_acc');
};
consolex._('关闭全部蚂蚁森林相关页面');
timersx.rec.save('close_af_win');
while (_cond() && !_tOut()) {
devicex.keycode(4);
sleep(700);
}
let _succ = ['相关页面关闭完毕', '保留当前支付宝页面'];
consolex._(_tOut() ? '页面关闭可能未成功' : _succ);
},
isInPage() {
return alipayx.package_name === currentPackage()
|| $$sel.get('rl_ent')
|| $$sel.get('af_home')
|| $$sel.get('wait_awhile');
},
},
rl: {
/** load rl capt cache if needed */
get capt_img() {
if (this._capt && !imagesx.isRecycled(this._capt)) {
return this._capt;
}
return this.capt();
},
capt() {
return this._capt = imagesx.capt({clone: true});
},
reclaimAll() {
imagesx.reclaim(this._capt);
this.pool.clean();
},
pool: {
data: [],
add() {
this.data.unshift($$app.page.rl.capt());
return this;
},
filter() {
let _pool = this.data;
for (let i = 0; i < _pool.length; i += 1) {
if (!_pool[i] || imagesx.isRecycled(_pool[i])) {
_pool.splice(i--, 1);
}
}
return this;
},
trim(kept) {
let _pool = this.data;
let _idx = _pool.length;
while (_idx-- > kept) {
imagesx.reclaim(_pool[_idx]);
_pool.splice(_idx, 1);
}
return this;
},
clean() {
if (this.data.length) {
consolex._('清理排行榜截图样本池');
this.trim(0);
}
return this;
},
isDiff() {
let _pool = this.data;
if (_pool.length !== 2) {
return true;
}
let [_img, _tpl] = _pool;
return !imagesx.findImage(_img, _tpl, {
compress_level: 4,
});
},
},
launch(shared_opt) {
// TODO split from alipay spring board
$$app.page.autojs.spring_board.employ();
// TODO loadFromConfig
let _plans = ['intent', 'click_btn'];
return $$app.page._plansLauncher('rl', _plans, shared_opt);
},
backTo() {
let _isIn = () => $$flag.rl_in_page;
let _max = 3;
while (_max--) {
sleep(240);
devicex.keycode(4);
consolex._('模拟返回键返回排行榜页面');
if (a11yx.wait(_isIn, 2.4e3, 80)) {
sleep(240);
if (a11yx.wait(_isIn, 480, 80)) {
consolex._('返回排行榜成功');
return true;
}
if ($$app.page.fri.isInPage()) {
consolex._('当前页面为好友森林页面');
continue;
}
}
if ($$app.page.alipay.isInPage()) {
consolex._(['当前页面为支付宝首页', '重新跳转至排行榜页面']);
return this.launch();
}
consolex._('返回排行榜单次超时');
}
consolex._(['返回排行榜失败', '尝试重启支付宝到排行榜页面'], 3);
$$app.page.af.launch();
$$app.page.rl.launch();
$$app.monitor.rl_in_page.start();
},
isInPage() {
let _fg = $$flag.rl_in_page;
return $$und(_fg) ? $$sel.get('rl_title') : _fg;
},