forked from lolisaikou/LazyStudy
-
Notifications
You must be signed in to change notification settings - Fork 2
/
!xxqg_v3.1.3(fixall).js
2848 lines (2687 loc) · 104 KB
/
!xxqg_v3.1.3(fixall).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
importClass(android.database.sqlite.SQLiteDatabase);
/**
* @Description: Auto.js xxqg-helper (6+6)+(6+6)+(1+1+2)+6+6+1=41分
* @version: 3.1.3
* @Author: Ivan
* @Date: 2020-6-10
*/
/**
* 我要选读文章6+6:6篇,每篇学习1分钟
* 视听学习6:360秒
* 每日答题6:5道
* 挑战答题6:5道以上
* 分享2:2个
* 发表观点1:1个
* 收藏不再积分
*/
var aCount = 6;//文章默认学习篇数
var vCount = 6;//小视频默认学习个数
var cCount = 1;//评论次数
var sCount = 2;//分享次数
var zCount = 2;//争上游答题轮数
var aTime = 60 + random(5, 15);//每篇文章学习-60秒 60*6≈360秒=6分钟
var vTime = 15 + random(5, 15);//每个小视频学习-15秒
var rTime = 360 + random(5, 15);//广播收听6分 * 60 = 360秒
//随机加5-15秒学习时长
var commentText = ["支持党,支持国家!", "为实现中华民族伟大复兴而不懈奋斗!", "不忘初心,牢记使命"];//评论内容,可自行修改,大于5个字便计分
var num = random(0, commentText.length - 1);//随机数
//var aCatlog = files.read("./article.txt");//文章学习类别,可自定义修改为“要闻”、“新思想”等
var aCat = ["推荐", "要闻", "综合"];
var aCatlog = aCat[num];//文章学习类别,随机取"推荐","要闻","综合","实践"
var asub = 2; //订阅数
var lCount = 1;//挑战答题轮数
var qCount = randomNum(5, 7);//挑战答题每轮答题数(5~7随机)
var myScores = {};//分数
var customize_flag = true;//自定义运行标志,true:1/false:0
var vCat = ["第一频道", "学习视频", "联播频道"];
var vCatlog = vCat[num]; //视频学习类别,随机取 "第一频道"、"学习视频"、"联播频道"
var xxScores; //累计学习积分
var date_string = getTodayDateString();//获取当天日期字符串,定义为全局变量,方便其他函数调用
var ziXingTi = "选择词语的正确词形。"; //字形题,已定义为全局变量
var zsyDelay = 100; //单位为ms毫秒,示例为0-100的随机值,定义争上游答题延时时间,参考某些学习工具的延时时间为100ms,即0.1秒,默认的delay为随机500ms以上
var localTiku = true; ////是否启用本地题库的搜索和更新(true:1启用,false:0不启用),网络搜题或随机点击到正确答案时会同时更新本地题库
/**
* @description: 生成从minNum到maxNum的随机数
* @param: minNum-较小的数
* @param: maxNum-较大的数
* @return: null
*/
function randomNum(minNum, maxNum) {
switch (arguments.length) {
case 1:
return parseInt(Math.random() * minNum + 1, 10);
case 2:
return parseInt(Math.random() * (maxNum - minNum + 1) + minNum, 10);
default:
return 0;
}
}
/**
* @description: 延时函数
* @param: seconds-延迟秒数
* @return: null
*/
function delay(seconds) {
sleep(1000 * seconds + randomNum(0, 500));//sleep函数参数单位为毫秒所以乘1000
}
/**
* @description: 读取文章数据库
* @param: title,date
* @return: res
*/
function getLearnedArticle(title, date) {
rtitle = title.replace("'", "''");
var dbName = "list.db";
//文件路径
var path = files.path(dbName);
//确保文件存在
if (!files.exists(path)) {
// files.createWithDirs(path);
console.error("未找到题库!请将题库放置与js同一目录下");
}
//创建或打开数据库
var db = SQLiteDatabase.openOrCreateDatabase(path, null);
var createTable = "\
CREATE TABLE IF NOt EXISTS learnedArticles(\
title CHAR(500),\
date CHAR(100)\
);";
// var cleanTable = "DELETE FROM tikuNet";
db.execSQL(createTable);
// db.execSQL(cleanTable);
var sql = "SELECT * FROM learnedArticles WHERE title = '" + rtitle + "' AND date = '" + date + "'";
var cursor = db.rawQuery(sql, null);
var res = cursor.moveToFirst();
cursor.close();
db.close();
return res;
}
/**
* @description: 获取的文章题目写入数据库
* @param: title,date
* @return: res
*/
function insertLearnedArticle(title, date) {
rtitle = title.replace("'", "''");
var dbName = "list.db";
var path = files.path(dbName);
var db = SQLiteDatabase.openOrCreateDatabase(path, null);
var createTable = "\
CREATE TABLE IF NOt EXISTS learnedArticles(\
title CHAR(253),\
date CHAR(100)\
);";
// var cleanTable = "DELETE FROM tikuNet";
db.execSQL(createTable);
var sql = "INSERT INTO learnedArticles VALUES ('" + rtitle + "','" + date + "')";
db.execSQL(sql);
db.close();
}
/**
* @description: 文章学习计时(弹窗)函数
* @param: n-文章标号 seconds-学习秒数
* @return: null
*/
function article_timing(n, seconds) {
seconds = seconds + randomNum(0, 10)
let h = device.height;//屏幕高
let w = device.width;//屏幕宽
let x = (w / 3) * 2;
let h1 = (h / 6) * 5;
let h2 = (h / 6);
for (var i = 0; i < seconds; i++) {
while (!textContains("欢迎发表你的观点").exists())//如果离开了文章界面则一直等待
{
console.error("当前已离开第" + (n + 1) + "文章界面,请重新返回文章页面...");
delay(2);
if (textContains("欢迎发表你的观点").exists()) {
break;//防止通知/下拉菜单等不改变阅读界面但误判为离开
}
console.log("重新返回到学习主页,如果一直失败,请手动返回!");
delay(0.5);
console.log("阅读失败");
return false; //返回阅读失败
//back();
/*
start_app(1);
while (!id("home_bottom_tab_button_work").exists());
id("home_bottom_tab_button_work").findOne().click();
num = random(0, commentText.length - 1) ;//随机数
aCatlog = aCat[num] ;
//s = "“学习强国”学习平台";
click(aCatlog);
//console.log('文章类别:' + aCatlog + ';关键词:'+ s)
console.log('文章类别:' + aCatlog );
delay(1);
click(s);
delay(2);
break;
*/
}
if (i % 5 == 0)//每5秒打印一次学习情况
{
console.info("第" + (n + 1) + "篇文章已经学习" + (i + 1) + "秒,剩余" + (seconds - i - 1) + "秒!");
}
delay(1);
if (i % 10 == 0)//每10秒滑动一次,如果android版本<7.0请将此滑动代码删除
{
toast("这是防息屏toast,请忽视-。-");
if (i <= seconds / 2) {
swipe(x, h1, x, h2, 500);//向下滑动
}
else {
swipe(x, h2, x, h1, 500);//向上滑动
}
}
}
//console.log("193阅读成功");
return true; //返回阅读成功
}
/**
* @description: 视频学习计时(弹窗)函数
* @param: n-视频标号 seconds-学习秒数
* @return: null
*/
function video_timing_bailing(n, seconds) {
let h = device.height;//屏幕高
let w = device.width;//屏幕宽
let x = (w / 3) * 2;//横坐标2分之3处
let h1 = (h / 6) * 5;//纵坐标6分之5处
let h2 = (h / 6);//纵坐标6分之1处
for (var i = 0; i < seconds; i++) {
if (desc("继续播放")) {
click("继续播放");
}
while (!textContains("分享").exists() || id("home_bottom_tab_button_work").exists())//如果离开了百灵小视频界面则一直等待
{
console.error("当前已离开第" + (n + 1) + "个小视频界面,请重新返回视频");
delay(2);
if (textContains("/ 00").exists()) {
break;//防止通知/下拉菜单等不改变阅读界面但误判为离开
console.log("已返回小视频播放界面");
}
console.log("重新返回到学习主页,如果一直失败,请手动返回!");
delay(0.5);
console.log("百灵视频观看失败");
return false; //返回阅读失败
/*
console.log("返回到学习主页,如果一直失败,请手动返回!");
start_app(1);
while (!id("home_bottom_tab_button_work").exists());
id("home_bottom_tab_button_work").findOne().click();
delay(1);
click("百灵");
delay(2);
click("竖");
delay(2);
//a = className("FrameLayout").depth(23).findOnce(0);//根据控件搜索视频框,但部分手机不适配,改用下面坐标点击
click((w/2)+random()*10,h/4);//坐标点击第一个视频
//a.click();
delay(2);
break;
*/
}
if (textContains("即将播放").exists()) {
i = seconds - 2;
//console.log("即将播放下一个小视频"+i);
}
//持续学习
delay(1);
if (i % 10 == 0)//每10秒打印一次学习情况
{
console.info("第" + (n + 1) + "个小视频已经观看" + (i + 1) + "秒,剩余" + (seconds - i - 1) + "秒!");
toast("防息屏弹窗,请无视");
}
}
delay(1);
//console.log("247阅读成功");
return true; //返回阅读成功
}
/**
* @description: 新闻联播小视频学习计时(弹窗)函数
* @param: n-视频标号 seconds-学习秒数
* @return: null
*/
function video_timing_news(n, seconds) {
seconds = seconds + randomNum(0, 10);//加随机时间
for (var i = 0; i < seconds; i++) {
if (desc("继续播放")) {
click("继续播放");
}
delay(1);
var f = 0;//记录返回次数
while (!textContains("欢迎发表你的观点").exists())//如果离开了联播小视频界面则一直等待
{
console.error("当前已离开第" + (n + 1) + "个新闻小视频界面,请重新返回视频");
delay(2);
if (textContains("欢迎发表你的观点").exists() || textContains("展开").exists()) {
break;//防止通知/下拉菜单等不改变阅读界面但误判为离开
}
console.log("重新返回到学习主页,如果一直失败,请手动返回!");
delay(0.5);
console.log("视频学习失败");
return false; //返回阅读失败
}
if (i % 10 == 0)//每10秒打印一次学习情况
{
console.info("第" + (n + 1) + "个小视频已经观看" + (i + 1) + "秒,剩余" + (seconds - i - 1) + "秒!");
toast("防息屏弹窗,请无视");
}
}
//console.log("305阅读成功");
return true; //返回阅读成功
}
/**
* @description: 广播学习计时(弹窗)函数
* @param: r_time-已经收听的时间 seconds-学习秒数
* @return: null
*/
function radio_timing(r_time, seconds) {
for (var i = 0; i < seconds; i++) {
delay(1);
if (i % 5 == 0)//每5秒打印一次信息
{
console.info("广播已经收听" + (i + 1 + r_time) + "秒,剩余" + (seconds - i - 1) + "秒!");
}
if (i % 15 == 0)//每15秒弹一次窗防止息屏
{
toast("这是防息屏弹窗,可忽略-. -");
}
}
}
/**
* @description: 日期转字符串函数
* @param: y,m,d 日期数字 2019 1 1
* @return: s 日期字符串 "2019-xx-xx"
*/
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;
}
/**
* @description: 获取当天日期字符串函数
* @param: null
* @return: s 日期字符串 "2019-xx-xx"
*/
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
}
/**
* @description: 获取昨天日期字符串函数
* @param: null
* @return: s 日期字符串 "2019-xx-xx"
*/
function getYestardayDateString() {
var date = new Date();
date.setDate(date.getDate() - 1);
var y = date.getFullYear();
var m = date.getMonth();
var d = date.getDate();
var s = dateToString(y, m, d);//年-月-日
return s
}
/**
* @description: 文章学习函数 (阅读文章+文章学习时长)---6+6=12分
* @param: null
* @return: null
*/
function articleStudy(x) {
while (!id("home_bottom_tab_button_work").exists());//等待加载出主页
var listView = className("ListView");//获取文章ListView控件用于翻页
let s = "学习平台";//获取当天日期字符串
if (x == 0) {
id("home_bottom_tab_button_work").findOne().click();//点击主页正下方的"学习"按钮
delay(2);
}
click(aCatlog);
delay(2);
var zt_flag = false;//判断进入专题界面标志
var fail = 0;//点击失败次数
// console.log('文章类别:' + aCatlog + '关键词:'+ s)
for (var i = 0, t = 0; i < aCount;) {
console.log('文章类别:' + aCatlog);
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())//如果存在“央视网、中央广播电视总台、播放、展开”则认为进入了视频需退出。关键词测试
{
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需关闭电台收听
if (!id("home_bottom_tab_button_work").exists()) {
start_app(1);
delay(0.5);
id("home_bottom_tab_button_work").findOne().click();
}//等待加载出主页
//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;
}
delay(1);
//记录已学习的文章
var currentNewsTitle = ""
if (id("xxqg-article-header").exists()) {
currentNewsTitle = id("xxqg-article-header").findOne().child(0).text(); // 最终解决办法
} else if (textContains("来源").exists()) {
currentNewsTitle = textContains("来源").findOne().parent().children()[0].text();
} else if (textContains("作者").exists()) {
currentNewsTitle = textContains("作者").findOne().parent().children()[0].text();
} else if (descContains("来源").exists()) {
currentNewsTitle = descContains("来源").findOne().parent().children()[0].desc();
} else if (descContains("作者").exists()) {
currentNewsTitle = descContains("作者").findOne().parent().children()[0].desc();
} else {
console.log("无法定位文章标题,即将退出并阅读下一篇")
t++;
back();
/* num = random(0, commentText.length - 1) ;//随机数
aCatlog = aCat[num] ;
console.log('文章类别:' + aCatlog ); */
delay(1.5);
continue;
}
if (currentNewsTitle == "") {
console.log("标题为空,即将退出并阅读下一篇")
t++;
back();
/* num = random(0, commentText.length - 1) ;//随机数
aCatlog = aCat[num] ;
console.log('文章类别:' + aCatlog );
click(aCatlog); */
delay(1.5);
continue;
}
var flag = getLearnedArticle(currentNewsTitle, date_string);
if (flag) {
//已经存在,表明阅读过了
console.info("该文章已经阅读过,即将退出并阅读下一篇");
t++;
back();
num = random(0, commentText.length - 1);//随机数
aCatlog = aCat[num];
console.log('文章类别:' + aCatlog);
click(aCatlog);
delay(2);
continue;
} else {
//没阅读过,添加到数据库
//insertLearnedArticle(currentNewsTitle, date_string);
}
console.log("正在学习第" + (i + 1) + "篇文章...");
fail = 0;//失败次数清0
if (sCount != 0)//分享2篇文章
{
CollectAndShare(i);//分享 若运行到此报错请注释本行!
sCount--;
}
if (cCount != 0)//评论1次
{
Comment(i);//评论
cCount--;
}
if (article_timing(i, aTime)) { //如果阅读成功
//添加标题到数据库
console.log("文章阅读成功,记录文章标题");
console.log('文章名称:' + currentNewsTitle);
insertLearnedArticle(currentNewsTitle, date_string);
delay(1);
} else {
if (!id("home_bottom_tab_button_work").exists()) {
start_app(1);
delay(0.5);
id("home_bottom_tab_button_work").findOne().click();
}//等待加载出主页
delay(1);
num = random(0, commentText.length - 1);//随机数
aCatlog = aCat[num];
console.log('文章类别:' + aCatlog);
click(aCatlog); //重新进入文章页面
delay(2);
}
if (textContains("欢迎发表你的观点").exists() && !id("home_bottom_tab_button_work").exists()) {
back();//返回主界面
delay(0.5);
}
if (!id("home_bottom_tab_button_work").exists()) {
start_app(1);
delay(0.5);
id("home_bottom_tab_button_work").findOne().click();
delay(1);
click(aCatlog); //重新进入文章页面
}//等待加载出主页
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;
}
if (!id("home_bottom_tab_button_work").exists()) {
start_app(1);
delay(0.5);
id("home_bottom_tab_button_work").findOne().click();
}//等待加载出主页
//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);
}
}
}
/**
* @description: “百灵”小视频学习函数
* @param: vCount,vTime
* @return: null
*/
function videoStudy_bailing(vCount, vTime) {
let h = device.height;//屏幕高
let w = device.width;//屏幕宽
let x = (w / 3) * 2;//横坐标2分之3处
let h1 = (h / 6) * 5;//纵坐标6分之5处
let h2 = (h / 6);//纵坐标6分之1处
//
while (!id("home_bottom_tab_button_work").exists());//等待加载出主页
id("home_bottom_tab_button_work").findOne().click();//点击主页正下方的"学习"按钮
delay(2);
click("百灵");
delay(2);
click("竖");
delay(2);
//var a = className("FrameLayout").depth(23).findOnce(0);//根据控件搜索视频框,但部分手机不适配,改用下面坐标点击
//a.click();
click((w / 2) + random() * 10, h / 4);//坐标点击第一个视频
delay(1);
for (var i = 0; i < vCount;) {
console.log("正在观看第" + (i + 1) + "个小视频");
let nextVideo = false;
var currentNewsTitle = ""
while (true) {
try {
if (textContains("分享").exists) {//百灵视频
currentNewsTitle = textContains("分享").findOne().parent().parent().parent().children()[1].text(); //10.29测试,央视网/中央广播电视总台 视频标题
//console.log('视频名称1:'+currentNewsTitle);
} else {
console.log("无法定位视频标题,即将退出并观看下一个")
nextVideo = true;
}
if (currentNewsTitle == "") {
console.log("标题为空,即将退出并观看下一个")
nextVideo = true;
} else {
var flag = getLearnedArticle(currentNewsTitle, date_string);
if (flag) {
//已经存在,表明阅读过了
console.info("该视频已观看过,即将退出并阅读下一篇");
nextVideo = true;
} else {
console.log('视频名称:' + currentNewsTitle);
//观看的视频
nextVideo = false;
delay(0.5);
break;
}
}
if (nextVideo) {//滑动下一个视频
if (textContains("竖").exists && textContains("炫").exists) {
delay(2);
click("竖");
delay(2);
click((w / 2) + random() * 10, h / 4);//坐标点击第一个视频
}
delay(1);
swipe(x, h1, x, h2, 500);//往下翻(纵坐标从5/6处滑到1/6处)
}
} catch (e) {
console.log(e);
console.error("出现错误,请检查!");
break;
}
}
if (video_timing_bailing(i, vTime)) {//观看百灵小视频成功
////观看成功,记录已观看的视频
insertLearnedArticle(currentNewsTitle, date_string);
//console.log('623记录视频名称:'+currentNewsTitle);
i++;
delay(1);
if (i != vCount - 1) {
swipe(x, h1, x, h2, 500);//往下翻(纵坐标从5/6处滑到1/6处)
}
} else {
//观看失败
console.info("566已离开阅读界面,将退出并阅读下一篇");
start_app(1);
//while (!id("home_bottom_tab_button_work").exists());//等待加载出主页
//id("home_bottom_tab_button_work").findOne().click();//点击主页正下方的"学习"按钮
delay(2);
click("百灵");
delay(2);
click("竖");
delay(2);
//var a = className("FrameLayout").depth(23).findOnce(0);//根据控件搜索视频框,但部分手机不适配,改用下面坐标点击
//a.click();
click((w / 2) + random() * 10, h / 4);//坐标点击第一个视频
delay(1);
}
}
back();
delay(2);
}
/**
* @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("电视台");
vCatlog = vCat[num]; //视频学习类别,随机取 "第一频道"、"学习视频"、"联播频道"
if (num == 0) {
var s = "央视网";
} else if (num == 1) {
var s = "央视新闻";
} else {
var s = "中央广播电视总台";
}
delay(1);
click(aCatlog);
delay(2);
var listView = className("ListView");//获取listView视频列表控件用于翻页
var fail = 0;//点击失败次数
delay(1);
for (var i = 0, t = 1; i < vCount;) {
console.log('视频类别:' + vCatlog + '关键词:' + s)
if (click(s, t) == true) {
fail = 0;//失败次数清0
//记录已学习的视频
var currentNewsTitle = ""
if (textContains("展开").exists) {
if (s == "央视网" || s == "中央广播电视总台") {
currentNewsTitle = textContains("展开").findOne().parent().parent().parent().children()[1].text(); //10.29测试,央视网/中央广播电视总台 视频标题
// console.log('视频名称1:'+currentNewsTitle);
}
if (s == "央视新闻") {
currentNewsTitle = textContains("展开").findOne().parent().parent().parent().children()[2].text(); //10.29测试,央视新闻 视频标题
//console.log('视频名称2:'+currentNewsTitle);
let currentNewsTitle1 = currentNewsTitle.substr(0, 4);
//console.log('视频名称2:'+currentNewsTitle1);
if (currentNewsTitle1 == "央视新闻") {
currentNewsTitle = textContains("展开").findOne().parent().parent().parent().children()[1].text();
// console.log('视频名称2:'+currentNewsTitle);
}
}
} else {
console.log("无法定位视频标题,即将退出并观看下一个")
t++;
back();
delay(1);
continue;
}
if (currentNewsTitle == "") {
console.log("标题为空,即将退出并阅读下一篇")
t++;
back();
num = random(0, commentText.length - 1);//随机数
if (num == 0) {
var s = "央视网";
} else if (num == 1) {
var s = "央视新闻";
} else {
var s = "中央广播电视总台";
}
vCatlog = vCat[num];
console.log('视频频道:' + vCatlog + ';关键词:' + s);
click(vCatlog);
delay(1.5);
continue;
}
console.log("正在观看第" + (i + 1) + "个视频...");
console.log('视频名称:' + currentNewsTitle);
if (sCount != 0)//分享2篇文章
{
CollectAndShare(i);//分享 若运行到此报错请注释本行!
sCount--;
}
if (cCount != 0)//评论1次
{
Comment(i);//评论
cCount--;
}
if (video_timing_news(i, vTime)) {
//如果阅读成功
//没阅读过,添加到数据库
console.log("观看视频成功,记录视频标题");
console.log('视频名称:' + currentNewsTitle);
insertLearnedArticle(currentNewsTitle, date_string);
delay(1);
} else {
start_app(1);
delay(1.5);
click("电视台");
delay(1.5);
num = random(0, commentText.length - 1);//随机数
if (num == 0) {
var s = "央视网";
} else if (num == 1) {
var s = "央视新闻";
} else {
var s = "中央广播电视总台";
}
vCatlog = vCat[num];
console.log('视频频道:' + vCatlog + ';关键词:' + s);
click(vCatlog); //重新进入文章页面
}
if (textContains("展开").exists && !id("home_bottom_tab_button_work").exists()) {
back();//返回主界面
delay(0.5);
}
if (!id("home_bottom_tab_button_work").exists()) {
start_app(1);
delay(1.5);
click("电视台");
delay(1.5);
click(vCatlog);
}//等待加载出主页
delay(1);
i++;
t++;
if (i == 3) {//如果是平板等设备,请尝试修改i为合适值!
listView.scrollForward();//翻页
delay(2);
t = 0;
}
}
else {
if (fail > 3)//连续翻几页没有点击成功则改换频道
{
num = random(0, commentText.length - 1); //重取随机数
vCatlog = vCat[num];
click(vCatlog);
delay(2);
if (num == 0) {
var s = "央视网";
} else if (num == 1) {
var s = "央视新闻";
} else {
var s = "中央广播电视总台";
}
delay(1);
console.warn("改换:" + vCatlog + '关键词:' + s);
fail = 0;//失败次数清0
continue;
}
if (!textContains(s).exists())//未找到关键词
{
fail++;//失败次数加一
}
listView.scrollForward();//翻页
delay(2);
t = 0;
}
}
}
/**
* @description: 听“电台”新闻广播函数 (视听学习+视听学习时长)---6+6=12分
* @param: null
* @return: null
*/
function listenToRadio() {
while (!id("home_bottom_tab_button_work").exists());//等待加载出主页
id("home_bottom_tab_button_work").findOne().click();//点击主页正下方的"学习"按钮
delay(2);
click("电台");
delay(1);
click("听新闻广播");
delay(2);
if (textContains("最近收听").exists()) {
click("最近收听");
console.log("896正在收听广播...");
delay(1);
} else if (textContains("推荐收听").exists()) {
click("推荐收听");
console.log("900正在收听广播...");
delay(1);
} else if (textContains("正在收听").exists()) {
//click("正在收听");
console.log("905正在收听广播...");
delay(1);
}
if (!id("home_bottom_tab_button_work").exists()) {
start_app(1);
}
delay(1);
}
/**
* @description: 收藏加分享函数 (收藏+分享)---1+1=2分
* @param: i-文章标号
* @return: null
*/
function CollectAndShare(i) {
while (!textContains("欢迎发表你的观点").exists())//如果没有找到评论框则认为没有进入文章界面,一直等待
{
delay(1);
console.log("等待进入文章界面")
}
console.log("正在进行第" + (i + 1) + "次分享...");
var textOrder = text("欢迎发表你的观点").findOnce().drawingOrder();
// var collectOrder = textOrder + 2;
var shareOrder = textOrder + 3;
// var collectIcon = className("ImageView").filter(function (iv) {
// return iv.drawingOrder() == collectOrder;
// }).findOnce();
var shareIcon = className("ImageView").filter(function (iv) {
return iv.drawingOrder() == shareOrder;
}).findOnce();
//var collectIcon = classNameContains("ImageView").depth(10).findOnce(0);//右下角收藏按钮
// collectIcon.click();//点击收藏
// console.info("收藏成功!");
// delay(1);
//var shareIcon = classNameContains("ImageView").depth(10).findOnce(1);//右下角分享按钮
shareIcon.click();//点击分享
while (!textContains("分享到学习强").exists());//等待弹出分享选项界面
delay(1);
click("分享到学习强国");
delay(2);
console.info("分享成功!");
back();//返回文章界面
delay(1);
// collectIcon.click();//再次点击,取消收藏
// console.info("取消收藏!");
// delay(1);
}
/**
* @description: 评论函数---2分
* @param: i-文章标号
* @return: null
*/
function Comment(i) {
while (!textContains("欢迎发表你的观点").exists())//如果没有找到评论框则认为没有进入文章界面,一直等待
{
delay(1);
console.log("等待进入文章界面")
}
click("欢迎发表你的观点");//单击评论框
console.log("正在进行第" + (i + 1) + "次评论...");
delay(1);
var num = random(0, commentText.length - 1)//随机数
setText(commentText[num]);//输入评论内容
delay(1);
click("发布");//点击右上角发布按钮
console.info("评论成功!");
delay(2);
click("删除");//删除该评论
delay(2);
click("确认");//确认删除
console.info("评论删除成功!");
delay(1);
}
/**
* @description: 本地频道
* @param: null
* @return: null
*/
function localChannel() {
delay(1)
while (!id("home_bottom_tab_button_work").exists());//等待加载出主页
id("home_bottom_tab_button_work").findOne().click();
console.log("点击本地频道");
if (text("新思想").exists()) {
text("新思想").findOne().parent().parent().child(3).click();
delay(3);
className("android.support.v7.widget.RecyclerView").findOne().child(2).click();