-
Notifications
You must be signed in to change notification settings - Fork 5
/
questionCommon.js.bak
944 lines (870 loc) · 36.9 KB
/
questionCommon.js.bak
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
var tikuCommon = require("./tikuCommon.js");
FuncConfig = storages.create("强国学习配置");
var delaytime1=FuncConfig.get("延时最小值",520);
var delaytime2=FuncConfig.get("延时最大值",620);
delaytime2=Number(delaytime2)
delaytime1=Number(delaytime1)
/*************************************************公共部分******************************************************/
/**
* @description: 延时函数
* @param: seconds-延迟秒数
* @return: null
*/
function delay(seconds) {
sleep(1000 * seconds); //sleep函数参数单位为毫秒所以乘1000
}
/**
* @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: str
* @return: int 字母序号
*/
function indexFromChar(str) {
return str.charCodeAt(0) - "A".charCodeAt(0);
}
/**
* @description: 返回字段首字母
* @param: int 字母序号
* @return: str
*/
function charFromIndex(int) {
return String.fromCharCode("A".charCodeAt(0) + int);
}
/*************************************************挑战答题部分******************************************************/
/**
* @description: 答错后查找正确答案
* @param: delayTime, myColor, myThreshold, listArray, options
* @return: correctAns 正确答案
*/
function findCorrectAnswer(delayTime, myColor, myThreshold, listArray, options) {
console.hide(); //隐藏console控制台窗口
sleep(delayTime); //等待截屏
var img = captureScreen(); //截个屏
// let imgName = "./ddd" + new Date().getTime() + ".png";
// let imgName = "./ddd.png";
// captureScreen(imgName);//截个屏
// var img = images.read(imgName);
// toastLog(imgName);
console.show(); //显示console控制台窗口
//delay(3);
// 查找绿色答案#f24650
var correctAns = new Array();
listArray.some(item => {
var listBounds = item.bounds();
// console.log(listBounds);
var point = findColor(img, myColor, {
region: [listBounds.left, listBounds.top, listBounds.right - listBounds.left, listBounds.bottom - listBounds.top],
threshold: myThreshold
});
if (point) {
correctAns.push(options[listArray.indexOf(item)]);
correctAns.push(charFromIndex(listArray.indexOf(item)));
toastLog(correctAns);
return true;
} else {
// console.log("没找到");
}
});
return correctAns;
}
/**
* @description: 每次答题循环
* @param: conNum 连续答对的次数
* @return: null
*/
function challengeQuestionLoop(conNum, qCount) {
if (conNum >= qCount) //答题次数足够退出,每轮5次
{
let listArray = className("ListView").findOnce().children(); //题目选项列表
let i = random(0, listArray.length - 1);
console.log("本轮次数足够,随机点击一个答案,答错进入下一轮");
listArray[i].child(0).click(); //随意点击一个答案
console.log("----------------------------------");
return;
}
if (className("ListView").exists()) {
var question = className("ListView").findOnce().parent().child(0).text();
console.log((conNum + 1).toString() + ".题目:" + question);
} else {
console.error("提取题目失败!");
let listArray = className("ListView").findOnce().children(); //题目选项列表
let i = random(0, listArray.length - 1);
console.log("随机点击一个");
listArray[i].child(0).click(); //随意点击一个答案
return;
}
var chutiIndex = question.lastIndexOf("出题单位");
if (chutiIndex != -1) {
question = question.substring(0, chutiIndex - 2);
}
question = question.replace(/\s/g, "");
var options = []; //选项列表
if (className("ListView").exists()) {
className("ListView").findOne().children().forEach(child => {
var answer_q = child.child(0).child(1).text();
options.push(answer_q);
});
} else {
console.error("答案获取失败!");
return;
}
// 特殊情况外理
let specialQuestion = ["选择词语的正确词形。", "选择正确的读音。"]
if (specialQuestion.indexOf(question) > -1) {
question = question + options[0];
}
var answer = tikuCommon.getAnswer(question, 'tiku');
/* if (answer.length == 0) { //tiku表中没有则到tikuNet表中搜索答案
answer = getAnswer(question, 'tikuNet');
} */
if (/^[a-zA-Z]{1}$/.test(answer)) { //如果为ABCD形式
var indexAnsTiku = indexFromChar(answer.toUpperCase());
answer = options[indexAnsTiku];
toastLog("answer from char=" + answer);
}
let hasClicked = false;
var listArray = className("ListView").findOnce().children(); //题目选项列表
if ((answer == "") || !textEndsWith(answer).exists()) //如果没找到答案
{
let i = random(0, listArray.length - 1);
console.error("没有找到答案,随机点击一个");
listArray[i].child(0).click(); //随意点击一个答案
var delayTime = 120;
var myColor = "#44BF78";
var myThreshold = 4;
var correctAns = findCorrectAnswer(delayTime, myColor, myThreshold, listArray, options);
console.info("正确答案是:" + correctAns[0]);
/* console.hide(); //隐藏console控制台窗口
sleep(100); //等待截屏
var img = captureScreen();//截个屏
// captureScreen("./ddd.png");//截个屏
// var img = images.read("./ddd.png");
console.show(); //显示console控制台窗口
//delay(3);
// 查找绿色答案#f24650
var correctAns = false;
listArray.forEach(item => {
var listBounds = item.bounds();
// console.log(listBounds);
var point = findColor( img, "#44BF78", {
region: [listBounds.left, listBounds.top, listBounds.right-listBounds.left, listBounds.bottom-listBounds.top],
threshold: 4
});
if(point){
correctAns = options[listArray.indexOf(item)];
console.log("正确答案是:" + correctAns);
}else{
// console.log("没找到");
}
}); */
hasClicked = true;
// 更新题库
// delay(1);
if (correctAns) //如果答案不是null,就更新题库
{
if (answer == "") {
var sql = "INSERT INTO tiku (question, option, answer, wrongAnswer) VALUES ('" + question + "','" + correctAns[1] + "','" + correctAns[0] + "','')";
} else {
var sql = "UPDATE tiku SET answer='" + correctAns[0] + "' option='" + correctAns[1] + "' WHERE question LIKE '" + question + "'";
}
// console.log(correctAns);
tikuCommon.insertOrUpdate(sql);
console.log("更新题库答案...");
}
console.log("-------------------------------");
} else //如果找到了答案
{
/* listArray.some(item => {
var listDescStr = item.child(0).child(1).text();
console.error(deleteNO(listDescStr));
if (deleteNO(listDescStr) == answer) {
item.child(0).click(); //点击答案
hasClicked = true;
rightCount++;
console.log("-------------------------------");
return true;
}
}); */
console.info("答案:" + answer);
var optletters = charFromIndex(options.indexOf(answer));
// toastLog(optletters);
var sql = "UPDATE tiku SET option='" + optletters + "' WHERE question LIKE '" + question + "'";
tikuCommon.insertOrUpdate(sql);
// console.log("更新题库答案...");
text(answer).click();
hasClicked = true;
console.log("-------------------------------");
/* var delayTime = 120;
var myColor = "#44BF78";
var myThreshold = 4;
var correctAns = findCorrectAnswer(delayTime, myColor, myThreshold, listArray, options);
delay(1);
if (text("v5IOXn6lQWYTJeqX2eHuNcrPesmSud2JdogYyGnRNxujMT8RS7y43zxY4coWepspQkvw" +
"RDTJtCTsZ5JW+8sGvTRDzFnDeO+BcOEpP0Rte6f+HwcGxeN2dglWfgH8P0C7HkCMJOAAAAAElFTkSuQmCC").exists()) //遇到❌号,则答错了,不再通过结束本局字样判断
{
// var sql = "DELETE FROM tiku WHERE question = '" + question + "'";
// tikuCommon.insertOrUpdate(sql);
// toastLog("答案有误,删除此题!");
console.info("正确答案是:" + correctAns);
let sql = "UPDATE tiku SET answer='" + correctAns + "' WHERE question LIKE '" + question + "'";
tikuCommon.tikuCommon.insertOrUpdate(sql);
toastLog("答案有误,已更正答案!");
} */
}
if (!hasClicked) //如果没有点击成功
{
console.error("未能成功点击,随机点击一个");
let i = random(0, listArray.length - 1);
listArray[i].child(0).click(); //随意点击一个答案
console.log("-------------------------------");
}
}
/*************************************************争上游、双人对战部分*************************************************/
/**
* @description: 答题争上游、双人对战,去掉题目和答案前面的序号
* @param: str 问题或答案
* @return: 去掉序号后的题目或答案
*/
function deleteNO(str) {
/* if (className("android.view.View").textStartsWith("距离答题结束").exists()) {
// console.log(str.slice(3));
return str.slice(3);
} else {
return str;
} */
return str.slice(3);
}
/*************************************************争上游答题部分******************************************************/
/**
* @description: 双人对战答题循环
* @param: conNum 连续答对的次数
* @return: null
*/
function competitionLoop(conNum) {
delaytime4=randomNum(delaytime1, delaytime2)
console.log("延时:"+delaytime4);
sleep(20);
var question = "";
// if (!className("RadioButton").exists() || className("android.view.View").text("继续挑战").exists() || textContains("继续挑战").exists() /*|| !textContains("距离答题结束").exists()*/){//不存在本局结束标志 继续挑战,则执行 20201225界面变化,距离答题结束 删除
// /*console.info("答题结束!");*/ //配合20201225界面变化 距离答题结束 去除,本语句去除
// return;
// }
// className("android.view.View").depth(29).waitFor();
while (question == "") {
try{
// console.error(conNum);
// if (className("ListView").exists()) {
// question = className("ListView").findOnce().parent().child(0).text();
if (className("android.view.View").depth(29).exists() && !text("继续挑战").exists()) {
question = className("android.view.View").depth(29).findOnce().text();
// console.log(question);
// //找题目,防出错
// while ( question == "") {
// delay(0.8);
// if (!className("RadioButton").exists() || className("android.view.View").text("继续挑战").exists() || textContains("继续挑战").exists()) {
// console.info("答题结束!");
// return;
// }else{
// let i = random(0, listArray.length - 1);
// console.error("题目提取失败");
// listArray[i].child(0).click(); //随意点击一个答案
// }
// //找题目
// question = className("android.view.View").depth(29).findOnce().text();
// }
if (question == "") {
return false;
}
if (question.slice(0, question.indexOf(".")) == conNum) {
question = "";
} else {
question = deleteNO(question);
console.log((conNum + 1).toString() + ".题目:" + question);
var chutiIndex = question.lastIndexOf("出题单位");
if (chutiIndex != -1) {
question = question.substring(0, chutiIndex - 2);
}
question = question.replace(/\s/g, "");
// className("ListView").waitFor();
sleep(delaytime4);
var listArray = className("ListView").findOnce().children(); //题目选项列表
// 特殊情况外理
let specialQuestion = ["选择词语的正确词形。", "选择正确的读音。",""]
if (specialQuestion.indexOf(question) > -1) {
question = question + deleteNO(listArray[0].child(0).child(1).text());
}
var answer = tikuCommon.getAnswer(question, 'tiku');
/* if (answer.length == 0) { //tiku表中没有则到tikuNet表中搜索答案
answer = getAnswer(question, 'tikuNet');
} */
/*
if (/^[a-zA-Z]{1}$/.test(answer)) { //如果为ABCD形式
var indexAnsTiku = indexFromChar(answer.toUpperCase());
answer = listArray[indexAnsTiku].child(0).child(1).text();
answer = deleteNO(answer);
toastLog("answer from char=" + answer);
} */
if (question == "") {
console.error("提取题目失败!");
let i = random(0, listArray.length - 1);
console.log("随机点击");
listArray[i].child(0).click();//随意点击一个答案
return;
}
if (text("100").depth(24).exists()) {
toastLog("有人100了");
return;
}
let hasClicked = false;
// let listArray = className("ListView").findOnce().children(); //题目选项列表
if (answer == "") //如果没找到答案
{
let i = random(0, listArray.length - 1);
console.error("没有找到答案,随机点击一个");
listArray[i].child(0).click(); //随意点击一个答案
var options = []; //选项列表
while (options.length == 0) {
if (className("ListView").exists()) {
className("ListView").findOne().children().forEach(child => {
var answer_q = child.child(0).child(1).text();
options.push(answer_q);
});
} else {
console.error("答案获取失败!");
return;
}
}
var delayTime = 1055;
var myColor = "#2BC87E";
var myThreshold = 25;
var correctAns = findCorrectAnswer(delayTime, myColor, myThreshold, listArray, options);
// 更新题库
// delay(1);
if (correctAns) //如果答案不是null,就更新题库
{
correctAns[0] = deleteNO(correctAns[0]);
console.info("正确答案是:" + correctAns[0]);
var sql = "INSERT INTO tiku (question, option, answer, wrongAnswer) VALUES ('" + question + "','" + correctAns[1] + "','" + correctAns[0] + "','')";
// console.log(correctAns);
tikuCommon.insertOrUpdate(sql);
console.log("更新题库答案...");
}
if (correctAns[0] == deleteNO(options[i])) { //listArray[i].child(0).child(1).text()
return true;
}
console.log("-------------------------------");
hasClicked = true;
} else //如果找到了答案
{
console.info("答案:" + answer);
/* listArray.some(item => {
var listDescStr = item.child(0).child(1).text();
console.error(deleteNO(listDescStr));
if (deleteNO(listDescStr) == answer) {
item.child(0).click(); //点击答案
hasClicked = true;
rightCount++;
console.log("-------------------------------");
return true;
}
}); */
if (textEndsWith(answer).exists()) {
/* var optletters = textEndsWith(answer).findOnce().text();
optletters = optletters[0];
toastLog(optletters); */
sleep(30)
textEndsWith(answer).click();
hasClicked = true;
console.log("-------------------------------");
return true;
}
}
//console.error(hasClicked);
if (!hasClicked) //如果没有点击成功
{
console.error("未能成功点击,随机点击一个");
let i = random(0, listArray.length - 1);
listArray[i].child(0).click(); //随意点击一个答案
console.log("-------------------------------");
}
return false;
}
} else {
// console.error("提取题目失败!");
/* let listArray = className("ListView").findOnce().children(); //题目选项列表
let i = random(0, listArray.length - 1);
console.log("随机点击一个");
listArray[i].child(0).click(); //随意点击一个答案 */
// return false;
}
}catch(e){
return;
}
// delay(0.1);
}
}
/**
* @description: 双人对战答题循环
* @param: conNum 连续答对的次数
* @return: null
*/
function competitionLoopnew() {
// var question = "";
// className("android.view.View").depth(29).waitFor();
delaytime4=randomNum(delaytime1, delaytime2)
console.log("延时:"+delaytime4);
sleep(20)
while (className("android.view.View").depth(29).exists() && !text("继续挑战").exists()) {
try {
if (className("android.view.View").depth(29).exists() && !text("继续挑战").exists()) {
var aquestion = className("android.view.View").depth(29).findOnce().text();
var question = deleteNO(aquestion);
}
if (aquestion != oldaquestion && question != "") {
console.log(aquestion.slice(0, aquestion.indexOf(".")) + ".题目:" + question);
var chutiIndex = question.lastIndexOf("出题单位");
if (chutiIndex != -1) {
question = question.substring(0, chutiIndex - 2);
}
question = question.replace(/\s/g, "");
// className("ListView").waitFor();
sleep(delaytime4);
var listArray = className("ListView").findOnce().children(); //题目选项列表
// 特殊情况外理
let specialQuestion = ["选择词语的正确词形。", "选择正确的读音。"]
if (specialQuestion.indexOf(question) > -1) {
question = question + deleteNO(listArray[0].child(0).child(1).text());
}
var answer = tikuCommon.getAnswer(question, 'tiku');
/* if (answer.length == 0) { //tiku表中没有则到tikuNet表中搜索答案
answer = getAnswer(question, 'tikuNet');
} */
/*
if (/^[a-zA-Z]{1}$/.test(answer)) { //如果为ABCD形式
var indexAnsTiku = indexFromChar(answer.toUpperCase());
answer = listArray[indexAnsTiku].child(0).child(1).text();
answer = deleteNO(answer);
toastLog("answer from char=" + answer);
} */
if (text("100").depth(24).exists()) {
toastLog("有人100了");
return;
}
let hasClicked = false;
// let listArray = className("ListView").findOnce().children(); //题目选项列表
if (answer == "") //如果没找到答案
{
let i = random(0, listArray.length - 1);
console.error("没有找到答案,随机点击一个");
listArray[i].child(0).click(); //随意点击一个答案
var options = []; //选项列表
while (options.length == 0) {
if (className("ListView").exists()) {
className("ListView").findOne().children().forEach(child => {
var answer_q = child.child(0).child(1).text();
options.push(answer_q);
});
} else {
console.error("答案获取失败!");
return;
}
}
var delayTime = 1055;
var myColor = "#2BC87E";
var myThreshold = 25;
var correctAns = findCorrectAnswer(delayTime, myColor, myThreshold, listArray, options);
// 更新题库
// delay(1);
if (correctAns) //如果答案不是null,就更新题库
{
correctAns[0] = deleteNO(correctAns[0]);
console.info("正确答案是:" + correctAns[0]);
var sql = "INSERT INTO tiku (question, option, answer, wrongAnswer) VALUES ('" + question + "','" + correctAns[1] + "','" + correctAns[0] + "','')";
// console.log(correctAns);
tikuCommon.insertOrUpdate(sql);
console.log("更新题库答案...");
}
/* if (correctAns[0] == deleteNO(options[i])) { //listArray[i].child(0).child(1).text()
return true;
} */
console.log("-------------------------------");
hasClicked = true;
} else //如果找到了答案
{
console.info("答案:" + answer);
/* listArray.some(item => {
var listDescStr = item.child(0).child(1).text();
console.error(deleteNO(listDescStr));
if (deleteNO(listDescStr) == answer) {
item.child(0).click(); //点击答案
hasClicked = true;
rightCount++;
console.log("-------------------------------");
return true;
}
}); */
if (textEndsWith(answer).exists()) {
/* var optletters = textEndsWith(answer).findOnce().text();
optletters = optletters[0];
toastLog(optletters); */
sleep(30)
textEndsWith(answer).click();
hasClicked = true;
console.log("-------------------------------");
// return true;
}
}
//console.error(hasClicked);
if (!hasClicked) //如果没有点击成功
{
console.error("未能成功点击,随机点击一个");
let i = random(0, listArray.length - 1);
listArray[i].child(0).click(); //随意点击一个答案
console.log("-------------------------------");
}
// return false;
var oldaquestion = aquestion; //对比新旧题目
}else{
console.error("提取题目失败!");
let listArray = className("ListView").findOnce().children();//题目选项列表
let i = random(0, listArray.length - 1);
console.log("随机点击");
listArray[i].child(0).click();//随意点击一个答案
return;
}
} catch (e) {
logDefault(e); //输出错误信息,调试用
logError("出现错误,请检查3!");
return;
}
}
}
/*************************************************每日答题部分***************************************************/
/**
* @description: 获取填空题题目数组
* @param: null
* @return: questionArray
*/
function getFitbQuestion() {
var questionCollections = className("EditText").findOnce().parent().parent();
var questionArray = [];
var findBlank = false;
var blankCount = 0;
var blankNumStr = "";
var i = 0;
questionCollections.children().forEach(item => {
if (item.className() != "android.widget.EditText") {
if (item.text() != "") { //题目段
if (findBlank) {
blankNumStr = "|" + blankCount.toString();
questionArray.push(blankNumStr);
findBlank = false;
}
questionArray.push(item.text());
} else {
findBlank = true;
blankCount = (className("EditText").findOnce(i).parent().childCount() - 1);
i++;
}
}
});
/* questionArray.forEach( item=> {
console.log(item);
}) */
return questionArray;
}
/**
* @description: 获取选择题题目数组
* @param: null
* @return: questionArray
*/
function getChoiceQuestion() {
var questionCollections = className("ListView").findOnce().parent().child(1);
var questionArray = [];
questionArray.push(questionCollections.text());
return questionArray;
}
/**
* @description: 获取提示字符串
* @param: null
* @return: tipsStr
*/
function getTipsStr() {
var tipsStr = "";
while (tipsStr == "") {
if (text("查看提示").exists()) {
var seeTips = text("查看提示").findOnce();
seeTips.click();
delay(1);
click(device.width * 0.5, device.height * 0.41);
delay(1);
click(device.width * 0.5, device.height * 0.35);
} else {
console.error("未找到查看提示");
}
if (text("提示").exists()) {
var tipsLine = text("提示").findOnce().parent();
//获取提示内容
if (tipsLine.parent().child(1).child(0).text() == "") {
var tipsViewArray = tipsLine.parent().child(1).child(0).children();
} else {
var tipsViewArray = tipsLine.parent().child(1).children();
}
tipsViewArray.forEach(item => {
if (item.text().substr(0, 2) != "--" || item.text().substr(0, 2) != "来源") {
tipsStr += item.text();
}
})
// console.log("提示:" + tipsStr);
//关闭提示
tipsLine.child(1).click();
break;
}
delay(1);
}
return tipsStr;
}
/**
* @description: 从提示中获取填空题答案
* @param: timu, tipsStr
* @return: ansTips
*/
function getAnswerFromTips(timu, tipsStr) {
var ansTips = "";
for (var i = 1; i < timu.length - 1; i++) {
if (timu[i].charAt(0) == "|") {
var blankLen = timu[i].substring(1);
var indexKey = tipsStr.indexOf(timu[i + 1]);
var ansFind = tipsStr.substr(indexKey - blankLen, blankLen);
ansTips += ansFind;
}
}
return ansTips;
}
/**
* @description: 根据提示点击选择题选项
* @param: tipsStr
* @return: clickStr
*/
function clickByTips(tipsStr) {
var clickStr = "";
var correctAnswerStr = "";
var isFind = false;
if (className("ListView").exists()) {
var listArray = className("ListView").findOne().children();
listArray.forEach(item => {
var ansStr = item.child(0).child(2).text();
if (tipsStr.indexOf(ansStr) >= 0) {
item.child(0).click();
clickStr += item.child(0).child(1).text().charAt(0);
correctAnswerStr = ansStr;
isFind = true;
}
});
if (!isFind) { //没有找到 随机点击一个
console.error("未能成功点击,随机点击一个");
let i = random(0, listArray.length - 1);
listArray[i].child(0).click();
clickStr += listArray[i].child(0).child(1).text().charAt(0);
correctAnswerStr = listArray[i].child(0).child(2).text();
}
}
if (textStartsWith("单选题").exists()) {
return correctAnswerStr;
} else {
return clickStr;
}
}
/**
* @description: 根据答案点击选择题选项
* @param: answer
* @return: null
*/
function clickByAnswer(answer) {
var hasClicked = false;
if (className("ListView").exists()) {
var listArray = className("ListView").findOnce().children();
listArray.forEach(item => {
var listIndexStr = item.child(0).child(1).text().charAt(0);
//单选答案为非ABCD
var listDescStr = item.child(0).child(2).text();
// console.log(listDescStr)
if (answer == listDescStr) {
item.child(0).click();
hasClicked = true;
} else if (answer.indexOf(listIndexStr) >= 0) {
item.child(0).click();
hasClicked = true;
}
});
if (!hasClicked) { //没有找到 随机点击一个
console.error("未能成功点击,随机点击一个");
let i = random(0, listArray.length - 1);
listArray[i].child(0).click();
// clickStr += listArray[i].child(0).child(1).text().charAt(0);
// correctAnswerStr = listArray[i].child(0).child(2).text();
}
}
}
/**
* @description: 检查答案是否正确,并更新数据库
* @param: question, ansTiku, answer
* @return: null
*/
function checkAndUpdate(question, ansTiku, answer) {
try{
if (text("下一题").exists() || text("完成").exists()) { //答错了
swipe(100, device.height - 100, 100, 100, 500);
var nCount = 0
while (nCount < 5) {
if (textStartsWith("正确答案").exists()) {
var correctAns = textStartsWith("正确答案").findOnce().text().substr(6);
if (textStartsWith("单选题").exists()) {
//单选题选项
var optletters = correctAns;
// 单选题答案
var alpha = "ABCDEF";
let indexList = alpha.indexOf(correctAns);
var listArray = className("ListView").findOne().children();
// 找到答案项
correctAns = listArray[indexList].child(0).child(2).text();
}
console.info("正确答案是:" + correctAns);
if (ansTiku == "") { //题库为空则插入正确答案
var sql = "INSERT INTO tiku (question, option, answer, wrongAnswer) VALUES ('" + question + "','" + optletters + "','" + correctAns + "','')";
} else { //更新题库答案
var sql = "UPDATE tiku SET answer='" + correctAns + "' option='" + optletters + "' WHERE question LIKE '" + question + "'";
}
tikuCommon.insertOrUpdate(sql);
console.log("更新题库答案...");
delay(1);
break;
} else {
var clickPos = className("android.webkit.WebView").findOnce().child(2).child(0).child(1).bounds();
click(clickPos.left + device.width * 0.13, clickPos.top + device.height * 0.1);
console.error("未捕获正确答案,尝试修正");
}
nCount++;
}
if (className("Button").exists()) {
className("Button").findOnce().click();
} else {
click(device.width * 0.85, device.height * 0.06);
}
} else { //正确后进入下一题,或者进入再来一局界面
if (ansTiku == "" && answer != "") { //正确进入下一题,且题库答案为空
var sql = "INSERT INTO tiku (question, option, answer, wrongAnswer) VALUES ('" + question + "', '','" + answer + "','')";
tikuCommon.insertOrUpdate(sql);
console.log("更新题库答案...");
}
}
}catch(e){
return;
}
}
/**
* @description: 每日答题循环
* @param: null
* @return: null
*/
function dailyQuestionLoop() {
if (textStartsWith("填空题").exists()) {
var questionType = "填空题:"; //questionType题型是什么
var questionArray = getFitbQuestion();
//console.log('填空题')
} else if (textStartsWith("多选题").exists()) {
var questionType = "多选题:";
var questionArray = getChoiceQuestion();
//console.log('选择题')
} else if (textStartsWith("单选题").exists()) {
var questionType = "单选题:";
var questionArray = getChoiceQuestion();
}
var blankArray = [];
var question = "";
questionArray.forEach(item => {
if (item != null && item.charAt(0) == "|") { //是空格数
blankArray.push(item.substring(1));
} else { //是题目段
question += item;
}
});
question = question.replace(/\s/g, "");
console.log(questionType + question);
// 特殊情况外理
let specialQuestion = ["选择词语的正确词形。", "选择正确的读音。"]
if (specialQuestion.indexOf(question) > -1) {
question = question + className("ListView").findOnce().child(0).child(0).child(2).text();
}
var ansTiku = tikuCommon.getAnswer(question, 'tiku');
/* if (ansTiku.length == 0) {//tiku表中没有则到tikuNet表中搜索答案
ansTiku = getAnswer(question, 'tikuNet');
} */
var answer = ansTiku.replace(/(^\s*)|(\s*$)/g, "");
if (textStartsWith("填空题").exists()) {
if (answer == "") {
var tipsStr = getTipsStr();
answer = getAnswerFromTips(questionArray, tipsStr);
console.info("提示中的答案:" + answer);
setText(0, answer.substr(0, blankArray[0]));
if (blankArray.length > 1) {
for (var i = 1; i < blankArray.length; i++) {
setText(i, answer.substr(blankArray[i - 1], blankArray[i]));
}
}
} else {
console.info("答案:" + answer);
setText(0, answer.substr(0, blankArray[0]));
if (blankArray.length > 1) {
for (var i = 1; i < blankArray.length; i++) {
setText(i, answer.substr(blankArray[i - 1], blankArray[i]));
}
}
}
} else if (textStartsWith("多选题").exists() || textStartsWith("单选题").exists()) {
if (answer == "") {
var tipsStr = getTipsStr();
answer = clickByTips(tipsStr);
console.info("提示中的答案:" + answer);
} else {
console.info("答案:" + ansTiku);
clickByAnswer(answer);
}
}
delay(1.5);
if (text("确定").exists()) {
text("确定").click();
delay(0.5);
} else if (text("下一题").exists()) {
click("下一题");
delay(0.5);
} else if (text("完成").exists()) {
text("完成").click();
delay(0.5);
} else {
console.warn("未找到右上角确定按钮控件,根据坐标点击");
click(device.width * 0.85, device.height * 0.06); //右上角确定按钮,根据自己手机实际修改
}
checkAndUpdate(question, ansTiku, answer);
console.log("---------------------");
delay(2);
}
exports.randomNum = randomNum;
exports.challengeQuestionLoop = challengeQuestionLoop;
exports.competitionLoop = competitionLoop;
exports.dailyQuestionLoop = dailyQuestionLoop;