Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update 学习强国.js #174

Open
wants to merge 2 commits into
base: version-14.2
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 21 additions & 13 deletions 学习强国.js
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,22 @@ media.resumeMusic();
back_track_flag = 2;
// 注意:四人赛和双人对战因无法获取题目,需要ocr

/**
* 等待需要点击的选项出现,如果出现 第?题、继续挑战,就break
* @param {int} option 第?个选项
*/
function waitForRadioButton(optionIndex) {
var endNow = 0
while(!className('android.widget.RadioButton').depth(32).exists()) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里貌似并没有解决控件因为某种原因没检测出来卡死的原因
如果检测不出来waitFor()会卡死,但你的while循环也退不出来啊
另外这里的depth()不能写死为32,因为挑战答题的是28

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

挑战答题写成28就好了啊。

我写了以后就从来没有卡死过。
因为检测不到radioButton的情况就是答题结束或者控件未出现

if(textMatches(/第\d题/).exists() || text('继续挑战').exists()) {
endNow = 1;
break;
}
};
if (endNow == 0) className('android.widget.RadioButton').depth(32).findOnce(optionIndex).click();
slp(1.8);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

slp(1.8)是啥意思呢,sleep()?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我直接复制过来的,就是延时函数

}

/**
* 答题
* @param {int} depth_option 选项控件的深度
Expand All @@ -387,8 +403,7 @@ back_track_flag = 2;
function do_contest_answer(depth_option, question) {
if (question == "选择正确的读音" || question == "选择词语的正确词形" || question == "下列词形正确的是") {
// 选择第一个
className('android.widget.RadioButton').depth(depth_option).waitFor();
className('android.widget.RadioButton').depth(depth_option).findOne().click();
waitForRadioButton(0)
} else {
var result;
// 发送http请求获取答案 网站搜题速度 r1 > r2
Expand All @@ -406,18 +421,12 @@ function do_contest_answer(depth_option, question) {
}
}

className('android.widget.RadioButton').depth(depth_option).waitFor();

if (result) {
try {
className('android.widget.RadioButton').depth(depth_option).findOnce(result[0].charCodeAt(3) - 65).click();
} catch (error) {
// 如果选项不存在,则点击第一个
className('android.widget.RadioButton').depth(depth_option).findOne().click();
}
answer = result[0].charCodeAt(3) - 65
waitForRadioButton(answer)
} else {
// 如果没找到结果则选择第一个
className('android.widget.RadioButton').depth(depth_option).findOne().click();
waitForRadioButton(0)
}
}
}
Expand Down Expand Up @@ -1110,8 +1119,7 @@ function do_contest() {
log(question);
if (question) do_contest_answer(32, question);
else {
className('android.widget.RadioButton').depth(32).waitFor();
className('android.widget.RadioButton').depth(32).findOne().click();
waitForRadioButton(0)
}
// 等待新题目加载
while (!textMatches(/第\d题/).exists() && !text('继续挑战').exists() && !text('开始').exists());
Expand Down