-
Notifications
You must be signed in to change notification settings - Fork 554
/
ant-forest-launcher.js
6980 lines (6298 loc) · 340 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 Nov 1, 2021
* @version 2.2.2
* @author SuperMonster003
* @see https://github.com/SuperMonster003/Ant-Forest
*/
let {
$$und, $$obj, $$arr, $$cvt, $$bool, $$func,
$$num, $$impeded, $$str, $$link,
} = require('./modules/mod-global');
let { uix } = require('./modules/ext-ui');
let { appx } = require('./modules/ext-app');
let { db } = require('./modules/mod-database');
let { afrst } = require('./modules/mod-ant-forest');
let { alipay } = require('./modules/mod-alipay');
let { filesx } = require('./modules/ext-files');
let { cryptox } = require('./modules/ext-crypto');
let { imagesx } = require('./modules/ext-images');
let { eventsx } = require('./modules/ext-events');
let { project } = require('./modules/mod-project');
let { dialogsx } = require('./modules/ext-dialogs');
let { enginesx } = require('./modules/ext-engines');
let { consolex } = require('./modules/ext-console');
let { pluginsx } = require('./modules/ext-plugins');
let { storagesx } = require('./modules/ext-storages');
let { a11yx, $$sel } = require('./modules/ext-a11y');
let { devicex, $$disp } = require('./modules/ext-device');
let $$init = {
check() {
requiresApi(util.versionCodes.N.apiLevel);
requiresAutojsVersion('6.1.1');
App.ALIPAY.ensureInstalled();
a11yx.ensureSvcAndFunc();
devicex.checkScreenOffTimeout();
return $$init;
},
global() {
setGlobalObjects();
setGlobalFlags();
setGlobalLog();
consolex.__();
consolex._(`开发者测试日志已启用`, 0, 0, -2);
consolex._(`设备型号: ${device.brand} ${device.product}`);
$$disp.debug();
appSetter().setTask().setBlist().setPages().setLayout().setIntent();
accSetter().setParams().setMain();
consolex._(`Auto.js版本: ${autojs.versionName}`);
consolex._(`项目版本: ${project.getLocalVerName()}`);
consolex._(`安卓SDK版本: ${device.sdkInt}`);
consolex._(`安卓系统版本: ${device.release}`);
consolex._(`Root权限: ${$$app.hasRootAccess ? '已获取' : '未获取'}`);
return $$init;
// tool function(s) //
function setGlobalObjects() {
global.$$flag = {
autojsHasRoot: appx.hasRoot(),
autojsHasSecure: appx.hasSecure(),
};
global.$$cfg = Object.assign({},
storagesx['@default'].af,
storagesx.af_cfg.get('config'));
global.$$db = db.create('af', { alterType: 'union' });
global.$$app = {
developer: String.unTap(`434535154232343343441542${'\x33'.padStart(6, '0')}`),
rankListTitle: String.unEsc('2615FE0F0020597D53CB6392884C699C'),
taskName: String.unEsc('8682868168EE6797').surround('"'),
isInitScreenOn: devicex.isInitScreenOn,
initForegroundPackageName: currentPackage(),
enginesExecArgv: enginesx.my_engine_exec_argv,
cwd: enginesx.cwd,
cwp: enginesx.cwp,
hasRootAccess: $$flag.autojsHasRoot,
rootAccessPrivileges: $$cfg.rootAccessPrivileges,
friendDropBy: {
_pool: [],
_max: 5,
ic(name) {
let _ctr = this._pool[name] || 0;
if (_ctr === this._max) {
consolex._('发送排行榜复查停止信号');
consolex._('已达连续好友访问最大阈值');
$$flag.isRankListReviewStopped = 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 tsSeconds() {
return Date.now() / 1e3 >> 0;
},
exit() {
try {
this.layout.closeAll();
floaty.closeAll(); // just in case
if (this.queue.getExclusiveAllTasksLength() > 1) {
consolex._('移除当前脚本广播监听器');
events.broadcast.removeAllListeners();
consolex._('发送初始屏幕开关状态广播');
events.broadcast.emit('init_scr_on_state_change', this.isInitScreenOn);
}
} catch (e) {
console.error(e + '\n' + e.stack);
} finally {
consolex.$((this.taskName || '"Unknown"') + '任务结束', 1, 0, 0, '2n');
// exit() might cause ScriptInterruptedException
// as $$app.exit might be 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);
$$db.close();
$$flag.glob_e_scr_privilege = true;
},
};
$$sel.add('af', [ '蚂蚁森林', { currentApp: 'alipay' } ])
.add('alipay_home', [ /首页|Homepage/, { boundsInside: [ 0, cY(0.7), W, H ], currentApp: 'alipay' } ])
.add('af_title', [ /蚂蚁森林|Ant Forest/, { boundsInside: [ 0, 0, cX(0.4), cY(0.2) ], currentApp: 'alipay' } ])
// .add('af_home', [/合种|背包|通知|攻略|任务|.*大树养成.*/, {currentApp: 'alipay'}])
.add('af_home', [ /^(共被你收[\u4e00-\u9fff]?\d+g|\d+g被好友收[\u4e00-\u9fff]?|收[\u4e00-\u9fff]?好友\d+g|今日最慷慨|森林新消息)$/, { currentApp: 'alipay' } ])
.add('rl_ent', [ /查看更多好友|View more friends/, { currentApp: 'alipay' } ])
.add('rankListTitle', [ $$app.rankListTitle, { currentApp: 'alipay' } ])
.add('list', [ className('ListView'), { currentApp: 'alipay' } ])
.add('fri_tt', [ /.+的蚂蚁森林/, { boundsInside: [ 0, 0, cX(0.95), cY(0.2) ], currentApp: 'alipay' } ])
.add('shield_used', [ /.*使用了.*保护罩.*/, { currentApp: 'alipay' } ])
.add('wait_awhile', [ /.*稍等片刻.*/, { currentApp: 'alipay' } ])
.add('reload_frst_page', [ '重新加载', { currentApp: 'alipay' } ])
.add('close_btn', [ /关闭|Close/, { currentApp: 'alipay' } ])
.add('login_btn', [ /登录|Log in|.*loginButton/, { currentApp: 'alipay' } ])
.add('login_new_acc', [ /换个新账号登录|[Aa]dd [Aa]ccount/, { currentApp: 'alipay' } ])
.add('login_other_acc', [ /换个账号登录|.*switchAccount/, { currentApp: 'alipay' } ])
.add('login_other_mthd_init_pg', [ /其他登录方式|Other accounts/, { currentApp: 'alipay' } ])
.add('login_other_mthd', [ /换个方式登录|.*[Ss]w.+[Ll]og.+thod/, { currentApp: 'alipay' } ])
.add('login_by_code', [ /密码登录|Log ?in with password/, { currentApp: 'alipay' } ])
.add('login_next_step', [ /下一步|Next|.*nextButton/, { currentApp: 'alipay' } ])
.add('input_username', {
className: 'EditText',
filter: w => /(会员|用户)名|手机|邮箱/.test(w.content()),
currentApp: 'alipay',
})
.add('input_password', () => {
if (pickup(/.*(忘记密码|输入.*密码).*/)) {
let wc = pickup({ className: 'EditText', currentApp: 'alipay' }, 'w[]');
return wc.length ? wc[wc.length - 1] : null;
}
return null;
})
.add('switch_to_other_acc', {
idMatches: /.+_item_account/,
currentApp: 'alipay',
})
.add('login_err_ensure', idEndsWith('ensure'))
.add('login_err_msg', () => {
return pickup([ id('com.alipay.mobile.antui:id/message'), { currentApp: 'alipay' } ], 'txt')
|| pickup([ $$sel.get('login_err_ensure'), { currentApp: 'alipay' } ], 'p2c0>0>0', 'txt');
})
.add('acc_logged_out', [ new RegExp('.*('
+ /在其他设备登录|logged +in +on +another/.source + '|'
+ /.*账号于.*通过.*登录.*|account +logged +on +to/.source + ').*'), {
currentApp: 'alipay',
} ]);
}
function setGlobalFlags() {
let _dbg_info_sw = $$cfg.debugInfoSwitch;
let _msg_sw = $$cfg.messageShowingSwitch;
let _console_msg_sw = _msg_sw && $$cfg.consoleLogSwitch;
$$flag.show_debug_info = _dbg_info_sw && _console_msg_sw;
$$flag.show_energy_result = _msg_sw && $$cfg.resultShowingSwitch;
$$flag.show_floaty_result = $$cfg.floatyResultSwitch;
_console_msg_sw ? consolex.print.enable() : consolex.print.disable();
let _e_argv = $$app.enginesExecArgv;
if (Object.size(_e_argv, { exclude: 'intent' }) > 0) {
if (!$$und(_e_argv.isDebug)) {
$$flag.show_debug_info = Boolean(_e_argv.isDebug);
}
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.autojsGlobalLogSwitch && consolex.setGlobalLogConfig({
file: $$cfg.autojsGlobalLogConfigPath + 'auto.js-log.log',
filePattern: $$cfg.autojsGlobalLogConfigFilePattern,
maxBackupSize: $$cfg.autojsGlobalLogConfigMaxBackupSize,
maxFileSize: $$cfg.autojsGlobalLogConfigMaxFileSize << 10,
});
consolex.debug.switchSet($$flag.show_debug_info);
}
function appSetter() {
return {
setTask() {
/**
* @param {number} du_minute
* @param {{isToast?: boolean, isAsync?: 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.isAsync === undefined || _opt.isAsync === true;
let _is_toast = _opt.isToast === undefined || _opt.isToast === true;
let _task_s = this.taskName + '任务';
let _toast_lv = _is_toast ? 2 : 0;
let _msg = s => consolex.d([ '推迟' + _task_s, s ], _toast_lv, 0, 2);
let _ts = this.ts + du_minute * 60e3;
let _suff = storagesx.af.get('fg_blist_ctr') ? '_auto' : '';
if (Number(du_minute) === -1) {
//// -=-= PENDING =-=- ////
_msg('任务触发条件: 息屏时');
pluginsx.af.on_screen_off_launcher.deploy({
callback(task) {
$$app.setStoAutoTask({
task: task,
next_ts: -1,
next_type: 'on_screen_off',
}, () => $$app.exit());
},
});
} else {
_msg('推迟时长: ' + du_minute + '分钟');
tasks.addDisposableTask({
path: $$app.cwp,
date: _ts,
isAsync: _is_async,
callback(task) {
$$app.setStoAutoTask({
task: task,
next_ts: _ts,
next_type: 'postponed' + _suff,
}, () => $$app.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'|'on_screen_off'
* } 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_task = this.getStoAutoTask();
let _sto_id = _sto_task.task_id;
if (_sto_id > 0 && _sto_id !== task.task_id) {
consolex._([ '移除旧的自动定时任务', '任务ID: ' + _sto_id ]);
if (_sto_task.timestamp < 0) {
tasks.removeIntentTask(_sto_id, { isAsync: true });
} else {
tasks.removeTimedTask(_sto_id, { isAsync: 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 ? Numberx.padStart(_h, 2) + '时' : '';
let _m = _du_date.getMinutes();
let _m_str = _h || _m ? Numberx.padStart(_m, 2) + '分' : '';
let _s = _du_date.getSeconds();
let _s_str = (_h || _m ? Numberx.padStart(_s, 2) : _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({
shield: '好友使用能量保护罩',
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: {
shield: 'shield',
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.shield) {
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 pickup([ '返回', { clickable: true } ], 'c0')
|| pickup([ '返回', { clickable: true } ]);
};
let _id = () => {
return 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 pickup([ /关闭|Close/, { clickable: true } ], 'c0')
|| pickup([ /关闭|Close/, { clickable: 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({
taskName: $$app.taskName,
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_rotation_landscape) {
if ($$flag.show_energy_result && $$flag.show_floaty_result) {
consolex.$([
'当前设备屏幕为水平显示方向',
'悬浮窗结果展示方式已被禁用',
], 3, 0, 0, -2);
$$flag.show_floaty_result = false;
}
consolex._('重新获取当前设备屏幕显示信息');
$$disp.refresh();
}
return $$disp.is_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 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(pickup([ '蚂蚁森林', {
filter: (w) => {
/** @type {UiObject$} */
let p = w.compass('p3');
return p !== null && pickup(w, { filter: w => /官方/.test(w.content()) }, '?');
},
} ]), 'w'), shared_opt);
}
},
},
rl: {
_launcher(trigger, shared_opt) {
return appx.launch(trigger, Object.assign({
taskName: '好友排行榜',
package_name: alipay.package_name,
screen_orientation: android.view.Surface.ROTATION_0,
condition_launch: () => true,
condition_ready() {
let _loading = () => pickup(/加载中.*/);
let _cA = () => !_loading();
let _cB = () => !a11yx.wait(_loading, 360, 120);
let _listLoaded = () => _cA() && _cB();
return $$app.page.rl.isInPage() && _listLoaded();
},
disturbance() {
a11yx.click(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('rankListTitle')) {
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 => pickup([ rex, {
className: 'TextView',
boundsInside: [ 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 pickup(idMatches(/.*action_(log|search)/));
},
get is_fg() {
return pickup([ 'Navigate up', { className: 'ImageButton' } ])
|| this.is_home || this.is_log || this.is_settings
|| pickup(idMatches(/.*md_\w+/));
},
spring_board: {
on: () => $$cfg.appLaunchSpringboard === 'ON',
employ() {
if (!this.on()) {
return false;
}
consolex._('开始部署启动跳板');
let _aj_name = autojs.name;
let _res = appx.launch(context.getPackageName(), {
app_name: _aj_name,
isDebug: 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._(`等待返回${autojs.name}应用页面超时`);
// 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(alipay.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.close(alipay.package_name, {
shell_acceptable: $$app.hasRootAccess && $$app.rootAccessPrivileges.forceStopApp,
})) {
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 = () => recorder.isGreaterThan('close_af_win', 10e3);
let _cond = () => {
return $$sel.get('af_title')
|| $$sel.get('rankListTitle')
|| pickup([ /浇水|发消息/, { className: 'Button' } ])
|| $$sel.get('login_new_acc');
};
consolex._('关闭全部蚂蚁森林相关页面');
recorder.save('close_af_win');
while (_cond() && !_tOut()) {
devicex.keycode(4);
sleep(700);
}
let _succ = [ '相关页面关闭完毕', '保留当前支付宝页面' ];
consolex._(_tOut() ? '页面关闭可能未成功' : _succ);
},
isInPage() {
return alipay.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 springboard
$$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()) {