-
Notifications
You must be signed in to change notification settings - Fork 198
/
Copy pathmain.js
2997 lines (2882 loc) · 120 KB
/
main.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
"ui";
//db操作
importClass(android.database.sqlite.SQLiteDatabase);
//运行日志
console.setGlobalLogConfig({ "file": "./运行日志.txt" });
var aCount = 12;//文章默认学习篇数
var vCount = 7;//小视频默认学习个数
var cCount = 2;//收藏+分享+评论次数
var aTime = 30;//每篇文章学习-30秒 30*12≈360秒=6分钟
var vTime = 60;//每个小视频学习60秒
var rTime = 360;//音视频时长-6分钟
var dyNum = 2;//订阅 2
var commentText = ["支持党,支持国家!", "为实现中华民族伟大复兴而不懈奋斗!", "不忘初心,牢记使命"];//评论内容,可自行修改,大于5个字便计分
var num = random(0, commentText.length - 1) ;//随机数
var aCat = ["推荐","要闻","综合"];
var aCatlog = aCat[num] ;//文章学习类别,随机取"推荐""要闻"、"新思想"
var aZX = 1;//文章执行1或2脚本
var date_string = getTodayDateString();//获取当天日期字符串
var vCat = ["第一频道", "学习视频", "联播频道"];
var vCatlog = vCat[num] ; //视频学习类别,随机取 "第一频道"、"学习视频"、"联播频道"
if (num == 0){
var s = "央视网";
}else if (num == 1){
var s = "央视新闻";
}else {
var s = "中央广播电视总台";
}
var lCount = 1;//挑战答题轮数
var qCount = random(5, 7);//挑战答题每轮答题数(5~7随机)
var zCount = 2;//争上游答题轮数
var zsyzd =1;//争上游和双人对战是否自动做,1,2 默认自动1
var oldaquestion;//争上游和对战答题循环,定义旧题目对比新题目用20201022
var myScores = {};//分数
//特殊题,特点:题目一样,答案不同
var ZiXingTi = "选择词语的正确词形。"; //字形题
var DuYinTi = "选择正确的读音。";//读音题 20201211
var ErShiSiShi ="下列不属于二十四史的是。";//二十四史
var customize_flag = false;//自定义运行标志
/*
<---------------UI部分开始--------------->
*/
alert("协议及说明", "免责声明:\n本程序只供个人学习Auto.js使用,不得盈利传播,不得用于违法用途,否则造成的一切后果自负!\n如果继续使用此应用即代表您同意此协议\n说明:此应用仅适用于Android7.0以上的版本。");
var color = "#009688";
var txt = files.read("./运行日志.txt");
var dbName = "tiku.db";//题库文件名
var path = files.path(dbName);
var db = SQLiteDatabase.openOrCreateDatabase(path, null);
var sql = "SELECT * FROM tikuNet;";
var cursor = db.rawQuery(sql, null);
if (cursor.moveToFirst()) {
var answer = cursor.getString(0);
cursor.close();
}
ui.layout(
<drawer id="drawer">
<vertical>
<appbar>
<toolbar id="toolbar" title="自动学习强国 v2.4.0正式版"/>
<tabs id="tabs"/>
</appbar>
<viewpager id="viewpager">
<frame>
<ScrollView>
<vertical>
<button text="先点我开启无障碍和悬浮窗,如果没有反应,说明已经开启" style="Widget.AppCompat.Button.Colored" id="click_me" w="*" />
<button id="stop" w="*" text="紧急停止所有任务" style="Widget.AppCompat.Button.Colored" />
<button style="Widget.AppCompat.Button.Colored" id="all" h="50" text="默认执行" />
<button id="customize" w="*" text="自定义执行" style="Widget.AppCompat.Button.Colored" />
<button text="-------以下为单个任务执行-------" style="Widget.AppCompat.Button.Borderless.Colored" w="*"/>
<button id="cq" w="*" text="挑战答题" style="Widget.AppCompat.Button.Colored" />
<button id="dq" w="*" text="每日答题" style="Widget.AppCompat.Button.Colored" />
<button id="sr" w="*" text="双人对战" style="Widget.AppCompat.Button.Colored" />
<button id="zsy" w="*" text="争上游答题" style="Widget.AppCompat.Button.Colored" />
<button id="dwzdate" w="*" text="选读文章(基于日期)" style="Widget.AppCompat.Button.Colored" />
<button id="dwzbobao" w="*" text="选读文章(基于播报)" style="Widget.AppCompat.Button.Colored" />
<button text="-------公告-------" style="Widget.AppCompat.Button.Borderless.Colored" w="*"/>
<button text="此应用仅适用于Android7.0以上!" style="Widget.AppCompat.Button.Borderless.Colored" w="auto"/>
<button w="250" w="*" id="about" text="使用说明" style="Widget.AppCompat.Button.Colored" />
</vertical>
</ScrollView>
</frame>
<frame>
<ScrollView>
<vertical>
<horizontal>
<text textSize="15sp" marginLeft="15" textColor="black" text="文章频道:" />
<input id="aCatlog" w="55" text="" />
<text textSize="15sp" marginLeft="15" textColor="black" text="日期:" />
<input id="date_string" w="110" text="" />
</horizontal>
<horizontal>
<text textSize="15sp" marginLeft="15" textColor="black" text="文章数量:" />
<input id="aCount" w="30" text="" />
<text textSize="15sp" marginLeft="15" textColor="black" text="时长:" />
<input id="aTime" w="30" text="" />
<text textSize="15sp" marginLeft="15" textColor="black" text="执行:" />
<input id="aZX" w="30" text="" />
</horizontal>
<horizontal>
<text textSize="15sp" marginLeft="15" textColor="black" text="视频频道:" />
<input id="vCatlog" w="80" text="" />
<text textSize="15sp" marginLeft="15" textColor="black" text="关键词:" />
<input id="s" w="150" text="" />
</horizontal>
<horizontal>
<text textSize="15sp" marginLeft="15" textColor="black" text="视频数量:" />
<input id="vCount" w="30" text="" />
<text textSize="15sp" marginLeft="15" textColor="black" text="时长:" />
<input id="vTime" w="30" text="" />
</horizontal>
<horizontal>
<text textSize="15sp" marginLeft="15" textColor="black" text="挑战次数:" />
<input id="lCount" w="30" text="" />
<text textSize="15sp" marginLeft="15" textColor="black" text="答题:" />
<input id="qCount" w="30" text="" />
<text textSize="15sp" marginLeft="15" textColor="black" text="争上游次数:" />
<input id="zCount" w="30" text="" />
</horizontal>
</vertical>
</ScrollView>
</frame>
<frame>
<ScrollView>
<text text="{{txt}}" textColor="black" textSize="16sp" />
</ScrollView>
</frame>
<frame>
<ScrollView>
<vertical>
<text id="v240" />
<text id="v220" />
<text id="v204" />
<text id="v203" />
<text id="v202" />
<text id="v201" />
<text id="v200" />
<text id="v101" />
<text id="v100" />
</vertical>
</ScrollView>
</frame>
<frame>
<vertical>
<webview id="webview" h="300" margin="0 16"/>
<text text="官方网站:http://xzy.free.idcfengye.com/" />
<text text="有时访问会显示not found请过后重试或联系站长" />
</vertical>
</frame>
</viewpager>
</vertical>
<vertical layout_gravity="left" bg="#ffffff" w="280">
<img w="280" h="200" scaleType="fitXY" src="http://images.shejidaren.com/wp-content/uploads/2014/10/023746fki.jpg"/>
<list id="menu">
<horizontal bg="?selectableItemBackground" w="*">
<img w="50" h="50" padding="16" src="{{this.icon}}" tint="{{color}}"/>
<text textColor="black" textSize="15sp" text="{{this.title}}" layout_gravity="center"/>
</horizontal>
</list>
</vertical>
</drawer>
);
ui.v240.setText("v2.4.0:2021.2.16\n1,修复适配问题\n2,更新UI\n3,更新协议及说明\n");
ui.v220.setText("v2.2.0:2021.1.27\n1,添加争上游答题\n2,修复个别执行没有返回的问题\n3,添加协议及说明\n");
ui.v204.setText("v2.0.4:2020.8.29\n1,添加应用安装检测\n2,修复视听学习不能加积分的bug\n");
ui.v203.setText("v2.0.3:2020.8.28\n1,修复一些bug\n2,添加公告\n");
ui.v202.setText("v2.0.2:2020.8.27\n1,修复选读文章bug\n2,添加更新记录\n");
ui.v201.setText("v2.0.1:2020.8.27\n1,修复一些bug\n2,添加弹窗提示\n");
ui.v200.setText("v2.0.0:2020.8.27\n1,修复视听学习及一些bug\n2,添加本地频道及分享功能\n3,更新UI界面\n4,添加一键刷积分\n");
ui.v101.setText("v1.0.1:2020.8.26\n1,修复一些bug\n");
ui.v100.setText("v1.0.0:2020.8.26\n原始版本,构建UI布局。添加选读文章及视听学习功能");
//创建选项菜单(右上角)
ui.emitter.on("create_options_menu", menu=>{
menu.add("协议");
menu.add("关于");
menu.add("说明");
});
//监听选项菜单点击
ui.emitter.on("options_item_selected", (e, item)=>{
switch(item.getTitle()){
case "协议":
alert("协议", "免责声明:本程序只供个人学习Auto.js使用,不得盈利传播,不得用于违法用途,否则造成的一切后果自负!\n如果继续使用此应用即代表您同意此协议");
break;
case "关于":
alert("关于", "自动学习强国 v2.4.3 ,徐子越制作");
break;
case "说明":
alert("使用说明",
"〇程序需要 悬浮窗 和 无障碍权限(设置→辅助功能→无障碍→本 APP)\n 〇程序工作原理为模拟点击,基于Auto.js框架+JavaScript脚本执行 \n 〇程序不支持每周答题,专项答题,订阅。正常执行完毕42分(可执行前手动答题,答题完毕学习强国请返回主界面; 也可执行中手动辅助答题,以手动点击为准) \n 〇积分判断执行:读取今日积分确定需执行任务,任务精准,但部分手机可能不支持(积分获取正常推荐使用) \n 〇循序依次执行:预置每日积分所需执行任务数,不判断积分,依次执行所有任务(积分获取返回null或报错使用) \n ◎请确保进入学习强国时位于 主界面,模拟点击从主界面开始 \n ◎因存在文章误点击视频,多次重复点击同一文章视频问题,有概率造成循环执行,请手动补学 \n ◎安卓版本低于安卓7,无法执行收藏评论转发,文章界面模拟滑动 \n ◎测试机型:Redmi 6,Android 9,MiUI 11开发版,Honor 8 Lite \n ★代码基于以下项目实现(UI及其它有所更改):Auto.js https://github.com/hyb1996/Auto.js \n LazyStudy https://github.com/lolisaikou/LazyStudy \n AutoLearnChina https://github.com/gzhjic/LearnChinaHelper \n XXQG-Helper https://github.com/ivanwhaf/xxqg-helper \n ●免责声明:本程序只供个人学习Auto.js使用,不得盈利传播,不得用于违法用途,否则造成的一切后果自负!"
);
break;
}
e.consumed = true;
});
activity.setSupportActionBar(ui.toolbar);
//设置滑动页面的标题
ui.viewpager.setTitles(["自动", "数据配置", "运行日志", "更新记录", "xzy的网站"]);
//让滑动页面和标签栏联动
ui.tabs.setupWithViewPager(ui.viewpager);
//让工具栏左上角可以打开侧拉菜单
ui.toolbar.setupWithDrawer(ui.drawer);
ui.menu.setDataSource([
{
title: "作者QQ:2417481092",
icon: "@drawable/ic_android_black_48dp"
},
{
title: "作者微信:xu13515380920",
icon: "@drawable/ic_settings_black_48dp"
},
{
title: "作者电话:13515380920",
icon: "@drawable/ic_favorite_black_48dp"
},
{
title: "退出",
icon: "@drawable/ic_exit_to_app_black_48dp"
}
]);
ui.menu.on("item_click", item => {
switch(item.title){
case "退出":
ui.finish();
break;
}
})
ui.webview.loadUrl("http://xzy.free.idcfengye.com/");
ui.click_me.on("click", ()=>{
toast("选择'自动学习强国'开启无障碍");
engines.execScript("选择'自动学习强国'开启无障碍","auto.waitFor();console.show();console.hide();");
});
var thread = null;
ui.all.click(function () {
if (thread != null && thread.isAlive()) {
alert("注意", "脚本正在运行,请结束之前进程");
return;
}
toast("开始积分判断运行");
thread = threads.start(function () {
aCatlog = ui.aCatlog.getText();
vCatlog = ui.vCatlog.getText();
aZX = parseInt(ui.aZX.getText());
lCount = parseInt(ui.lCount.getText());
qCount = parseInt(ui.qCount.getText());
zCount = parseInt(ui.zCount.getText());
main();
});
});
ui.customize.click(function () {
if (thread != null && thread.isAlive()) {
alert("注意", "脚本正在运行,请结束之前进程");
return;
}
toast("开始自定义运行");
thread = threads.start(function () {
aCatlog = ui.aCatlog.getText();
date_string = parseInt(ui.date_string.getText());
vCatlog = ui.vCatlog.getText();
s = ui.s.getText();
aCount = parseInt(ui.aCount.getText());
aTime = parseInt(ui.aTime.getText());
aZX = parseInt(ui.aZX.getText());
vCount = parseInt(ui.vCount.getText());
vTime = parseInt(ui.vTime.getText());
lCount = parseInt(ui.lCount.getText());
qCount = parseInt(ui.qCount.getText());
zCount = parseInt(ui.zCount.getText());
customize_flag = true;
console.log('文章频道:' + aCatlog.toString() + '日期:' + date_string)
console.log('文章数量:' + aCount.toString() + '篇')
console.log('视频频道:' + vCatlog.toString() + '关键词' + s)
console.log('视频数量:' + vCount.toString() + '个')
main();
});
});
ui.cq.click(function () {//挑战答题
auto.waitFor();//等待获取无障碍辅助权限
if (thread != null && thread.isAlive()) {
alert("注意", "脚本正在运行,请结束之前进程");
return;
}
thread = threads.start(function () {
lCount = parseInt(ui.lCount.getText());
qCount = parseInt(ui.qCount.getText());
start_app();
challengeQuestion();
threads.shutDownAll();
console.hide();
engines.stopAll();
exit();
});
});
ui.dwzdate.click(function () {//挑战答题
auto.waitFor();//等待获取无障碍辅助权限
if (thread != null && thread.isAlive()) {
alert("注意", "脚本正在运行,请结束之前进程");
return;
}
thread = threads.start(function () {
start_app();
articleStudy1();
threads.shutDownAll();
console.hide();
engines.stopAll();
exit();
});
});
ui.dwzbobao.click(function () {//挑战答题
auto.waitFor();//等待获取无障碍辅助权限
if (thread != null && thread.isAlive()) {
alert("注意", "脚本正在运行,请结束之前进程");
return;
}
thread = threads.start(function () {
start_app();
articleStudy2();
threads.shutDownAll();
console.hide();
engines.stopAll();
exit();
});
});
ui.dq.click(function () {//每日答题
auto.waitFor();//等待获取无障碍辅助权限
if (thread != null && thread.isAlive()) {
alert("注意", "脚本正在运行,请结束之前进程");
return;
}
thread = threads.start(function () {
start_app();
dailyQuestion();
threads.shutDownAll();
console.hide();
engines.stopAll();
exit();
});
});
ui.sr.click(function () {//双人对战
auto.waitFor();//等待获取无障碍辅助权限
if (thread != null && thread.isAlive()) {
alert("注意", "脚本正在运行,请结束之前进程");
return;
}
thread = threads.start(function () {
start_app();
zCount = parseInt(ui.zCount.getText());
SRQuestion();
threads.shutDownAll();
console.hide();
engines.stopAll();
exit();
});
});
ui.zsy.click(function () {//争上游答题
auto.waitFor();//等待获取无障碍辅助权限
if (thread != null && thread.isAlive()) {
alert("注意", "脚本正在运行,请结束之前进程");
return;
}
thread = threads.start(function () {
start_app();
zCount = parseInt(ui.zCount.getText());
zsyQuestion();
threads.shutDownAll();
console.hide();
engines.stopAll();
exit();
});
});
ui.stop.click(function () {
if (thread != null && thread.isAlive()) {
threads.shutDownAll();
toast("停止运行!")
console.hide();
}
else {
toast("没有线程在运行!")
}
});
ui.about.click(function () {
alert("使用说明",
"〇程序需要 悬浮窗 和 无障碍权限(设置→辅助功能→无障碍→本 APP)\n 〇程序工作原理为模拟点击,基于Auto.js框架+JavaScript脚本执行 \n 〇程序不支持每周答题,专项答题,订阅。正常执行完毕42分(可执行前手动答题,答题完毕学习强国请返回主界面; 也可执行中手动辅助答题,以手动点击为准) \n 〇积分判断执行:读取今日积分确定需执行任务,任务精准,但部分手机可能不支持(积分获取正常推荐使用) \n 〇循序依次执行:预置每日积分所需执行任务数,不判断积分,依次执行所有任务(积分获取返回null或报错使用) \n ◎请确保进入学习强国时位于 主界面,模拟点击从主界面开始 \n ◎因存在文章误点击视频,多次重复点击同一文章视频问题,有概率造成循环执行,请手动补学 \n ◎安卓版本低于安卓7,无法执行收藏评论转发,文章界面模拟滑动 \n ◎测试机型:Redmi 6,Android 9,MiUI 11开发版,Honor 8 Lite \n ★代码基于以下项目实现(UI及其它有所更改):Auto.js https://github.com/hyb1996/Auto.js \n LazyStudy https://github.com/lolisaikou/LazyStudy \n AutoLearnChina https://github.com/gzhjic/LearnChinaHelper \n XXQG-Helper https://github.com/ivanwhaf/xxqg-helper \n ●免责声明:本程序只供个人学习Auto.js使用,不得盈利传播,不得用于违法用途,否则造成的一切后果自负!"
)
});
ui.aCatlog.setText(aCatlog.toString());
ui.date_string.setText(date_string.toString());
ui.aCount.setText(aCount.toString());
ui.aTime.setText(aTime.toString());
ui.aZX.setText(aZX.toString());
ui.vCatlog.setText(vCatlog.toString());
ui.s.setText(s.toString());
ui.vCount.setText(vCount.toString());
ui.vTime.setText(vTime.toString());
ui.lCount.setText(lCount.toString());
ui.qCount.setText(qCount.toString());
ui.zCount.setText(zCount.toString());
function getTodayDateString() {
var date = new Date();
var y = date.getFullYear();
var m = date.getMonth();
var d = date.getDate();
var s = dateToString(y, m, d);//年,月,日
return s
}
function dateToString(y, m, d) {
var year = y.toString();
if ((m + 1) < 10) {
var month = "0" + (m + 1).toString();
} else {
var month = (m + 1).toString();
}
if (d < 10) {
var day = "0" + d.toString();
} else {
var day = d.toString();
}
var s = year + "-" + month + "-" + day;//年-月-日
return s;
}
/*
<---------------UI部分结束--------------->
*/
function main() {
if (!judge_tiku_existence()) {//题库不存在则退出
return;
}
auto.waitFor();//等待获取无障碍辅助权限
start_app();//启动app
var start = new Date().getTime();//程序开始时间
if (customize_flag == true) {
//自定义学习,各项目执行顺序可换
localChannel1();//本地频道
zsyQuestion();//争上游答题
SRQuestion();//双人对战
challengeQuestion();//挑战答题
dailyQuestion();//每日答题
if (aZX == 1){
articleStudy1();//学习文章脚本1,包含点赞、分享和评论
}else{
articleStudy2();//学习文章脚本2,包含点赞、分享和评论
}
videoStudy_news();//看视频
}else {
getScores();//获取积分
while ( myScores["双人对战"] < 1 || myScores["争上游答题"] < 2 || myScores['本地频道'] != 1 || myScores['挑战答题'] != 6 || myScores['每日答题'] != 5 || myScores['视听学习'] != 6 || myScores['我要选读文章'] != 12 /*|| myScores['分享'] != 1 || myScores['发表观点'] != 1*/){
if (myScores['本地频道'] != 1) {
localChannel1();//本地频道
}
if (myScores["争上游答题"] < 2) {
zsyQuestion();//争上游答题
}
if (myScores["双人对战"] < 1) {
SRQuestion();//双人对战
}
if (myScores['挑战答题'] != 6) {
challengeQuestion();//挑战答题
}
if (myScores['每日答题'] != 5) {
dailyQuestion(); //每日答题
}
if (myScores['我要选读文章'] != 12) {
if (aZX == 1){
articleStudy1();//学习文章脚本1,包含点赞、分享和评论
}else{
articleStudy2();//学习文章脚本2,包含点赞、分享和评论
}
}
if (myScores['视听学习'] != 6){
videoStudy_news();//看视频
}
getScores();//再次获取积分,核对文章和视听时长,补学
continue;//break结束当前循环,continue继续执行当前循环
}
if (myScores['分享'] != 1 || myScores['发表观点'] != 1){
aCount = 2;//置文章数2,学习文章2,启动分享收藏评论2
articleStudy1(); //收藏+分享 若c运行到此报错请注释本行!
}
if (myScores['视听学习时长'] != 6){
listenToRadio();//听电台广播补视听时长
}
}
var end = new Date().getTime();
console.log("运行结束,共耗时" + (parseInt(end - start)) / 1000 + "秒");
threads.shutDownAll();
console.hide();
engines.stopAll();
exit();
}
/** if (id("home_bottom_tab_button_work").exists()) {
id("home_bottom_tab_button_work").findOne().click();}
while (!id("home_bottom_tab_button_work").exists()) {//20201001 学习按钮文字属性由"学习"改为 "工作",以下所有点击学习按钮加载主页均同步修改
id("home_bottom_tab_button_work").findOne().click();
**/
/**
* @description: 启动app
* @param: null
* @return: null
*/
function start_app() {
console.setPosition(0, device.height / 2);//部分华为手机console有bug请注释本行
console.show();//部分华为手机console有bug请注释本行
console.log("启动学习强国");
if (!launchApp("学习强国")){//启动学习强国app
console.error("找不到学习强国App!");
return;
}
delay(3); //如果已清理强国app后台,默认打开主页;如果未清理后台,3秒应该可以拉起强国app
if (className("android.view.View").text("继续挑战").exists()){//双人对战 争上游结束页
back(); delay(1); }
if (className("android.view.View").text("开始对战").exists()){//双人对战开始页
back(); delay(1); }
if (className("android.widget.Button").text("退出").exists()){//双人对战退出房间
className("android.widget.Button").text("退出").findOne().click();
back(); delay(1); }
if (className("android.view.View").text("开始比赛").exists()){//争上游答题开始页
back(); delay(1); }
if (className("android.view.View").text("答题练习").exists()){//我要答题页
back(); delay(1); }
if (id("menu_contact").exists()){//强国通讯录
id("home_bottom_tab_button_work").findOne().click();
delay(1); }
if (id("more_text").exists()){//学习积分页
back(); delay(1); }
if (id("my_display_name").exists()){//我的主页
back(); delay(1); }
/*while (!id("home_bottom_tab_button_work").exists()){
back();delay(2);
continue;
} */ //适合内部返回主页,不适合已清理强国后台情况下初始拉起强国app
while (!id("home_bottom_tab_button_work").exists()) {//20201001 学习按钮文字属性由"学习"改为 "工作",以下所有点击学习按钮加载主页均同步修改
id("home_bottom_tab_button_work").findOne().click();//点击主页正下方的"学习"按钮
console.log("等待加载出主页");
delay(1);
continue;/*break;exists(); back();*/
}
delay(1);
}
/**
* @description: 定义延时函数
* @param: seconds-延迟秒数
* @return: null
*/
function delay(seconds) {
sleep(1000 * seconds);//sleep函数参数单位为毫秒所以乘1000
}
/**
* @description: 获取积分
* @param: null
* @return: null
*/
function getScores() {
while (!id("home_bottom_tab_button_work").exists());//等待加载出主页
id("home_bottom_tab_button_work").findOne().click();//点击主页正下方的"学习"按钮
delay(2);
console.log("正在获取积分...");
while (!text("积分明细").exists()) {//自主页点击右上角积分数字进入学习积分
if (id("comm_head_xuexi_score").exists()) {
id("comm_head_xuexi_score").findOnce().click();
} else if (text("积分").exists()) {
text("积分").findOnce().parent().child(1).click();
} else if (id("comm_head_xuexi_mine").exists()){//自强国通页面进入我的主页点击学习积分
id("comm_head_xuexi_mine").findOnce().click();
if (id("my_display_name").exists()){//我的主页
id("my_recycler_view").findOnce().child(0).click();
}
}
delay(3);
}
let err = false;
while (!err) {
try {
className("android.widget.ListView").findOnce().children().forEach(item => {
let name = item.child(0).child(0).text();
let str = item.child(2).text().split("/");
let score = str[0].match(/[0-9][0-9]*/g);
myScores[name] = score;
});
err = true;
} catch (e) {
console.log(e);
}
}
console.log(myScores);
aCount = 12 - myScores["我要选读文章"];
vCount = 6 - myScores["视听学习"];
rTime = (6 - myScores["视听学习时长"]) * 60;
console.log('剩余文章:' + aCount.toString() + '篇')
console.log('剩余视频:' + vCount.toString() + '个')
console.log('视听学习时长:' + rTime.toString() + '秒')
delay(1); back(); delay(1);
}
/**
* @description: 文章学习函数 (阅读文章+文章学习时长)---12分
* @param: null
* @return: null
*/
//文章学习函数之1 点击基于日期s=date_String或 "学习强国"平台
function articleStudy1() {
while (!id("home_bottom_tab_button_work").exists());//等待加载出主页
id("home_bottom_tab_button_work").findOne().click();//点击主页正下方的"学习"按钮
delay(2);
var aCatlog = aCat[num] ;//文章学习类别,随机取"推荐""要闻"、"新思想"
var date_string = getTodayDateString();//获取当天日期字符串
var s = date_string;
var listView = className("ListView");//获取文章ListView控件用于翻页
click(aCatlog);
delay(2);
var zt_flag = false;//判断进入专题界面标志
var fail = 0;//点击失败次数
console.log('文章类别:' + aCatlog + '关键词:'+ s)
for (var i = 0, t = 0; i < aCount;) {
if (click(s, t) == true)//如果点击成功则进入文章页面,不成功意味着本页已经到底,要翻页
{
let n = 0;
while (!textContains("欢迎发表你的观点").exists())//如果没有找到评论框则认为没有进入文章界面,一直等待
{
delay(1);
console.warn("正在等待加载文章界面...");
if (n > 3)//等待超过3秒则认为进入了专题界面,退出进下一篇文章
{
console.warn("没找到评论框!该界面非文章界面!");
zt_flag = true;
break;
}
n++;
}
if (textContains("央视网").exists() || textContains("广播").exists() || textContains("中央广播电视总台").exists() ||textContains("播放").exists() ||textContains("展开").exists() )//如果存在“央视网、中央广播电视总台、播放、展开”则认为进入了视频需退出。关键词测试
{
console.warn("进入视频界面,退出并进下一篇文章!");
t++;
back();
/* while (!id("home_bottom_tab_button_work").exists());
delay(0.5);
click("电台");
delay(1);
click("最近收听");
console.log("因广播被打断,重新收听广播...");
delay(1);
back();*/
while (!id("home_bottom_tab_button_work").exists());
id("home_bottom_tab_button_work").findOne().click();
delay(1);
num = random(0, commentText.length - 1) ; //重取随机数
aCatlog = aCat[num] ;
s = "“学习强国”学习平台";
console.log('文章类别:' + aCatlog + '关键词:'+ s)
click(aCatlog);
delay(1);
continue;
}
if (id("v_play").exists() || id("bg_play").exists())//进入电台页面2020.09.28
{
console.warn("进入电台界面,退出并进下一篇文章!");
t++;
if (id("btn_back").exists()){
id("btn_back").findOnce().click();//返回 2020.09.28需关闭电台收听
}else{
back; }//返回 2020.09.28需关闭电台收听
while (!id("home_bottom_tab_button_work").exists());
id("home_bottom_tab_button_work").findOne().click();
delay(1);
num = random(0, commentText.length - 1) ; //重取随机数
aCatlog = aCat[num] ;
s = "“学习强国”学习平台";
console.log('文章类别:' + aCatlog + '关键词:'+ s)
click(aCatlog);
delay(1);
continue;
}
if (zt_flag == true)//进入专题页标志
{
console.warn("进入了专题界面,退出并进下一篇文章!")
t++;
back();
delay(1);
zt_flag = false;
continue;
}
console.log("正在学习第" + (i + 1) + "篇文章...");
fail = 0;//失败次数清0
article_timing(i, aTime);
if (i < cCount)//收藏分享2篇文章
{
CollectAndShare(i);//收藏+分享 若运行到此报错请注释本行!
Comment(i);//评论
}
back();//返回主界面
while (!id("home_bottom_tab_button_work").exists());//等待加载出主页
delay(1);
i++;
t++;//t为实际点击的文章控件在当前布局中的标号,和i不同,勿改动!
} else {
if (id("v_play").exists() || id("bg_play").exists())//进入电台页面2020.09.28
{
console.warn("进入电台界面,退出并进下一篇文章!");
t++;
if (id("btn_back").exists()){
id("btn_back").findOnce().click();//返回 2020.09.28需关闭电台收听
}else{
back; }
while (!id("home_bottom_tab_button_work").exists());
id("home_bottom_tab_button_work").findOne().click();
delay(1);
num = random(0, commentText.length - 1) ; //重取随机数
aCatlog = aCat[num] ;
s = "“学习强国”学习平台";
console.log('文章类别:' + aCatlog + '关键词:'+ s)
click(aCatlog);
delay(1);
continue;
}
if (i == 0)//如果第一次点击就没点击成功则认为首页无当天文章
{
date_string = getYestardayDateString();
s = date_string;
/*s = "“学习强国”学习平台";*/
num = random(0, commentText.length - 1) ; //重取随机数
aCatlog = aCat[num] ;
click(aCatlog);
console.warn("首页没有找到当天文章,即将学习昨日新闻!"+aCatlog + s);
continue;
}
if (fail > 3)//连续翻几页没有点击成功则认为今天的新闻还没出来,学习昨天的
{
date_string = getYestardayDateString();
/*s = date_string;*/
s = "“学习强国”学习平台";
num = random(0, commentText.length - 1) ; //重取随机数
aCatlog = aCat[num] ;
click(aCatlog);
console.warn("没有找到当天文章,即将学习昨日新闻!"+aCatlog + s);
fail = 0;//失败次数清0
continue;
}
if (!textContains(s).exists())//当前页面当天新闻
{
fail++;//失败次数加一
}
listView.scrollForward();//向下滑动(翻页)
t = 0;
delay(1.5);
}
}
}
//文章学习函数之2 基于播报判断.因基于父子控件判断,点击基于日期s=date_String 感谢chongyadong
function articleStudy2() {
while (!id("home_bottom_tab_button_work").exists());//等待加载出主页
id("home_bottom_tab_button_work").findOne().click();//点击主页正下方的"学习"按钮
delay(2);
var aCatlog = aCat[num] ;//文章学习类别,随机取"推荐""要闻"、"新思想"
var date_string = getTodayDateString();//获取当天日期字符串
var s = date_string;
var listView = className("ListView");//获取文章ListView控件用于翻页
click(aCatlog);
delay(2);
var zt_flag = false;//判断进入专题界面标志
var currentNewsTitle = "";
var fail = 0; //点击失败次数
console.log('文章类别:' + aCatlog + '关键词:'+ s)
for (var i = 0, t = 0; i < aCount;) {
var art_obj = text(s).findOnce(t);
//console.info(art_obj);
if ((art_obj != null) && (art_obj.parent().childCount() == 4)) {
t++; //t为实际查找的文章控件在当前布局中的标号,和i不同,勿改动!
if ((art_obj.parent().child(3).text() == "播报") && (art_obj.parent().child(0).text() != currentNewsTitle)) //如果播报存在就进入文章正文
{
currentNewsTitle = art_obj.parent().child(0).text();
log(currentNewsTitle);
art_obj.parent().click();
delay(1);
let n = 0;
while (!textContains("欢迎发表你的观点").exists())//如果没有找到评论框则认为没有进入文章界面,一直等待
{
delay(1);
console.warn("正在等待加载文章界面...");
if (n > 3)//等待超过3秒则认为进入了专题界面,退出进下一篇文章
{
console.warn("没找到评论框!该界面非文章界面!");
zt_flag = true;
break;
}
n++;
}
if (textContains("央视网").exists() || textContains("广播").exists() || textContains("中央广播电视总台").exists() ||textContains("播放").exists() ||textContains("展开").exists() )//如果存在“央视网、中央广播电视总台、播放、展开”则认为进入了视频需退出。关键词测试
{
console.warn("进入视频界面,退出并进下一篇文章!");
t++;
back();
/*while (!id("home_bottom_tab_button_work").exists());
delay(0.5);
click("电台");
delay(1);
click("最近收听");
console.log("因广播被打断,重新收听广播...");
delay(1);
back();*/
while (!id("home_bottom_tab_button_work").exists());
id("home_bottom_tab_button_work").findOne().click();
delay(1);
num = random(0, commentText.length - 1) ; //重取随机数
aCatlog = aCat[num] ;
s = date_string;
/*s = "“学习强国”学习平台";*/
console.log('文章类别:' + aCatlog + '关键词:'+ s)
click(aCatlog);
delay(1);
continue;
}
if (id("v_play").exists() || id("bg_play").exists())//进入电台页面2020.09.28
{
console.warn("进入电台界面,退出并进下一篇文章!");
t++;
if (id("btn_back").exists()){
id("btn_back").findOnce().click();//返回 2020.09.28需关闭电台收听
}else{
back; }//返回 2020.09.28需关闭电台收听
while (!id("home_bottom_tab_button_work").exists());
id("home_bottom_tab_button_work").findOne().click();
delay(1);
num = random(0, commentText.length - 1) ; //重取随机数
aCatlog = aCat[num] ;
s = date_string;
/*s = "“学习强国”学习平台";*/
console.log('文章类别:' + aCatlog + '关键词:'+ s)
click(aCatlog);
delay(1);
continue;
}
if (zt_flag == true)//进入专题页标志
{
console.warn("进入了专题界面,退出并进下一篇文章!")
t++;
back();
delay(1);
zt_flag = false;
continue;
}
console.log("正在学习第" + (i + 1) + "篇文章...");
fail = 0; //失败次数清0
article_timing(i, aTime);
if (i < cCount)//收藏分享2篇文章
{
CollectAndShare(i);//收藏+分享 若c运行到此报错请注释本行!
Comment(i);//评论
}
back(); //返回主界面
while (!id("home_bottom_tab_button_work").exists());//等待加载出主页
delay(1);
i++;
}else{ //判断非目标文章
if (t > 2) {
listView.scrollForward(); //向下滑动(翻页
console.log("----------翻页------------");
t = 0;
delay(1.5);
}
}
}else{
if (fail > 3) //连续翻几页没有点击成功则认为今天的新闻还没出来,学习昨天的
{
date_string = getYestardayDateString();
s = date_string;
/*s = "“学习强国”学习平台";*/
num = random(0, commentText.length - 1) ; //重取随机数
aCatlog = aCat[num] ;
click(aCatlog);
console.warn("没有找到当天文章,即将学习昨日新闻!"+aCatlog + s);
fail = 0;//失败次数清0
continue;
}
if (!textContains(date_string).exists()) //当前页面当天新闻
{
fail++; //失败次数加一
}
listView.scrollForward(); //向下滑动(翻页
console.log("----------翻页------------");
t = 0;
delay(1.5);
}
}
}
/**
* @description: 文章学习计时(弹窗)函数
* @param: n-文章标号 seconds-学习秒数
* @return: null
*/
function article_timing(n, seconds) {
h = device.height;//屏幕高
w = device.width;//屏幕宽
x = (w / 3) * 2;
h1 = (h / 6) * 5;
h2 = (h / 6);
seconds = seconds + random(0,10);
for (var i = 0; i < seconds; i++) {
delay(1);
while (!textContains("欢迎发表你的观点").exists())//如果离开了文章界面则一直等待
{
console.error("当前已离开第" + (n + 1) + "文章界面,请重新返回文章页面...");
delay(2);
if(id("home_bottom_tab_button_work").exists()){
id("home_bottom_tab_button_work").findOne().click();
delay(1);
num = random(0, commentText.length - 1) ; //重取随机数
var date_string = getTodayDateString();
/*s = date_string;*/
s = "“学习强国”学习平台";
var aCatlog = aCat[num] ;
click(aCatlog);
console.log('文章类别:' + aCatlog + '关键词:'+ s)
delay(2);
click(s);
delay(2);
break;//break结束当前循环,continue继续执行当前循环,该命令导致手动进入文章无效 待修正
}
}
if (i % 5 == 0)
{
console.info("第" + (n + 1) + "篇文章已经学习" + (i + 1) + "秒,剩余" + (seconds - i - 1) + "秒!");
toast("防息屏弹窗,请无视");
if (i <= seconds / 2) {//每10秒滑动一次,如果android版本<7.0请将此滑动代码删除
swipe(x, h1, x, h2, 500);//向下滑动
} else {
swipe(x, h2, x, h1, 500);//向上滑动
}
}
}
}
/**
* @description:新闻联播小视频学习函数
* @param: null
* @return: null
*/
function videoStudy_news() {
while (!id("home_bottom_tab_button_work").exists());//等待加载出主页
id("home_bottom_tab_button_work").findOne().click();//点击主页正下方的"学习"按钮
delay(2);
click("电视台");
var vCatlog = vCat[num] ; //视频学习类别,随机取 "第一频道"、"学习视频"、"联播频道"
if (num == 0){
var s = "中央广播电视总台";
}else if (num == 1){
var s = "央视新闻";
}else {
var s = "中央广播电视总台";
}
delay(1);
click(vCatlog);
delay(2);
var listView = className("ListView");//获取listView视频列表控件用于翻页
var fail = 0;//点击失败次数