├── tiku.db
├── res
└── logo.png
├── jsoup-1.13.1.jar
├── main.js
├── README.md
├── project.json
├── sql.txt
├── tikuCommon.js
├── updateTikuNet.js
├── !floating.js
├── !NO_UI.js
├── LICENSE
├── UI.js
├── !zsyTzAnswer.js
└── !xxqg_v3.1.3(fixall).js
/tiku.db:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wanghuisenior/auto_xxqg/HEAD/tiku.db
--------------------------------------------------------------------------------
/res/logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wanghuisenior/auto_xxqg/HEAD/res/logo.png
--------------------------------------------------------------------------------
/jsoup-1.13.1.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wanghuisenior/auto_xxqg/HEAD/jsoup-1.13.1.jar
--------------------------------------------------------------------------------
/main.js:
--------------------------------------------------------------------------------
1 | //engines.execScriptFile("!NO_UI.js");
2 | //engines.execScriptFile("!floating.js");//可选择浮动菜单启动
3 | engines.execScriptFile("UI.js");
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # auto_xxqg
2 | ### 2020.01.04 优化
3 | ### 2020.12.30 发现各路大神改的代码都不太好用,我也改了一版,优化了非常多东西,整合了网络题库,同时题库存放在sdcard内无需每次安装都重置了,添加了服务器上传开关及刷题开关(上传到我自己的服务器上,刷题刷到自己tiku),支持多账户一键答题。文章阅读每个账号不干扰。但autojs是平时看的,不太会,所以订阅部分或者其他bug不太好改。正考虑是不是放源码出来
4 | # auto_xxqg
5 | ### Android9 MIUI11.0.3稳定版测试完美42分,app版本v2.14.1,version20200620
6 | ###
7 | ### 发现大神改的更nb一点,直接用人家的了,此版本可能不再更新了
8 | ### 传送门 https://github.com/lolisaikou/LazyStudy 很好用!!
9 |
--------------------------------------------------------------------------------
/project.json:
--------------------------------------------------------------------------------
1 | {
2 | "assets": [],
3 | "build": {
4 | "build_id": "99F82FE1-141",
5 | "build_number": 141,
6 | "build_time": 1608281774894
7 | },
8 | "useFeatures": [],
9 | "icon": "res/logo.png",
10 | "launchConfig": {
11 | "hideLogs": false
12 | },
13 | "main": "main.js",
14 | "name": "强国助手",
15 | "packageName": "com.auto_xxqg",
16 | "scripts": {},
17 | "versionCode": 20201218,
18 | "versionName": "2.19.0"
19 | }
--------------------------------------------------------------------------------
/sql.txt:
--------------------------------------------------------------------------------
1 | 1、查询问题相同的数据
2 | SELECT
3 | question,answer
4 | FROM
5 | tiku
6 | GROUP BY
7 | question
8 |
9 | HAVING
10 | count( question ) > 1
11 |
12 |
13 | 2、删除表中问题和答案相同的记录,只保留rowid最小的一条
14 | DELETE
15 | FROM
16 | tiku
17 | WHERE
18 | ( tiku.question, tiku.answer ) IN ( SELECT question, answer FROM tiku GROUP BY question, answer HAVING count( * ) > 1 )
19 | AND rowid NOT IN (
20 | SELECT
21 | min( rowid )
22 | FROM
23 | tiku
24 | GROUP BY
25 | question,
26 | answer
27 | HAVING
28 | count( * ) > 1)
29 |
30 |
31 | 3、 把tikuNet表里的数据复制到tiku
32 | INSERT INTO tiku ( question, answer ) SELECT
33 | question,
34 | answer
35 | FROM
36 | tikuNet
--------------------------------------------------------------------------------
/tikuCommon.js:
--------------------------------------------------------------------------------
1 | importClass(android.database.sqlite.SQLiteDatabase);
2 | var path=files.path("/sdcard/Download/tiku.db");
3 | function searchTiku(keyw) {
4 | //表名
5 | var tableName = "tiku";
6 | var ansArray = searchDb(keyw, tableName, "");
7 | return ansArray;
8 |
9 | }
10 |
11 | function searchDb(keyw, _tableName, queryStr) {
12 | var tableName = _tableName;
13 | //创建或打开数据库
14 | var db = SQLiteDatabase.openOrCreateDatabase(path, null);
15 | var query = "";
16 | if (queryStr == "") {
17 | query = "SELECT question,answer FROM " + tableName + " WHERE question LIKE '" + keyw + "%'";//前缀匹配
18 | } else {
19 | query = queryStr;
20 | }
21 |
22 | log(query);
23 | //query="select * from tiku"
24 | //db.execSQL(query);
25 |
26 | var cursor = db.rawQuery(query, null);
27 | cursor.moveToFirst();
28 | var ansTiku = [];
29 | if (cursor.getCount() > 0) {
30 | do {
31 | var timuObj={"question" : cursor.getString(0),"answer":cursor.getString(1)};
32 | ansTiku.push(timuObj);
33 | } while (cursor.moveToNext());
34 | } else {
35 | log("题库中未找到: " + keyw);
36 | }
37 | cursor.close();
38 | return ansTiku;
39 |
40 | }
41 |
42 | function executeSQL(sqlstr) {
43 | //创建或打开数据库
44 | var db = SQLiteDatabase.openOrCreateDatabase(path, null);
45 | db.execSQL(sqlstr);
46 | toastLog(sqlstr);
47 | db.close();
48 | }
49 |
50 |
51 | function indexFromChar(str) {
52 | return str.charCodeAt(0) - "A".charCodeAt(0);
53 | }
54 |
55 | function searchNet(keyw) {
56 | var tableName = "tikuNet";
57 | var ansArray = searchDb(keyw, tableName, "");
58 | return ansArray;
59 | }
60 |
61 | exports.searchTiku = searchTiku;
62 | exports.searchNet = searchNet;
63 | exports.searchDb = searchDb;
64 | exports.indexFromChar = indexFromChar;
65 | exports.executeSQL = executeSQL;
66 |
67 |
68 |
69 |
70 |
71 |
--------------------------------------------------------------------------------
/updateTikuNet.js:
--------------------------------------------------------------------------------
1 | // 加载jsoup.jar
2 | runtime.loadJar("./jsoup-1.13.1.jar");
3 | // 使用jsoup解析html
4 | importClass(org.jsoup.Jsoup);
5 | importClass(org.jsoup.nodes.Document);
6 | //importClass(org.jsoup.nodes.Element);
7 | importClass(org.jsoup.select.Elements);
8 |
9 | importClass(android.database.sqlite.SQLiteDatabase);
10 | /**
11 | * 插入tikuNet表
12 | * @param {} liArray li列表,包含题目和答案
13 | */
14 | function CreateAndInsert(liArray) {
15 |
16 | var dbName = "/sdcard/Download/tiku.db";
17 | //文件路径
18 | var path = files.path(dbName);
19 | //确保文件存在
20 | if (!files.exists(path)) {
21 | files.createWithDirs(path);
22 | }
23 | //创建或打开数据库
24 | var db = SQLiteDatabase.openOrCreateDatabase(path, null);
25 | var createTable = "\
26 | CREATE TABLE IF NOt EXISTS tikuNet(\
27 | question CHAR(253),\
28 | answer CHAR(100)\
29 | );";
30 | var cleanTable = "DELETE FROM tikuNet";
31 | db.execSQL(createTable);
32 | db.execSQL(cleanTable);
33 | log("创建打开清空表tikuNet!");
34 |
35 | var sql = "INSERT INTO tikuNet (question, answer) VALUES (?, ?)";
36 | db.beginTransaction();
37 | var stmt = db.compileStatement(sql);
38 | for (var li = 0, len = liArray.size(); li < len; li++) {
39 | //log("题目:"+li.text());
40 |
41 | var liText = liArray.get(li).text();
42 | var timuPos = liText.indexOf("】");
43 | var tiMu = liText.replace(/\s/g, "");
44 | var tiMu = tiMu.substring(timuPos).replace(/_/g, "");
45 | var daAn = liArray.get(li).select("b").first().text();
46 | // log(util.format("题目:%s\n答案:%s"), tiMu, daAn);
47 | stmt.bindString(1, tiMu);
48 | stmt.bindString(2, daAn);
49 | stmt.executeInsert();
50 | stmt.clearBindings();
51 | }
52 | db.setTransactionSuccessful();
53 | db.endTransaction();
54 | db.close();
55 | return true;
56 | }
57 |
58 |
59 | /**
60 | */
61 | function updateTikunet() {
62 | log("开始下载题库数据...");
63 | var htmlString = Jsoup.connect("https://qg.zyqq.top/tiku/").maxBodySize(0).timeout(10000).get();
64 | var htmlArray = Jsoup.parse(htmlString);
65 | var liArray = htmlArray.select("li:has(b)");
66 | //执行更新
67 | log("开始更新数据库...");
68 | if (CreateAndInsert(liArray)) {
69 | log("数据库更新完毕!");
70 | log(util.format("题库下载完毕,题目总数:%s"), liArray.size());
71 | return liArray.size();
72 | } else {
73 | return -1;
74 | }
75 | }
76 | //updateTikunet();
77 | module.exports = updateTikunet;
78 |
79 |
--------------------------------------------------------------------------------
/!floating.js:
--------------------------------------------------------------------------------
1 | //toastLog(" 请在无障碍中选择本 APP");
2 | auto.waitFor();
3 |
4 | let window = floaty.window(
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 | );
13 | //
14 | //
15 | //button id="updateTK" text=" 更新题库 " w="90" h="35" bg="#77ffffff" textSize="10sp" />
16 | let deviceWidth = device.width;
17 | let deviceHeight = device.height;
18 | //window.setPosition(deviceWidth * 0.65, deviceHeight * 0.54);
19 | window.setPosition(deviceWidth * 0.05, deviceHeight * 0.02);
20 | setInterval(() => {
21 | }, 1000);
22 |
23 |
24 | let wx, wy, downTime, windowX, windowY;
25 | // 这个函数是对应悬浮窗的移动
26 | window.move.setOnTouchListener(function (view, event) {
27 | switch (event.getAction()) {
28 | case event.ACTION_DOWN:
29 | wx = event.getRawX();
30 | wy = event.getRawY();
31 | windowX = window.getX();
32 | windowY = window.getY();
33 | downTime = new Date().getTime();
34 | return true;
35 | case event.ACTION_MOVE:
36 | // 如果按下的时间超过 xx 秒判断为长按,调整悬浮窗位置
37 | if (new Date().getTime() - downTime > 300) {
38 | window.setPosition(windowX + (event.getRawX() - wx), windowY + (event.getRawY() - wy));
39 | }
40 | return true;
41 | case event.ACTION_UP:
42 | // 手指弹起时如果偏移很小则判断为点击
43 | if (Math.abs(event.getRawY() - wy) < 30 && Math.abs(event.getRawX() - wx) < 30) {
44 | toastLog(" 长按调整位置 ")
45 | }
46 | return true;
47 | }
48 | return true;
49 | });
50 |
51 | // 这个函数是对应悬浮窗的退出
52 | window.exit.click(() => {
53 | toastLog(" 退出!");
54 | exit();
55 | });
56 |
57 | let th = null;
58 |
59 |
60 | window.goodStudy.click(() => {
61 | //多账号学习
62 | console.log("运行!NO_UI.js")
63 | engines.execScriptFile("!NO_UI.js");
64 | });
65 |
66 | //一键学习
67 | // window.startLL.click(() => {
68 | // let ss = "./!xxqg_v3.1.3(fixall).js";
69 | // startTh(ss);
70 | // });
71 | //手动答题,支持每日、每周、专项、挑战、争上游、双人对战等
72 | window.startDT.click(() => {
73 | try{
74 | let ss = "./!zsyTzAnswer.js"; //手动答题
75 | startTh(ss);
76 | }catch(e){console.error("出现了异常");}
77 | });
78 |
79 | /*
80 | //更新题库
81 | window.updateTK.click(() => {
82 | dialogs.build({
83 | title: "更新网络题库",
84 | content: "更新约耗时几分钟,确定更新?",
85 | positive: "确定",
86 | negative: "取消",
87 | })
88 | .on("positive", update)
89 | .show();
90 |
91 | function update() {
92 | threads.start(function () {
93 | //悬浮提示等待
94 | var w = floaty.rawWindow(
95 |
96 |
97 | ------------
98 | 正在更新题库…
99 | ------------
100 | ###请勿退出###
101 | ------------
102 |
103 |
104 | );
105 | w.setPosition(deviceWidth*0.2, deviceHeight*0.4);
106 | w.setSize(deviceWidth*0.8, deviceHeight*0.24);
107 |
108 | //更新题库
109 | var ss = "./updateTikuNet.js";
110 | //toastLog("正在更新题库,请勿退出…");
111 | let begin = require(ss);
112 | var resultNum = begin();
113 | var resultStr = "更新了" + resultNum + "道题!";
114 | w.close();//关闭悬浮提示
115 | //toastLog(resultStr);
116 | alert(resultStr);//弹出更新结果
117 | });
118 | }
119 | });
120 | */
121 |
122 | //停止
123 | window.stop.click(() => {
124 | engines.stopAllAndToast();
125 | if (th == null) {
126 | toastLog(" 没有进行中的脚本 ");
127 | } else {
128 | if (th.isAlive()) {
129 | threads.shutDownAll();
130 | toastLog(" 停止!");
131 | } else {
132 | toastLog(" 没有进行中的脚本 ");
133 | }
134 | }
135 | });
136 |
137 | function startTh(fileStr) {
138 | var ss = fileStr;
139 | if (th == null) {
140 | th = threads.start(function () {
141 | toastLog(" 开启线程");
142 | let begin = require(ss);
143 | begin();
144 | });
145 | } else {
146 | if (th.isAlive()) {
147 | toastLog(" 脚本都在运行了你还点!?");
148 | } else {
149 | th = threads.start(function () {
150 | let begin = require(ss);
151 | begin();
152 | });
153 | }
154 | }
155 | }
--------------------------------------------------------------------------------
/!NO_UI.js:
--------------------------------------------------------------------------------
1 | /**
2 | *
3 | * ** 更新日志 | 2020.12.1更新:
4 | * * 1.新增微信推送开关,默认开
5 | * * 2.重新启动和登录密码函数
6 | * * 3.新增结束后获取积分
7 | * * 4.修改解锁是否成功的判断
8 | * * 5.相关语句格式调整
9 | * * 6.支持题库备份和导入
10 | *
11 | * 说明:
12 | *
13 | * 1.支持多账号切换和微信推送,同时备份学习进度
14 | * 2.学习进度listX.db请复制list.db改名放在项目目录或备份目录,每次学习完成会自动备份
15 | * 3.微信推送采用pushplus,token可在pushplus网站中可以找到,http://pushplus.hxtrip.com/
16 | * 4.设置你的强国账号和密码,需要在强国APP上登录过(即设备已授权登录)
17 | * 5.复制到auto.js的项目目录,运行或编译即可享用,请授权无障碍和悬浮窗权限
18 | *
19 | * 作者:wanghaha
20 | * 日期:2020.12.1
21 | */
22 | //
23 | //自定义区开始 ================================================================================
24 |
25 | // var xxset = {
26 | // //定义账号和密码对象集,修改或增加账号数量都可以,数量不大于num
27 | // "users": [{
28 | // "username": "18888888888", //账号
29 | // "password": "88888888", //密码
30 | // },],
31 |
32 | // "url": "http://pushplus.hxtrip.com/send", //定义微信推送对象 url+"?token="+token+"&title="+title+"&content="+content
33 | // "token": "de17144cb3be48608fbfea27a5ef0b90", //在pushplus网站登录可以找到自己的token
34 | // "wxpost": 0, //是否微信推送
35 | // "article": "推荐", //文章阅读类型
36 | // "update2server": 0, //是否上传到远程服务器
37 | // "forever": 0, //是否开启无限答题刷题库
38 | // }
39 |
40 | var yjxx = "./!xxqg_v3.1.3(fixall).js"; //一键学习js
41 |
42 | var bakpath = "/sdcard/Download/"; //备份目录,配置文件也保存在该目录
43 |
44 | //自定义区结束 ================================================================================
45 |
46 | var DLog;//记录内容推送用
47 | //配置文件config
48 | var xxset = JSON.parse(files.read(bakpath + "config.txt"));
49 |
50 | //全局函数
51 | //日志记录和弹出提示
52 | function detailLog(str, log) {
53 | var time = new java.text.SimpleDateFormat('HH:mm:ss').format(new Date());
54 | //str = str + "
\n" + time + " " + log;
55 | str = str + "
" + time + " " + log;
56 | console.log(log);
57 | return str;
58 | }
59 |
60 | //登录帐号,10.25重写
61 | function input_xxid(user, password) {
62 | var sign_in = textContains("登录").findOne();
63 | let err = false;
64 | while (!err) { //等待强国主页加载
65 | try {
66 | id("et_phone_input").findOne().setText(user);
67 | id("et_pwd_login").findOne().setText(password);
68 | sign_in = textContains("登录").findOne();
69 | if (sign_in.enabled()) {
70 | click("登录");
71 | err = true;
72 | }
73 | } catch (e) {
74 | console.log(e);
75 | console.error("出现错误,请检查!");
76 | //console.log(currentActivity());
77 | }
78 | }
79 | //click("登录");
80 | var tel = geTel(user);
81 | while (!id("home_bottom_tab_button_work").exists()) {
82 | sleep(2000);
83 | console.log("正在等待加载出主页");
84 | }
85 | DLog = detailLog(DLog, "已成功登录" + tel + "账号");
86 | //back(); //返回,部分密码记录器弹出是否记录(如登录易)
87 | }
88 |
89 | //退出原帐号
90 | function exit_xxid() {
91 | text("我的").findOne().click()
92 | //sleep(2000);
93 | while (!textContains("我的").exists());
94 | id("my_setting").findOne().click();
95 | //sleep(2000);
96 | //退出登录
97 | while (!textContains("退出登录").exists());
98 | click("退出登录");
99 | //sleep(500);
100 | while (!textContains("确认").exists());
101 | click("确认");
102 | console.log("正在退出原帐号…");
103 | //DLog = detailLog(DLog, "正在退出原帐号…");
104 | sleep(1000);
105 | }
106 |
107 | //启动学习强国并切换账号,10.25重写
108 | function change_id(user, password) {
109 | let err = false;
110 | let f;
111 | while (!err) { //等待强国主页加载
112 | try {
113 | if (app.getAppName(currentPackage()) != "学习强国") {//如果强国未启动
114 | console.log("启动学习强国");
115 | if (!launchApp("学习强国")) {//启动学习强国app
116 | console.error("找不到学习强国App!");
117 | return;
118 | }
119 | } else {
120 | //console.log(currentActivity());
121 | if (currentActivity() != "com.alibaba.android.user.login.SignUpWithPwdActivity") {//如果强国界面不为密码登录页
122 | if (currentActivity() == "android.widget.FrameLayout") {//强国主界面
123 | if (id("home_bottom_tab_button_work").exists()) {//如果发现"学习"按钮
124 | //id("home_bottom_tab_button_work").findOne().click();//点击主页正下方的"学习"按钮
125 | err = true;
126 | }
127 |
128 | } else {
129 | if (text("退出").exists()) {//退出按钮
130 | //console.log('退出');
131 | var clickExit = text("退出").findOnce().click();
132 | //console.log(clickExit);
133 | if (!clickExit) {
134 | if (className("Button").exists()) {//退出按钮
135 | className("Button").findOnce().click();
136 | }
137 | }
138 | }
139 | back();
140 | }
141 | } else {
142 | input_xxid(user, password);
143 | return;
144 | }
145 | if (f == 3) {
146 | console.log("等待加载出主页");
147 | f = 0;
148 | }
149 | }
150 | sleep(1000);
151 | f++;
152 | } catch (e) {//如果出错?
153 | //console.log(e);
154 | console.error("出现错误,请检查!");
155 | }
156 | }
157 | exit_xxid();
158 | input_xxid(user, password);
159 | }
160 |
161 | //运行线程
162 | function start_xx(ss) {
163 | threads.shutDownAll();//关闭所有线程
164 | let begin = require(ss);//运行线程
165 | begin(); //运行线程
166 | }
167 |
168 | //微信推送
169 | function pushwx(title, content) {
170 | //发送日志post
171 | var wxsend = http.post(xxset.url, {
172 | "token": xxset.token,
173 | "title": title,
174 | "content": content,
175 | "topic":"0001",
176 | headers: { "Content-Type": "application/json" }
177 | });
178 | return wxsend;
179 | }
180 |
181 | //手机号码中间4位*号处理
182 | function geTel(tel) {
183 | //return tel.substring(0, 3) + "****" + tel.substr(tel.length - 4);
184 | return tel;
185 | }
186 |
187 | //获取积分
188 | function getXXScores(text) {
189 | //launchApp("学习强国");
190 | while (!id("home_bottom_tab_button_work").exists());//等待加载出主页
191 | id("home_bottom_tab_button_work").findOne().click();//点击主页正下方的"学习"按钮
192 | console.log("正在获取积分...");
193 | while (!id("comm_head_xuexi_score").exists());
194 | id("comm_head_xuexi_score").findOnce().click();
195 | sleep(2000);
196 | let err = false;
197 | while (!err) {
198 | try {
199 | text = textContains("今日已累积").findOne().text();
200 | text = text.match(/\d+/g)[0];//累计学习积分
201 | if (!isNaN(text)) {
202 | err = true;
203 | }
204 | } catch (e) {
205 | //console.log(e);
206 | console.log("正在重试获取积分...");
207 | }
208 | sleep(1000);
209 | }
210 | while (!id("home_bottom_tab_button_work").exists()) {
211 | back();
212 | sleep(500);
213 | }
214 | return text;
215 | }
216 |
217 | //是否解锁?
218 | function isScreenLocked() {
219 | importClass(android.app.KeyguardManager)
220 | importClass(android.content.Context)
221 | var km = context.getSystemService(Context.KEYGUARD_SERVICE);
222 | //console.log("is keyguard locked:"+km.isKeyguardLocked());
223 | //console.log("is keyguard secure:"+km.isKeyguardSecure());
224 | //return km.isKeyguardLocked()&&km.isKeyguardSecure();; //屏幕是否锁?是否已启用密码等
225 | return km.isKeyguardLocked();
226 | }
227 |
228 | function wakeUpdevice() {
229 | //唤醒并解锁(用于定时任务)
230 | if (!device.isScreenOn()) {//需要解锁
231 | sleep(1500);
232 | device.wakeUpIfNeeded();
233 | device.wakeUp();//唤醒
234 | if (device.device == "HLTE202N") {
235 | //海信A5,数字解锁,可参考修改,含下面的上滑解锁
236 | desc(2).findOne().click();
237 | desc(5).findOne().click();
238 | desc(6).findOne().click();
239 | desc(9).findOne().click();
240 | desc(8).findOne().click();
241 | desc(0).findOne().click();
242 | }
243 | if (device.device == "markw") {
244 | //红米4高配版,魔趣,上滑解锁
245 | swipe(device.width / 2, device.height - 100, device.width / 2, device.height / 3, 300);
246 | }
247 | //解锁屏幕成功与否?
248 | sleep(1500);
249 | if (!isScreenLocked()) {
250 | DLog = detailLog(DLog, "屏幕解锁成功");
251 | return true;
252 | } else {
253 | DLog = detailLog(DLog, "## 屏幕解锁不成功,请检查 ##");
254 | return false;
255 | }
256 | }
257 | return true;//处于屏幕激活状态,不需要解锁
258 | }
259 |
260 | function main() {
261 | //等待无障碍权限
262 | auto.waitFor();
263 | //控制台显示
264 | console.setPosition(0, device.height / 2);//部分华为手机console有bug请注释本行
265 | console.show();//部分华为手机console有bug请注释本行
266 | console.log("执行!NO_UI.js");
267 | let Scores=0;
268 | //定义变量,推送信息的开始行
269 | if (xxset.users.length > 1) {
270 | var titlemsg = "多账号懒人学习";
271 |
272 | } else {
273 | var titlemsg = "一键懒人学习";
274 | }
275 |
276 | DLog = "《" + new java.text.SimpleDateFormat('yyyy-MM-dd').format(new Date()) + " | " + titlemsg + "日志》";
277 |
278 | //唤醒屏幕开始
279 | if (!wakeUpdevice()) {
280 | if (xxset.wxpost) {
281 | //微信推送失败情况
282 | var nowtime = new java.text.SimpleDateFormat('HH:mm:ss').format(new Date());
283 | var title = nowtime + " 自动启动懒人学习失败";
284 | var content = DLog;
285 | var wxsend = pushwx(title, content);
286 | }
287 | //关闭悬浮窗
288 | //console.clear();
289 | console.hide();
290 | //退出
291 | exit();
292 | }
293 |
294 | DLog = detailLog(DLog, "### 正在启动一键学习 ###");
295 | DLog = detailLog(DLog, "备份目录为:" + bakpath);
296 |
297 | //循环完成多账户答题
298 | for (var i = 0; i < xxset.users.length; i++) {
299 | //手机号码*处理
300 | var tel = geTel(xxset.users[i].username);
301 | DLog = detailLog(DLog, (i+1).toString() + ".==开始" + tel + "学习==");
302 |
303 | if (xxset.users.length > 1) {//切换账号
304 | change_id(xxset.users[i].username, xxset.users[i].password);
305 | }
306 | start_xx(yjxx); //一键答题
307 | //获取积分
308 | Scores = getXXScores(Scores);
309 | DLog = detailLog(DLog, tel + "今日获得" + Scores + "积分");
310 | DLog = detailLog(DLog, "完成" + tel + "帐号的学习");
311 | }
312 |
313 |
314 | //获取电量
315 | var battery = device.getBattery();
316 | DLog = detailLog(DLog, "设备当前电量:" + battery);
317 | if (battery < 30) {
318 | //发送需要充电通知
319 | DLog = detailLog(DLog, "需要充电了");
320 | }
321 |
322 | //推送信息的结束行
323 | DLog = detailLog(DLog, "### 已完成" + titlemsg + " ###");
324 |
325 | //微信推送学习情况
326 | if (xxset.wxpost) {
327 | var nowtime = new java.text.SimpleDateFormat('HH:mm').format(new Date());
328 | var title = nowtime +" "+tel+" 已完成" + Scores + "分:" + titlemsg;
329 | var content = DLog;
330 | var wxsend = pushwx(title, content);
331 | //发送成功与否?
332 | if (wxsend.statusCode == 200) {
333 | DLog = detailLog(DLog, "--== 已成功推送到微信 ==--"); //成功发送日志
334 | } else {
335 | DLog = detailLog(DLog, "+++ 微信推送失败,请检查 +++");
336 | }
337 | }
338 |
339 | //返回桌面
340 | if (device.device == "HLTE202N") {//海信A5
341 | while (currentPackage() != "com.hmct.vision" && currentPackage() != "com.hmct.einklauncher") {
342 | back();
343 | DLog = detailLog(DLog, "返回");
344 | sleep(500);
345 | }
346 | }
347 | if (device.device == "markw") {//魔趣桌面,备用机型
348 | while (currentPackage() != "ch.deletescape.lawnchair.mokee" && currentPackage() != "ch.deletescape.lawnchair.LawnchairLauncher") {
349 | back();
350 | DLog = detailLog(DLog, "返回");
351 | sleep(500);
352 | }
353 | }
354 |
355 | //停止相关线程
356 | threads.shutDownAll();
357 | //等待10秒
358 | sleep(10 * 1000);
359 | //关闭悬浮窗
360 | //console.clear();
361 | console.hide();
362 |
363 | if (xxset.floating) {
364 | //打开悬浮菜单
365 | toast("### 可手动运行 每日答题等 进行学习 ###");
366 | engines.execScriptFile("./!floating.js");
367 | }
368 | }
369 | main();
370 |
371 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 2, June 1991
3 |
4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
6 | Everyone is permitted to copy and distribute verbatim copies
7 | of this license document, but changing it is not allowed.
8 |
9 | Preamble
10 |
11 | The licenses for most software are designed to take away your
12 | freedom to share and change it. By contrast, the GNU General Public
13 | License is intended to guarantee your freedom to share and change free
14 | software--to make sure the software is free for all its users. This
15 | General Public License applies to most of the Free Software
16 | Foundation's software and to any other program whose authors commit to
17 | using it. (Some other Free Software Foundation software is covered by
18 | the GNU Lesser General Public License instead.) You can apply it to
19 | your programs, too.
20 |
21 | When we speak of free software, we are referring to freedom, not
22 | price. Our General Public Licenses are designed to make sure that you
23 | have the freedom to distribute copies of free software (and charge for
24 | this service if you wish), that you receive source code or can get it
25 | if you want it, that you can change the software or use pieces of it
26 | in new free programs; and that you know you can do these things.
27 |
28 | To protect your rights, we need to make restrictions that forbid
29 | anyone to deny you these rights or to ask you to surrender the rights.
30 | These restrictions translate to certain responsibilities for you if you
31 | distribute copies of the software, or if you modify it.
32 |
33 | For example, if you distribute copies of such a program, whether
34 | gratis or for a fee, you must give the recipients all the rights that
35 | you have. You must make sure that they, too, receive or can get the
36 | source code. And you must show them these terms so they know their
37 | rights.
38 |
39 | We protect your rights with two steps: (1) copyright the software, and
40 | (2) offer you this license which gives you legal permission to copy,
41 | distribute and/or modify the software.
42 |
43 | Also, for each author's protection and ours, we want to make certain
44 | that everyone understands that there is no warranty for this free
45 | software. If the software is modified by someone else and passed on, we
46 | want its recipients to know that what they have is not the original, so
47 | that any problems introduced by others will not reflect on the original
48 | authors' reputations.
49 |
50 | Finally, any free program is threatened constantly by software
51 | patents. We wish to avoid the danger that redistributors of a free
52 | program will individually obtain patent licenses, in effect making the
53 | program proprietary. To prevent this, we have made it clear that any
54 | patent must be licensed for everyone's free use or not licensed at all.
55 |
56 | The precise terms and conditions for copying, distribution and
57 | modification follow.
58 |
59 | GNU GENERAL PUBLIC LICENSE
60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
61 |
62 | 0. This License applies to any program or other work which contains
63 | a notice placed by the copyright holder saying it may be distributed
64 | under the terms of this General Public License. The "Program", below,
65 | refers to any such program or work, and a "work based on the Program"
66 | means either the Program or any derivative work under copyright law:
67 | that is to say, a work containing the Program or a portion of it,
68 | either verbatim or with modifications and/or translated into another
69 | language. (Hereinafter, translation is included without limitation in
70 | the term "modification".) Each licensee is addressed as "you".
71 |
72 | Activities other than copying, distribution and modification are not
73 | covered by this License; they are outside its scope. The act of
74 | running the Program is not restricted, and the output from the Program
75 | is covered only if its contents constitute a work based on the
76 | Program (independent of having been made by running the Program).
77 | Whether that is true depends on what the Program does.
78 |
79 | 1. You may copy and distribute verbatim copies of the Program's
80 | source code as you receive it, in any medium, provided that you
81 | conspicuously and appropriately publish on each copy an appropriate
82 | copyright notice and disclaimer of warranty; keep intact all the
83 | notices that refer to this License and to the absence of any warranty;
84 | and give any other recipients of the Program a copy of this License
85 | along with the Program.
86 |
87 | You may charge a fee for the physical act of transferring a copy, and
88 | you may at your option offer warranty protection in exchange for a fee.
89 |
90 | 2. You may modify your copy or copies of the Program or any portion
91 | of it, thus forming a work based on the Program, and copy and
92 | distribute such modifications or work under the terms of Section 1
93 | above, provided that you also meet all of these conditions:
94 |
95 | a) You must cause the modified files to carry prominent notices
96 | stating that you changed the files and the date of any change.
97 |
98 | b) You must cause any work that you distribute or publish, that in
99 | whole or in part contains or is derived from the Program or any
100 | part thereof, to be licensed as a whole at no charge to all third
101 | parties under the terms of this License.
102 |
103 | c) If the modified program normally reads commands interactively
104 | when run, you must cause it, when started running for such
105 | interactive use in the most ordinary way, to print or display an
106 | announcement including an appropriate copyright notice and a
107 | notice that there is no warranty (or else, saying that you provide
108 | a warranty) and that users may redistribute the program under
109 | these conditions, and telling the user how to view a copy of this
110 | License. (Exception: if the Program itself is interactive but
111 | does not normally print such an announcement, your work based on
112 | the Program is not required to print an announcement.)
113 |
114 | These requirements apply to the modified work as a whole. If
115 | identifiable sections of that work are not derived from the Program,
116 | and can be reasonably considered independent and separate works in
117 | themselves, then this License, and its terms, do not apply to those
118 | sections when you distribute them as separate works. But when you
119 | distribute the same sections as part of a whole which is a work based
120 | on the Program, the distribution of the whole must be on the terms of
121 | this License, whose permissions for other licensees extend to the
122 | entire whole, and thus to each and every part regardless of who wrote it.
123 |
124 | Thus, it is not the intent of this section to claim rights or contest
125 | your rights to work written entirely by you; rather, the intent is to
126 | exercise the right to control the distribution of derivative or
127 | collective works based on the Program.
128 |
129 | In addition, mere aggregation of another work not based on the Program
130 | with the Program (or with a work based on the Program) on a volume of
131 | a storage or distribution medium does not bring the other work under
132 | the scope of this License.
133 |
134 | 3. You may copy and distribute the Program (or a work based on it,
135 | under Section 2) in object code or executable form under the terms of
136 | Sections 1 and 2 above provided that you also do one of the following:
137 |
138 | a) Accompany it with the complete corresponding machine-readable
139 | source code, which must be distributed under the terms of Sections
140 | 1 and 2 above on a medium customarily used for software interchange; or,
141 |
142 | b) Accompany it with a written offer, valid for at least three
143 | years, to give any third party, for a charge no more than your
144 | cost of physically performing source distribution, a complete
145 | machine-readable copy of the corresponding source code, to be
146 | distributed under the terms of Sections 1 and 2 above on a medium
147 | customarily used for software interchange; or,
148 |
149 | c) Accompany it with the information you received as to the offer
150 | to distribute corresponding source code. (This alternative is
151 | allowed only for noncommercial distribution and only if you
152 | received the program in object code or executable form with such
153 | an offer, in accord with Subsection b above.)
154 |
155 | The source code for a work means the preferred form of the work for
156 | making modifications to it. For an executable work, complete source
157 | code means all the source code for all modules it contains, plus any
158 | associated interface definition files, plus the scripts used to
159 | control compilation and installation of the executable. However, as a
160 | special exception, the source code distributed need not include
161 | anything that is normally distributed (in either source or binary
162 | form) with the major components (compiler, kernel, and so on) of the
163 | operating system on which the executable runs, unless that component
164 | itself accompanies the executable.
165 |
166 | If distribution of executable or object code is made by offering
167 | access to copy from a designated place, then offering equivalent
168 | access to copy the source code from the same place counts as
169 | distribution of the source code, even though third parties are not
170 | compelled to copy the source along with the object code.
171 |
172 | 4. You may not copy, modify, sublicense, or distribute the Program
173 | except as expressly provided under this License. Any attempt
174 | otherwise to copy, modify, sublicense or distribute the Program is
175 | void, and will automatically terminate your rights under this License.
176 | However, parties who have received copies, or rights, from you under
177 | this License will not have their licenses terminated so long as such
178 | parties remain in full compliance.
179 |
180 | 5. You are not required to accept this License, since you have not
181 | signed it. However, nothing else grants you permission to modify or
182 | distribute the Program or its derivative works. These actions are
183 | prohibited by law if you do not accept this License. Therefore, by
184 | modifying or distributing the Program (or any work based on the
185 | Program), you indicate your acceptance of this License to do so, and
186 | all its terms and conditions for copying, distributing or modifying
187 | the Program or works based on it.
188 |
189 | 6. Each time you redistribute the Program (or any work based on the
190 | Program), the recipient automatically receives a license from the
191 | original licensor to copy, distribute or modify the Program subject to
192 | these terms and conditions. You may not impose any further
193 | restrictions on the recipients' exercise of the rights granted herein.
194 | You are not responsible for enforcing compliance by third parties to
195 | this License.
196 |
197 | 7. If, as a consequence of a court judgment or allegation of patent
198 | infringement or for any other reason (not limited to patent issues),
199 | conditions are imposed on you (whether by court order, agreement or
200 | otherwise) that contradict the conditions of this License, they do not
201 | excuse you from the conditions of this License. If you cannot
202 | distribute so as to satisfy simultaneously your obligations under this
203 | License and any other pertinent obligations, then as a consequence you
204 | may not distribute the Program at all. For example, if a patent
205 | license would not permit royalty-free redistribution of the Program by
206 | all those who receive copies directly or indirectly through you, then
207 | the only way you could satisfy both it and this License would be to
208 | refrain entirely from distribution of the Program.
209 |
210 | If any portion of this section is held invalid or unenforceable under
211 | any particular circumstance, the balance of the section is intended to
212 | apply and the section as a whole is intended to apply in other
213 | circumstances.
214 |
215 | It is not the purpose of this section to induce you to infringe any
216 | patents or other property right claims or to contest validity of any
217 | such claims; this section has the sole purpose of protecting the
218 | integrity of the free software distribution system, which is
219 | implemented by public license practices. Many people have made
220 | generous contributions to the wide range of software distributed
221 | through that system in reliance on consistent application of that
222 | system; it is up to the author/donor to decide if he or she is willing
223 | to distribute software through any other system and a licensee cannot
224 | impose that choice.
225 |
226 | This section is intended to make thoroughly clear what is believed to
227 | be a consequence of the rest of this License.
228 |
229 | 8. If the distribution and/or use of the Program is restricted in
230 | certain countries either by patents or by copyrighted interfaces, the
231 | original copyright holder who places the Program under this License
232 | may add an explicit geographical distribution limitation excluding
233 | those countries, so that distribution is permitted only in or among
234 | countries not thus excluded. In such case, this License incorporates
235 | the limitation as if written in the body of this License.
236 |
237 | 9. The Free Software Foundation may publish revised and/or new versions
238 | of the General Public License from time to time. Such new versions will
239 | be similar in spirit to the present version, but may differ in detail to
240 | address new problems or concerns.
241 |
242 | Each version is given a distinguishing version number. If the Program
243 | specifies a version number of this License which applies to it and "any
244 | later version", you have the option of following the terms and conditions
245 | either of that version or of any later version published by the Free
246 | Software Foundation. If the Program does not specify a version number of
247 | this License, you may choose any version ever published by the Free Software
248 | Foundation.
249 |
250 | 10. If you wish to incorporate parts of the Program into other free
251 | programs whose distribution conditions are different, write to the author
252 | to ask for permission. For software which is copyrighted by the Free
253 | Software Foundation, write to the Free Software Foundation; we sometimes
254 | make exceptions for this. Our decision will be guided by the two goals
255 | of preserving the free status of all derivatives of our free software and
256 | of promoting the sharing and reuse of software generally.
257 |
258 | NO WARRANTY
259 |
260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
268 | REPAIR OR CORRECTION.
269 |
270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
278 | POSSIBILITY OF SUCH DAMAGES.
279 |
280 | END OF TERMS AND CONDITIONS
281 |
282 | How to Apply These Terms to Your New Programs
283 |
284 | If you develop a new program, and you want it to be of the greatest
285 | possible use to the public, the best way to achieve this is to make it
286 | free software which everyone can redistribute and change under these terms.
287 |
288 | To do so, attach the following notices to the program. It is safest
289 | to attach them to the start of each source file to most effectively
290 | convey the exclusion of warranty; and each file should have at least
291 | the "copyright" line and a pointer to where the full notice is found.
292 |
293 |
294 | Copyright (C)
295 |
296 | This program is free software; you can redistribute it and/or modify
297 | it under the terms of the GNU General Public License as published by
298 | the Free Software Foundation; either version 2 of the License, or
299 | (at your option) any later version.
300 |
301 | This program is distributed in the hope that it will be useful,
302 | but WITHOUT ANY WARRANTY; without even the implied warranty of
303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
304 | GNU General Public License for more details.
305 |
306 | You should have received a copy of the GNU General Public License along
307 | with this program; if not, write to the Free Software Foundation, Inc.,
308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
309 |
310 | Also add information on how to contact you by electronic and paper mail.
311 |
312 | If the program is interactive, make it output a short notice like this
313 | when it starts in an interactive mode:
314 |
315 | Gnomovision version 69, Copyright (C) year name of author
316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
317 | This is free software, and you are welcome to redistribute it
318 | under certain conditions; type `show c' for details.
319 |
320 | The hypothetical commands `show w' and `show c' should show the appropriate
321 | parts of the General Public License. Of course, the commands you use may
322 | be called something other than `show w' and `show c'; they could even be
323 | mouse-clicks or menu items--whatever suits your program.
324 |
325 | You should also get your employer (if you work as a programmer) or your
326 | school, if any, to sign a "copyright disclaimer" for the program, if
327 | necessary. Here is a sample; alter the names:
328 |
329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program
330 | `Gnomovision' (which makes passes at compilers) written by James Hacker.
331 |
332 | , 1 April 1989
333 | Ty Coon, President of Vice
334 |
335 | This General Public License does not permit incorporating your program into
336 | proprietary programs. If your program is a subroutine library, you may
337 | consider it more useful to permit linking proprietary applications with the
338 | library. If this is what you want to do, use the GNU Lesser General
339 | Public License instead of this License.
340 |
--------------------------------------------------------------------------------
/UI.js:
--------------------------------------------------------------------------------
1 | "ui";
2 | importClass(android.database.sqlite.SQLiteDatabase);
3 | importClass(android.view.View);
4 | var tikuCommon = require("./tikuCommon.js");
5 | let deviceWidth = device.width;
6 |
7 | let margin = parseInt(deviceWidth * 0.02);
8 |
9 | //记录集数组 重要!!!
10 | let qaArray = [];
11 | var path = files.path("/sdcard/Download/tiku.db");
12 | //确保文件存在
13 | if (!files.exists(path)) {
14 | //如果sdcard/download不存在tiku.db,则复制默认的题库文件到该目录
15 | files.copy("tiku.db", path);
16 | }
17 | ui.layout(
18 |
19 |
20 |
21 |
22 |
23 |
24 |
95 |
96 |
97 | );
98 |
99 | //标签名
100 | ui.viewpager.setTitles(["功能", "题库"]);
101 | //联动
102 | ui.tabs.setupWithViewPager(ui.viewpager);
103 |
104 | //进度条不可见
105 | ui.run(() => {
106 | ui.pbar.setVisibility(View.INVISIBLE);
107 | });
108 | //
109 | var config_path="/sdcard/Download/config.txt";
110 | var xxset = {
111 | //定义账号和密码对象集,修改或增加账号数量都可以,数量不大于num
112 | "users": [{
113 | "username": "18888888888", //账号
114 | "password": "88888888", //密码
115 | },],
116 |
117 | "url": "http://pushplus.hxtrip.com/send", //定义微信推送对象 url+"?token="+token+"&title="+title+"&content="+content
118 | "token": "de17144cb3be48608fbfea27a5ef0b90", //在pushplus网站登录可以找到自己的token
119 | "wxpost": 0, //是否微信推送
120 | "article": "推荐", //文章阅读类型
121 | "update2server": 0, //是否上传到远程服务器
122 | "forever": 0, //是否开启无限答题刷题库
123 | "weekdt": 1, //是否开启每周答题
124 | "specialdt": 1, //是否开启专项答题
125 | }
126 | //配置文件config
127 | if (files.exists(config_path)) {
128 | //读取配置文件
129 | xxset = JSON.parse(files.read(config_path));
130 | //新增属性wxpost
131 | if (xxset.wxpost == undefined) {
132 | //新增属性wxpost
133 | xxset.wxpost = 1;
134 | files.write(config_path, JSON.stringify(xxset));
135 | }
136 |
137 | } else {
138 | //生成配置文件
139 | files.create("/sdcard/Download/");//创建备份目录
140 | files.write(config_path, JSON.stringify(xxset));
141 | }
142 |
143 | ui.tikuLable.setText("tiku:" + getTikuNum('tiku') +" ,tikuNet:" + getTikuNum('tikuNet'));
144 | //阅读模式切换
145 | ui.amsw.click(() => {
146 | //var amode = files.read("./article.txt");
147 | toastLog("当前阅读模式为“" + xxset.article + "”")
148 | dialogs.select("请选择文章阅读模式:", ["推荐", "订阅"])
149 | .then(i => {
150 | if (i == 0) {
151 | xxset.article = "推荐";
152 | files.write(config_path, JSON.stringify(xxset));
153 | //files.write("./article.txt", "推荐")
154 | toastLog("阅读模式已改为推荐!");
155 | } else if (i == 1) {
156 | //files.write("./article.txt", "订阅")
157 | xxset.article = "订阅";
158 | files.write(config_path, JSON.stringify(xxset));
159 | toastLog("阅读模式已改为订阅!");
160 | } else {
161 | toastLog("你没有选择!");
162 | }
163 | });
164 | });
165 | ui.update2server.click(() => {
166 | //var amode = files.read("./article.txt");
167 | toastLog("当前上传" + (xxset.update2server==0?'关闭':'开启'));
168 | dialogs.select("请选择服务器上传开关:", ["开启", "关闭"])
169 | .then(i => {
170 | if (i == 0) {
171 | xxset.update2server = 1;
172 | files.write(config_path, JSON.stringify(xxset));
173 | // files.write("./article.txt", "推荐")
174 | toastLog("服务器上传开启!")
175 | } else if (i == 1) {
176 | xxset.update2server = 0;
177 | files.write(config_path, JSON.stringify(xxset));
178 | // files.write("./article.txt", "订阅")
179 | toastLog("服务器上传关闭!")
180 | } else {
181 | toastLog("你没有选择!")
182 | }
183 | });
184 | });
185 | ui.forever.click(() => {
186 | //var amode = files.read("./article.txt");
187 | toastLog("当前无限答题" + (xxset.forever==0?'关闭':'开启'));
188 | dialogs.select("请选择无限答题开关:", ["开启", "关闭"])
189 | .then(i => {
190 | if (i == 0) {
191 | xxset.forever = 1;
192 | files.write(config_path, JSON.stringify(xxset));
193 | //files.write("./article.txt", "推荐")
194 | toastLog("无限答题开启")
195 | } else if (i == 1) {
196 | xxset.forever = 0;
197 | files.write(config_path, JSON.stringify(xxset));
198 | //files.write("./article.txt", "订阅")
199 | toastLog("无限答题关闭")
200 | } else {
201 | toastLog("你没有选择!")
202 | }
203 | });
204 | });
205 | ui.weekdt.click(() => {
206 | //var amode = files.read("./article.txt");
207 | toastLog("当前每周答题" + (xxset.weekdt==0?'关闭':'开启'));
208 | dialogs.select("请选择每周答题开关:", ["开启", "关闭"])
209 | .then(i => {
210 | if (i == 0) {
211 | xxset.weekdt = 1;
212 | files.write(config_path, JSON.stringify(xxset));
213 | //files.write("./article.txt", "推荐")
214 | toastLog("每周答题开启")
215 | } else if (i == 1) {
216 | xxset.weekdt = 0;
217 | files.write(config_path, JSON.stringify(xxset));
218 | //files.write("./article.txt", "订阅")
219 | toastLog("每周答题关闭")
220 | } else {
221 | toastLog("你没有选择!")
222 | }
223 | });
224 | });
225 | ui.specialdt.click(() => {
226 | //var amode = files.read("./article.txt");
227 | toastLog("当前专项答题" + (xxset.specialdt==0?'关闭':'开启'));
228 | dialogs.select("请选择专项答题开关:", ["开启", "关闭"])
229 | .then(i => {
230 | if (i == 0) {
231 | xxset.specialdt = 1;
232 | files.write(config_path, JSON.stringify(xxset));
233 | //files.write("./article.txt", "推荐")
234 | toastLog("专项答题开启")
235 | } else if (i == 1) {
236 | xxset.specialdt = 0;
237 | files.write(config_path, JSON.stringify(xxset));
238 | //files.write("./article.txt", "订阅")
239 | toastLog("专项答题关闭")
240 | } else {
241 | toastLog("你没有选择!")
242 | }
243 | });
244 | });
245 |
246 | //加载悬浮窗
247 | ui.showFloating.click(() => {
248 | engines.execScriptFile("!floating.js");
249 | });
250 |
251 | //查询
252 | ui.search.click(() => {
253 | //预先初始化
254 | qaArray = [];
255 | threads.shutDownAll();
256 | ui.run(() => {
257 | ui.question.setText("");
258 | ui.answer.setText("");
259 | ui.questionIndex.setText("0");
260 | ui.questionCount.setText("0");
261 | });
262 | //查询开始
263 | threads.start(function () {
264 | if (ui.keyword.getText() != "") {
265 | var keyw = ui.keyword.getText();
266 | if (ui.rbQuestion.checked) {//按题目搜
267 | var sqlStr = util.format("SELECT question,answer FROM tiku WHERE %s LIKE '%%%s%'", "question", keyw);
268 | } else {//按答案搜
269 | var sqlStr = util.format("SELECT question,answer FROM tiku WHERE %s LIKE '%%%s%'", "answer", keyw);
270 | }
271 | qaArray = tikuCommon.searchDb(keyw, "tiku", sqlStr);
272 | var qCount = qaArray.length;
273 | if (qCount > 0) {
274 | ui.run(() => {
275 | ui.question.setText(qaArray[0].question);
276 | ui.answer.setText(qaArray[0].answer);
277 | ui.questionIndex.setText("1");
278 | ui.questionCount.setText(String(qCount));
279 | });
280 | } else {
281 | toastLog("未找到");
282 | ui.run(() => {
283 | ui.question.setText("未找到");
284 | });
285 | }
286 | } else {
287 | toastLog("请输入关键字");
288 | }
289 | });
290 | });
291 |
292 | //最近十条
293 | ui.lastTen.click(() => {
294 | threads.start(function () {
295 | var keyw = ui.keyword.getText();
296 | qaArray = tikuCommon.searchDb(keyw, "", "SELECT question,answer FROM tiku ORDER BY rowid DESC limit 10");
297 | var qCount = qaArray.length;
298 | if (qCount > 0) {
299 | //toastLog(qCount);
300 | ui.run(() => {
301 | ui.question.setText(qaArray[0].question);
302 | ui.answer.setText(qaArray[0].answer);
303 | ui.questionIndex.setText("1");
304 | ui.questionCount.setText(qCount.toString());
305 | });
306 | } else {
307 | toastLog("未找到");
308 | ui.run(() => {
309 | ui.question.setText("未找到");
310 | });
311 | }
312 | });
313 | });
314 |
315 | //上一条
316 | ui.prev.click(() => {
317 | threads.start(function () {
318 | if (qaArray.length > 0) {
319 | var qIndex = parseInt(ui.questionIndex.getText()) - 1;
320 | if (qIndex > 0) {
321 | ui.run(() => {
322 | ui.question.setText(qaArray[qIndex - 1].question);
323 | ui.answer.setText(qaArray[qIndex - 1].answer);
324 | ui.questionIndex.setText(String(qIndex));
325 | });
326 | } else {
327 | toastLog("已经是第一条了!");
328 | }
329 | } else {
330 | toastLog("题目为空");
331 | }
332 | });
333 | });
334 |
335 | //下一条
336 | ui.next.click(() => {
337 | threads.start(function () {
338 | if (qaArray.length > 0) {
339 | //toastLog(qaArray);
340 | var qIndex = parseInt(ui.questionIndex.getText()) - 1;
341 | if (qIndex < qaArray.length - 1) {
342 | //toastLog(qIndex);
343 | //toastLog(qaArray[qIndex + 1].question);
344 | ui.run(() => {
345 | ui.question.setText(qaArray[qIndex + 1].question);
346 | ui.answer.setText(qaArray[qIndex + 1].answer);
347 | ui.questionIndex.setText(String(qIndex + 2));
348 | });
349 | } else {
350 | toastLog("已经是最后一条了!");
351 | }
352 | } else {
353 | toastLog("题目为空");
354 | }
355 | });
356 | });
357 |
358 | //修改
359 | ui.update.click(() => {
360 | threads.start(function () {
361 | if (ui.question.getText() && qaArray.length > 0 && parseInt(ui.questionIndex.getText()) > 0) {
362 | var qIndex = parseInt(ui.questionIndex.getText()) - 1;
363 | var questionOld = qaArray[qIndex].question;
364 | var questionStr = ui.question.getText();
365 | var answerStr = ui.answer.getText();
366 | var sqlstr = "UPDATE tiku SET question = '" + questionStr + "' , answer = '" + answerStr + "' WHERE question= '" + questionOld + "'";
367 | tikuCommon.executeSQL(sqlstr);
368 | } else {
369 | toastLog("请先查询");
370 | }
371 | });
372 | });
373 |
374 | //删除
375 | ui.delete.click(() => {
376 | threads.start(function () {
377 | if (qaArray.length > 0 && parseInt(ui.questionIndex.getText()) > 0) {
378 | var qIndex = parseInt(ui.questionIndex.getText()) - 1;
379 | var questionOld = qaArray[qIndex].question;
380 | var sqlstr = "DELETE FROM tiku WHERE question = '" + questionOld + "'";
381 | tikuCommon.executeSQL(sqlstr);
382 | } else {
383 | toastLog("请先查询");
384 | }
385 | });
386 | });
387 |
388 | //新增
389 | ui.insert.click(() => {
390 | threads.start(function () {
391 | if (ui.question.getText() != "" && ui.answer.getText() != "") {
392 | var questionStr = ui.question.getText();
393 | var answerStr = ui.answer.getText();
394 | var sqlstr = "INSERT INTO tiku VALUES ('" + questionStr + "','" + answerStr + "','')";
395 | tikuCommon.executeSQL(sqlstr);
396 | } else {
397 | toastLog("请先输入 问题 答案");
398 | }
399 | });
400 | });
401 |
402 | function reset() {
403 |
404 | }
405 | //重置
406 | ui.reset.click(() => {
407 | threads.shutDownAll();
408 | threads.start(function () {
409 | qaArray = [];
410 | ui.run(() => {
411 | ui.keyword.setText("");
412 | ui.question.setText("");
413 | ui.answer.setText("");
414 | ui.questionIndex.setText("0");
415 | ui.questionCount.setText("0");
416 | ui.rbQuestion.setChecked(true);
417 | });
418 | toastLog("重置完毕!");
419 | });
420 | });
421 |
422 | //更新网络题库
423 | ui.updateTikuNet.click(() => {
424 | dialogs.build({
425 | title: "更新网络题库",
426 | content: "确定更新?",
427 | positive: "确定",
428 | negative: "取消",
429 | })
430 | .on("positive", update)
431 | .show();
432 |
433 | function update() {
434 | threads.start(function () {
435 | ui.run(() => {
436 | ui.resultLabel.setText("正在更新网络题库...");
437 | ui.pbar.setVisibility(View.VISIBLE);
438 | });
439 | var ss = "./updateTikuNet.js";
440 | let begin = require(ss);
441 | var resultNum = begin();
442 | var resultStr = "更新了" + resultNum + "道题!";
443 | log("更新了" + resultNum + "道题!")
444 | ui.run(() => {
445 | ui.resultLabel.setText("");
446 | ui.pbar.setVisibility(View.INVISIBLE);
447 | ui.resultLabel.setVisibility(View.INVISIBLE);
448 | });
449 | alert(resultStr);
450 | });
451 | }
452 | });
453 |
454 | ui.listdel.click(() => {
455 | dialogs.build({
456 | title: "提示",
457 | content: "确认清空文章阅读记录吗?",
458 | positive: "确定",
459 | negative: "取消",
460 | }).on("positive", clear)
461 | .show();
462 | function clear() {
463 | var db = SQLiteDatabase.openOrCreateDatabase(path, null);
464 | var Deletelistable = "DELETE FROM learnedArticles";
465 | db.execSQL(Deletelistable);
466 | db.close();
467 | toastLog("已清空文章阅读记录!");
468 | }
469 | })
470 |
471 | ui.getRepeatQuestion.click(() => {
472 | //查询开始
473 | threads.start(function () {
474 | var sqlStr = util.format("SELECT question,answer FROM tiku GROUP BY question HAVING count( question ) > 1");
475 | qaArray = tikuCommon.searchDb("", "tiku", sqlStr);
476 | var qCount = qaArray.length;
477 | if (qCount > 0) {
478 | ui.run(() => {
479 | ui.question.setText(qaArray[0].question);
480 | ui.answer.setText(qaArray[0].answer);
481 | ui.questionIndex.setText("1");
482 | ui.questionCount.setText(String(qCount));
483 | });
484 | } else {
485 | toastLog("未找到");
486 | ui.run(() => {
487 | ui.question.setText("未找到");
488 | });
489 | }
490 | });
491 | })
492 | function getTikuNum(tikuName) {
493 | var db = SQLiteDatabase.openOrCreateDatabase(files.path("/sdcard/Download/tiku.db"), null);
494 | var cursor = db.rawQuery("select count(*) from " + tikuName, null);
495 | cursor.moveToFirst()
496 | return cursor.getString(0)
497 | }
--------------------------------------------------------------------------------
/!zsyTzAnswer.js:
--------------------------------------------------------------------------------
1 | importClass(android.database.sqlite.SQLiteDatabase);
2 | var lCount = 1;//挑战答题轮数
3 | var qCount = randomNum(5, 7);//挑战答题每轮答题数(5~7随机),5次为最高分
4 | var zCount = 2;//争上游答题轮数
5 | var ziXingTi = "选择词语的正确词形。"; //字形题,已定义为全局变量
6 | var zsyDelay = 20; //定义争上游答题延时时间,示例为0-100的随机值,参考某些学习工具的延时时间为100ms,即0.1秒
7 |
8 | var path = files.path("/sdcard/Download/tiku.db");
9 | var xxset = JSON.parse(files.read("/sdcard/Download/config.txt"));
10 | function updateToServer(question, answer) {
11 | //上传到服务器
12 | if (xxset.update2server) {
13 | logInfo("开始上传...")
14 | var res = http.post("http://bldsj.zih718.com:8088/insertOrUpdate",
15 | {"question": question, "answer": answer});
16 | var code = res.body.json();
17 | if (code == 200) {
18 | logInfo("成功");
19 | } else if (code == 202) {
20 | logInfo("已存在");
21 | }
22 | }
23 | }
24 |
25 | /**
26 | * @description: 延时函数
27 | * @param: seconds-延迟秒数
28 | * @return: null
29 | */
30 | function delay(seconds) {
31 | sleep(1000 * seconds);//sleep函数参数单位为毫秒所以乘1000
32 | }
33 |
34 | function logDefault(str) {
35 | console.log(str);
36 | }
37 |
38 | function logInfo(str) {
39 | console.info(str);
40 | }
41 |
42 | function logError(str) {
43 | console.error(str);
44 | }
45 |
46 | /**
47 | * @description: 生成从minNum到maxNum的随机数
48 | * @param: minNum-较小的数
49 | * @param: maxNum-较大的数
50 | * @return: null
51 | */
52 | function randomNum(minNum, maxNum) {
53 | switch (arguments.length) {
54 | case 1:
55 | return parseInt(Math.random() * minNum + 1, 10);
56 | case 2:
57 | return parseInt(Math.random() * (maxNum - minNum + 1) + minNum, 10);
58 | default:
59 | return 0;
60 | }
61 | }
62 | /**
63 | * @description: 在答题选项画✔,用于各项答题部分
64 | * @param: x,y 坐标
65 | * @return: null
66 | */
67 | function drawfloaty(x, y) {
68 | //floaty.closeAll();
69 | var window = floaty.window(
70 |
71 |
72 |
73 | );
74 | window.setPosition(x, y - 45);
75 | return window;
76 | }
77 | /**
78 | * @description: 从数据库中搜索答案,没有答案就添加(存在即更新),或删除题库中的问题列
79 | * @param: upOrdel,question,answer;upOrdel:'up'=1,'del'=0
80 | * @return: null
81 | */
82 | function UpdateOrDeleteTK(upOrdel, question, answer) {//只针对tiku表,添加/更新或删除相应的列
83 | if (question == undefined) {
84 | logDefault("题目为空,返回!");
85 | return;
86 | }
87 |
88 | if (upOrdel == "up" || upOrdel == 1) {//更新题库
89 | let db = SQLiteDatabase.openOrCreateDatabase(path, null);
90 | if (answer == undefined) {
91 | logDefault("答案为空,返回!");
92 | return;
93 | }
94 |
95 | let sql1 = "SELECT answer FROM tiku WHERE question LIKE '%" + question + "%'"// 关键词前后都加%,增加搜索准确率
96 | let cursor = db.rawQuery(sql1, null);//查找是否存在
97 | if (!cursor.moveToFirst()) { //不存在,添加到题库
98 | sql1 = "INSERT INTO tiku VALUES ('" + question + "','" + answer + "','')";
99 | logDefault("更新答案到tiku表...");
100 | db.execSQL(sql1);
101 | updateToServer(question, answer);
102 | } else { //修正题库答案
103 | if (cursor.getString(0) != answer) { //题库答案和目的答案不一致
104 | // logError('题库答案:' + cursor.getString(0)); //调试用
105 | sql1 = "UPDATE tiku SET answer='" + answer + "' WHERE question LIKE '" + question + "'";
106 | logDefault("修正本地题库答案...");
107 | db.execSQL(sql1);
108 | updateToServer(question, answer);
109 | } else {
110 | updateToServer(question, answer);
111 | }
112 | }
113 | cursor.close();
114 | db.close(); //关闭数据库
115 | delay(1);
116 | } else if (upOrdel == "del" || upOrdel == 0) {
117 | let db = SQLiteDatabase.openOrCreateDatabase(path, null);
118 | let sql2 = "SELECT answer FROM tiku WHERE question LIKE '%" + question + "%'"// 关键词前后都加%,增加搜索准确率
119 | let cursor = db.rawQuery(sql2, null);//查找是否存在
120 | if (cursor.moveToFirst()) { //题库存在,删除该列
121 | sql2 = "DELETE FROM tiku WHERE question LIKE '" + question + "'";//删库语句
122 | logDefault("删除本地题库的相关题目列...");
123 | db.execSQL(sql2);
124 | } else {
125 | logDefault("本地题库找不到对应的题目,删除失败。");
126 | }
127 | cursor.close();
128 | db.close(); //关闭数据库
129 | delay(1);
130 | }
131 | }
132 |
133 |
134 | function getAnswer(question) {
135 | let db = SQLiteDatabase.openOrCreateDatabase(path, null);
136 | let sql1 = "SELECT answer FROM tiku WHERE question LIKE '%" + question + "%'";// 关键词前后都加%,增加搜索准确率
137 | let sql2 = "SELECT answer FROM tikuNet WHERE question LIKE '%" + question + "%'";
138 | let answer = "";
139 | let cursor = db.rawQuery(sql1, null);
140 | if (cursor.moveToFirst()) {
141 | answer = cursor.getString(0);
142 | cursor.close();
143 | logDefault("tiku答案:" + answer);
144 | return answer;
145 | } else {
146 | cursor = db.rawQuery(sql2, null);
147 | if (cursor.moveToFirst()) {
148 | answer = cursor.getString(0);
149 | cursor.close();
150 | db.close();
151 | logDefault("tikuNet答案:" + answer);
152 | return answer.replace(/(^\s*)|(\s*$)/g, "");;
153 | } else {
154 | logDefault("本地未找到答案,请求网络");
155 | let netTiku = "http://sg89.cn/api/tk1.php"; //在线题库
156 | let netziXingTi = "选择词语的正确词形%。"; //字形题网络原题,含空格+第一选项,改为通配%
157 | let netquestion = question.replace(ziXingTi, netziXingTi);//还原字形题的原题目(含空格)+第一个选项
158 | try {
159 | let zxda = http.post(netTiku, {//在线答案
160 | "t": "da",
161 | "q": netquestion
162 | });
163 | //判断发送是否成功
164 | // (zxda.statusCode = 200) {//post成功info
165 | let zxanswer = zxda.body.json();
166 | if (zxanswer.code == -1) { //未找到答案
167 | logError("网络请求未找到答案...");
168 | return '';
169 | } else {//找到答案 (0||1)
170 | let answer = zxanswer.as;//在线答案
171 | //添加或更新本地题库答案
172 | logDefault("网络答案:" + answer);
173 | return answer;//返回答案
174 | }
175 | } catch (e) {
176 | logError("网络请求出错,请检查!");
177 | return '';
178 | }
179 | }
180 | }
181 | }
182 |
183 | function indexFromChar(str) {
184 | return str.charCodeAt(0) - "A".charCodeAt(0);
185 | }
186 |
187 | /**
188 | * @description: 在答题选项画✔,用于各项答题部分
189 | * @param: x,y 坐标
190 | * @return: null
191 | */
192 |
193 |
194 | /***************************争上游、双人对战答题部分 开始***************************/
195 | /**
196 | * @description: 争上游答题 20200928增加
197 | * @param: null
198 | * @return: null
199 | */
200 | function zsyQuestion() {
201 | if (className("android.view.View").text("开始比赛").exists()) {
202 | logDefault("点击 开始比赛");
203 | className("android.view.View").text("开始比赛").findOne().click();
204 | }
205 | delay(5);
206 | let zNum = 1;//轮数
207 | logInfo("第" + zNum.toString() + "轮争上游答题开始...")
208 | while (true) {
209 | if (className("android.view.View").text("继续挑战").exists() || textContains("继续挑战").exists())//遇到继续挑战,则本局结束
210 | {
211 | logInfo("争上游答题本局结束!");
212 | zNum++;
213 | //当天上限两次
214 | if (className("android.view.View").text("非积分奖励局").exists()) {
215 | logInfo("今日争上游答题积分已完成!");
216 | zNum++;
217 | }//
218 | if (zNum > zCount) {
219 | if (xxset.forever) {
220 | logDefault("无限答题开启");
221 | delay(3);//等待5秒才能开始下一轮
222 | back();
223 | //desc("结束本局").click();//有可能找不到结束本局字样所在页面控件,所以直接返回到上一层
224 | delay(2);
225 | logDefault("点击 开始比赛");
226 | text("开始比赛").click();
227 | delay(3);
228 | continue;
229 | }
230 | logDefault("争上游答题结束");
231 | //回退返回主页
232 | back();
233 | delay(0.5);
234 | back();
235 | delay(0.5);
236 | break;
237 | } else {
238 | logDefault("即将开始下一轮...")
239 | delay(2);//等待2秒开始下一轮
240 | back();
241 | delay(1);
242 | back();
243 | while (!text("答题练习").exists()) ;//排行榜 答题竞赛
244 | delay(1);
245 | className("android.view.View").text("答题练习").findOne().parent().child(8).click();
246 | logDefault("开始争上游答题")
247 | delay(2);
248 | if (className("android.view.View").text("开始比赛").exists()) {
249 | className("android.view.View").text("开始比赛").findOne().click();
250 | }
251 | delay(6);
252 | }
253 | logInfo("第" + zNum.toString() + "轮开始...")
254 | } else if (!text("继续挑战").exists()) {
255 | zsyQuestionLoop();
256 | }
257 | }
258 | }
259 |
260 | /**
261 | * @description: 双人对战答题 20200928增加
262 | * @param: null
263 | * @return: null
264 | */
265 | function SRQuestion() {
266 | if (className("android.view.View").text("邀请对手").exists()) {
267 | logDefault("点击 邀请对手");
268 | className("android.view.View").text("邀请对手").findOne().parent().child(0).click();
269 | }
270 | delay(1);
271 | if (className("android.view.View").text("开始对战").exists()) {
272 | logDefault("点击 开始对战");
273 | className("android.view.View").text("开始对战").findOne().click();
274 | }
275 | delay(5);
276 | let zNum = 1;//轮数
277 | while (true) {
278 | if (className("android.view.View").text("继续挑战").exists() || textContains("继续挑战").exists() || textContains("请明日再来").exists() || className("android.view.View").text("非积分奖励局").exists()) {//遇到继续挑战,则本局结束
279 | logInfo("双人对战本局结束!");
280 | zNum++;
281 | if (zNum >= zCount) {
282 | logDefault("双人对战结束!返回主页!");
283 | if (textContains("知道了").exists()) {//今日次数已超过
284 | className("android.widget.Button").text("知道了").findOne().click();
285 | delay(1);
286 | //back(); delay(1);
287 | //back(); delay(1);
288 | break;
289 | }
290 | //回退返回主页
291 | back();
292 | delay(1);
293 | back();
294 | delay(1);
295 | if (text("退出").exists()) {
296 | className("android.widget.Button").text("退出").findOne().click();
297 | delay(1);
298 | }
299 | //back(); delay(1);
300 | //back(); delay(1);
301 | break;
302 | } else {
303 | logDefault("即将开始下一轮...")
304 | back();
305 | delay(1);
306 | back();
307 | delay(1);
308 | if (textContains("退出").exists()) {
309 | className("android.widget.Button").text("退出").findOne().click();
310 | delay(1);
311 | }
312 | while (!text("答题练习").exists()) ;//排行榜 答题竞赛
313 | delay(1);
314 | logDefault("开始双人对战")
315 | delay(2);
316 | if (className("android.view.View").text("邀请对手").exists()) {
317 | logDefault("点击 邀请对手");
318 | className("android.view.View").text("邀请对手").findOne().parent().child(0).click();
319 | }
320 | delay(1);
321 | if (className("android.view.View").text("开始对战").exists()) {
322 | logDefault("点击 开始对战");
323 | className("android.view.View").text("开始对战").findOne().click();
324 | }
325 | delay(5);
326 | }
327 | } else if (!text("继续挑战").exists()) {
328 | //textContains("距离答题结束").exists() &&
329 | zsyQuestionLoop();
330 | }
331 | }
332 | }
333 |
334 | /**
335 | * @description: 争上游答题 双人对战答题循环
336 | * @param: null
337 | * @return: null
338 | */
339 |
340 | function zsyQuestionLoop() {
341 | let ClickAnswer;
342 | while (className("ListView").exists() && !text("继续挑战").exists()) {
343 | try {
344 | if (className("ListView").exists() && !text("继续挑战").exists()) {
345 | var aquestion = className("ListView").findOnce().parent().child(0).text();
346 | var question = aquestion.substring(3); //争上游和对战题目前带1.2.3.需去除
347 | }
348 | if (aquestion != oldaquestion && question != "") {
349 | logDefault("题目:" + question);
350 | logDefault("------------------------");
351 | var chutiIndex = question.lastIndexOf("出题单位");
352 | if (chutiIndex != -1) {
353 | question = question.substring(0, chutiIndex - 2);
354 | }
355 |
356 | var options = [];//选项列表
357 | if (className("ListView").exists()) {
358 | className("ListView").findOne().children().forEach(child => {
359 | var answer_q = child.child(0).child(1).text();
360 | options.push(answer_q);
361 | });
362 | } else {
363 | logError("从页面上获取答案失败!");
364 | return;
365 | }
366 |
367 | // 判断是否为字形题,网络搜题和本地搜题
368 | question = question.replace(/\s/g, "");
369 |
370 | if (question == ziXingTi.replace(/\s/g, "")) {
371 | question = question + options[0].substring(3); //字形题在题目后面添加第一选项
372 | }
373 |
374 | var answer = getAnswer(question);
375 | if (/^[a-zA-Z]{1}$/.test(answer)) {//如果为ABCD形式
376 | var indexAnsTiku = indexFromChar(answer.toUpperCase());
377 | answer = options[indexAnsTiku];
378 | }
379 |
380 | let hasClicked = false;
381 | let listArray = className("ListView").findOnce().children();//题目选项列表
382 |
383 | logInfo("答案:" + answer);
384 | logInfo("------------------------");
385 | //如果找到答案
386 | if (answer.length != 0) {//如果找到了答案 该部分问题: 选项带A.B.C.D.,题库返回答案不带,char返回答案带
387 | var answer_a = answer.substring(0, 2);//定义answer_a,获取答案前两个字符对比A.B.C.D.应该不会出现E选项
388 | if (answer_a == "A." || answer_a == "B." || answer_a == "C." || answer_a == "D.") {
389 | listArray.forEach(item => {
390 | var listDescStrb = item.child(0).child(1).text();
391 | if (listDescStrb == answer) {
392 | //显示 对号
393 | //var b = item.child(0).bounds();
394 | //var tipsWindow = drawfloaty(b.left, b.top);
395 | item.child(0).click();//点击答案
396 | //sleep(randomNum(0, zsyDelay)/2);
397 | hasClicked = true;
398 | //消失 对号
399 | //sleep(randomNum(0, zsyDelay)/2);
400 | //tipsWindow.close();
401 | }
402 | });
403 | } else {
404 | listArray.forEach(item => {
405 | var listDescStra = item.child(0).child(1).text();
406 | var listDescStrb = listDescStra.substring(3);//选项去除A.B.C.D.再与answer对比
407 | var listDescStrc = listDescStrb.replace(/\s/g, "");
408 | if (listDescStrb == answer || listDescStrc == answer) {
409 | //显示 对号
410 | //var b = item.child(0).bounds();
411 | //var tipsWindow = drawfloaty(b.left, b.top);
412 | item.child(0).click();//点击答案
413 | //sleep(randomNum(0, zsyDelay)/2);
414 | hasClicked = true;
415 | //消失 对号
416 | //sleep(randomNum(0, zsyDelay)/2);
417 | //tipsWindow.close();
418 | }
419 | });
420 | }
421 | }
422 | if (!hasClicked || answer.length == 0) {//如果没有点击成功,或找不到题目
423 | if (!hasClicked) {
424 | logError("未能成功点击,随机点击");
425 | }
426 | if (answer.length == 0) {
427 | logError("未找到答案,随机点击");
428 | }
429 | let i = random(0, listArray.length - 1);
430 | listArray[i].child(0).click();//随意点击一个答案
431 | hasClicked = true;
432 | ClickAnswer = listArray[i].child(0).child(1).text();
433 | //记录已点击答案
434 | logDefault("随机点击:" + ClickAnswer);
435 | logDefault("------------------------");
436 | }
437 |
438 | var oldaquestion = aquestion; //对比新旧题目
439 | sleep(randomNum(0, zsyDelay));
440 | //完成一道题目作答
441 | }
442 | } catch (e) {
443 | logError(e); //输出错误信息,调试用
444 | // logError("出现错误,请检查!");
445 | return;
446 | }
447 | }
448 | }
449 |
450 | /***************************争上游、双人对战答题部分 结束***************************/
451 |
452 | /***************************每日、每周、专项答题部分 开始***************************/
453 | /**
454 | * @description: 获取填空题题目数组
455 | * @param: null
456 | * @return: questionArray
457 | */
458 | function getFitbQuestion() {
459 | var questionCollections = className("EditText").findOnce().parent().parent();
460 | var questionArray = [];
461 | var findBlank = false;
462 | var blankCount = 0;
463 | var blankNumStr = "";
464 | var i = 0;
465 | questionCollections.children().forEach(item => {
466 | if (item.className() != "android.widget.EditText") {
467 | if (item.text() != "") {//题目段
468 | if (findBlank) {
469 | blankNumStr = "|" + blankCount.toString();
470 | questionArray.push(blankNumStr);
471 | findBlank = false;
472 | }
473 | questionArray.push(item.text());
474 | } else {
475 | findBlank = true;
476 | blankCount = (className("EditText").findOnce(i).parent().childCount() - 1);
477 | i++;
478 | }
479 | }
480 | });
481 | return questionArray;
482 | }
483 |
484 |
485 | /**
486 | * @description: 获取选择题题目数组
487 | * @param: null
488 | * @return: questionArray
489 | */
490 | function getChoiceQuestion() {
491 | var questionCollections = className("ListView").findOnce().parent().child(1);
492 | var questionArray = [];
493 | questionArray.push(questionCollections.text());
494 | return questionArray;
495 | }
496 |
497 |
498 | /**
499 | * @description: 获取提示字符串
500 | * @param: null
501 | * @return: tipsStr
502 | */
503 | function getTipsStr() {
504 | var tipsStr = "";
505 | while (tipsStr == "") {
506 | if (text("查看提示").exists()) {
507 | var seeTips = text("查看提示").findOnce();
508 | seeTips.click();
509 | delay(1);
510 | click(device.width * 0.5, device.height * 0.41);
511 | delay(1);
512 | click(device.width * 0.5, device.height * 0.35);
513 | } else {
514 | logError("未找到查看提示");
515 | }
516 | if (text("提示").exists()) {
517 | var tipsLine = text("提示").findOnce().parent();
518 | //获取提示内容
519 | var tipsView = tipsLine.parent().child(1).child(0);
520 | tipsStr = tipsView.text();
521 | //关闭提示
522 | tipsLine.child(1).click();
523 | break;
524 | }
525 | delay(1);
526 | }
527 | return tipsStr;
528 | }
529 |
530 |
531 | /**
532 | * @description: 从提示中获取填空题答案
533 | * @param: timu, tipsStr
534 | * @return: ansTips
535 | */
536 | function getAnswerFromTips(timu, tipsStr) {
537 | var ansTips = "";
538 | for (var i = 1; i < timu.length - 1; i++) {
539 | if (timu[i].charAt(0) == "|") {
540 | var blankLen = timu[i].substring(1);
541 | var indexKey = tipsStr.indexOf(timu[i + 1]);
542 | var ansFind = tipsStr.substr(indexKey - blankLen, blankLen);
543 | ansTips += ansFind;
544 | }
545 | }
546 | return ansTips;
547 | }
548 |
549 | /**
550 | * @description: 根据提示点击选择题选项
551 | * @param: tipsStr
552 | * @return: clickStr
553 | */
554 | function clickByTips(tipsStr) {
555 | var clickStr = "";
556 | var isFind = false;
557 | if (className("ListView").exists()) {
558 | var listArray = className("ListView").findOne().children();
559 | listArray.forEach(item => {
560 | var ansStr = item.child(0).child(2).text();
561 | if (tipsStr.indexOf(ansStr) >= 0) {
562 | //显示 对号
563 | var b = item.child(0).bounds();
564 | var tipsWindow = drawfloaty(b.left, b.top);
565 | //时长点击
566 | sleep(300);
567 | //点击
568 | item.child(0).click();
569 | sleep(300);
570 | //消失 对号
571 | tipsWindow.close();
572 | clickStr += item.child(0).child(1).text().charAt(0);
573 | isFind = true;
574 | }
575 | });
576 | if (!isFind) { //没有找到 点击第一个
577 | listArray[0].child(0).click();
578 | delay(0.3);
579 | clickStr += listArray[0].child(0).child(1).text().charAt(0);
580 | }
581 | }
582 | return clickStr;
583 | }
584 |
585 |
586 | /**
587 | * @description: 根据答案点击选择题选项,10.29修改返回点击成功与否
588 | * @param: answer
589 | * @return: null
590 | */
591 | function clickByAnswer(answer) {
592 | let hasClicked = false;
593 | if (className("ListView").exists()) {
594 | var listArray = className("ListView").findOnce().children();
595 | listArray.forEach(item => {
596 | var listIndexStr = item.child(0).child(1).text().charAt(0);
597 | //单选答案为非ABCD
598 | var listDescStr = item.child(0).child(2).text();
599 | var listDescStrc = listDescStr.replace(/\s/g, "");
600 | if (answer.indexOf(listIndexStr) >= 0 || answer == listDescStr || listDescStrc == answer) {
601 | //显示 对号
602 | var b = item.child(0).bounds();
603 | var tipsWindow = drawfloaty(b.left, b.top);
604 | //时长点击
605 | sleep(300);
606 | //点击
607 | item.child(0).click();
608 | sleep(300);
609 | //消失 对号
610 | tipsWindow.close();
611 | hasClicked = true;
612 |
613 | }
614 | });
615 | return hasClicked;
616 | }
617 | }
618 |
619 | /**
620 | * @description: 检查答案是否正确,并更新数据库
621 | * @param: question, ansTiku, answer
622 | * @return: null
623 | */
624 | function checkAndUpdate(question, answer) {
625 | if (text("答案解析").exists()) {//答错了
626 | swipe(100, device.height - 100, 100, 100, 500);
627 | var nCout = 0
628 | while (nCout < 5) {
629 | if (textStartsWith("正确答案").exists()) {
630 | var correctAns = textStartsWith("正确答案").findOnce().text().substr(6);
631 | logInfo("正确答案是:" + correctAns);
632 | UpdateOrDeleteTK('up', question, correctAns);//添加或更新到本地题库
633 | break;
634 |
635 | } else {
636 | var clickPos = className("android.webkit.WebView").findOnce().child(2).child(0).child(1).bounds();
637 | logError("未捕获正确答案,尝试修正");
638 | click(clickPos.left + device.width * 0.13, clickPos.top + device.height * 0.1);
639 | }
640 | nCout++;
641 | }
642 | var clickNextOk = false;
643 | if (text("下一题").exists()) {
644 | clickNextOk = text("下一题").findOnce().click();
645 | delay(0.5);
646 | } else if (text("确定").exists()) {
647 | clickNextOk = text("确定").findOnce().click();
648 | delay(0.5);
649 | } else if (text("完成").exists()) {
650 | clickNextOk = text("完成").findOnce().click();
651 | delay(0.5);
652 | }
653 |
654 | if (!clickNextOk) { //按钮点击不成功,坐标点击
655 | logError("未找到右上角确定按钮控件,根据坐标点击");
656 | click(device.width * 0.85, device.height * 0.06);//右上角确定按钮,根据自己手机实际修改
657 | delay(0.5);
658 | }
659 |
660 | } else { //正确后进入下一题,或者进入再来一局界面
661 | if (question != "" && answer != "") {
662 | UpdateOrDeleteTK('up', question, answer);//添加或更新到本地题库
663 | }
664 | }
665 | }
666 |
667 |
668 | /**
669 | * @description: 每日答题循环
670 | * @param: null
671 | * @return: null
672 | */
673 | function dailyQuestionLoop() {
674 | if (textStartsWith("填空题").exists()) {
675 | var questionArray = getFitbQuestion();
676 | } else if (textStartsWith("多选题").exists() || textStartsWith("单选题").exists()) {
677 | var questionArray = getChoiceQuestion();
678 | }
679 |
680 | var blankArray = [];
681 | var question = "";
682 | questionArray.forEach(item => {
683 | if (item != null && item.charAt(0) == "|") { //是空格数
684 | blankArray.push(item.substring(1));
685 | } else { //是题目段
686 | question += item;
687 | }
688 | });
689 | logDefault("题目:" + question);
690 | logDefault("------------------------");
691 |
692 | var chutiIndex = question.lastIndexOf("出题单位");
693 | if (chutiIndex != -1) {
694 | question = question.substring(0, chutiIndex - 2);
695 | }
696 |
697 | var options = [];//选项列表
698 | if (!textStartsWith("填空题").exists()) {//选择题提取答案,为字形题准备
699 | if (className("ListView").exists()) {
700 | className("ListView").findOne().children().forEach(child => {
701 | var answer_q = child.child(0).child(2).text();
702 | options.push(answer_q);
703 | });
704 | } else {
705 | logError("答案获取失败!");
706 | return;
707 | }
708 | }
709 |
710 | // 判断是否为字形题,网络搜题和本地搜题
711 | question = question.replace(/\s/g, "");
712 |
713 | if (question == ziXingTi.replace(/\s/g, "")) {
714 | question = question + options[0]; //字形题在题目后面添加第一选项
715 | }
716 |
717 | var answer = getAnswer(question);
718 | if (textStartsWith("填空题").exists()) {
719 | if (answer == "") { //答案空,前面题库未找到答案,找提示
720 | var tipsStr = getTipsStr();
721 | answer = getAnswerFromTips(questionArray, tipsStr);
722 | logInfo("提示中答案:" + answer);
723 | var answerinput = className("EditText").findOnce().parent().child(0);//10.28修改填空题的输入方法
724 | answerinput.setText(answer);//10.28修改填空题的输入方法
725 | delay(0.1);
726 | /*
727 | setText(0, answer.substr(0, blankArray[0]));
728 | if (blankArray.length > 1) {
729 | for (var i = 1; i < blankArray.length; i++) {
730 | setText(i, answer.substr(blankArray[i - 1], blankArray[i]));
731 | }
732 | }
733 | */
734 | } else { //答案非空,题库中已找到答案
735 | logInfo("答案:" + answer);
736 | var answerinput = className("EditText").findOnce().parent().child(0);//10.28修改填空题的输入方法
737 | answerinput.setText(answer);//10.28修改填空题的输入方法
738 | delay(0.1);
739 | /*
740 | setText(0, answer.substr(0, blankArray[0]));
741 | if (blankArray.length > 1) {
742 | for (var i = 1; i < blankArray.length; i++) {
743 | setText(i, answer.substr(blankArray[i - 1], blankArray[i]));
744 | }
745 | }
746 | */
747 | }
748 | } else if (textStartsWith("多选题").exists() || textStartsWith("单选题").exists()) {
749 | if (answer == "") {
750 | var tipsStr = getTipsStr();
751 | answer = clickByTips(tipsStr);
752 | logInfo("提示中答案:" + answer);
753 | } else {
754 | logInfo("答案:" + answer);
755 | var clickAnswerOK = clickByAnswer(answer);
756 | if (!clickAnswerOK) {//题库答案有误,选项无法点击,进行提示作答
757 | //ansTiku = '';//为checkAndUpdate准备,更新本地题库答案
758 | var tipsStr = getTipsStr(); //根据提示找答案
759 | answer = clickByTips(tipsStr);
760 | logInfo("重新选择提示的答案:" + answer);
761 | delay(0.5);
762 | }
763 | }
764 | }
765 |
766 | var clickNextOk = false;
767 | if (text("下一题").exists()) {
768 | clickNextOk = text("下一题").findOnce().click();
769 | delay(0.5);
770 | } else if (text("确定").exists()) {
771 | clickNextOk = text("确定").findOnce().click();
772 | delay(0.5);
773 | } else if (text("完成").exists()) {
774 | clickNextOk = text("完成").findOnce().click();
775 | delay(0.5);
776 | }
777 |
778 | if (!clickNextOk) { //按钮点击不成功,坐标点击
779 | logError("未找到右上角确定按钮控件,根据坐标点击");
780 | click(device.width * 0.85, device.height * 0.06);//右上角确定按钮,根据自己手机实际修改
781 | delay(0.5);
782 | }
783 |
784 | checkAndUpdate(question, answer);//检查提示答案,更新本地题库
785 | logDefault("------------------------");
786 | delay(2);
787 | }
788 |
789 | /**
790 | * @description: 每日答题
791 | * @param: null
792 | * @return: null
793 | */
794 | function dailyQuestion() {
795 | let dlNum = 0;//每日答题轮数
796 | while (true) {
797 | delay(1)
798 | if (!(textStartsWith("填空题").exists() || textStartsWith("多选题").exists() || textStartsWith("单选题").exists())) {
799 | logError("没有找到题目!请检查是否进入答题界面!");
800 | logDefault("停止");
801 | break;
802 | }
803 | dailyQuestionLoop();
804 | if (text("再练一次").exists()) {
805 | logDefault("每周答题结束!")
806 | text("返回").click();
807 | delay(2);
808 | back();
809 | break;
810 | } else if (text("查看解析").exists()) {
811 | logDefault("专项答题结束!")
812 | back();
813 | delay(0.5);
814 | back();
815 | delay(0.5);
816 | break;
817 | } else if (text("再来一组").exists()) {
818 | delay(2);
819 | dlNum++;
820 | if (!text("领取奖励已达今日上限").exists()) {
821 | logDefault("点击 再来一组");
822 | text("再来一组").click();
823 | logInfo("第" + (dlNum + 1).toString() + "轮答题:");
824 | delay(1);
825 | } else {
826 | logDefault("每日答题结束!")
827 | if (xxset.forever) {
828 | logDefault("无限答题开启.");
829 | delay(5);
830 | logDefault("点击 再来一组");
831 | text("再来一组").click();
832 | delay(2);//无限答题刷题库
833 | continue;
834 | }
835 | //刷一次
836 | logDefault("点击 返回");
837 | text("返回").click();
838 | delay(2);
839 | //back(); delay(1);
840 | //back(); delay(1);
841 | break;
842 |
843 | }
844 | }
845 | }
846 | }
847 |
848 | /***************************每日、每周、专项答题部分 结束***************************/
849 |
850 | /***************************挑战答题部分 开始***************************/
851 | /**
852 | * @description: 挑战答题
853 | * @param: null
854 | * @return: null
855 | */
856 | function challengeQuestion() {
857 | let conNum = 0;//连续答对的次数
858 | let lNum = 0;//轮数
859 | while (true) {
860 | delay(2);
861 | if (!className("RadioButton").exists()) {
862 | logError("没有找到题目!请检查是否进入答题界面!");
863 | logDefault("停止");
864 | break;
865 | }
866 | challengeQuestionLoop(conNum);
867 | delay(0.5);
868 | if (text("v5IOXn6lQWYTJeqX2eHuNcrPesmSud2JdogYyGnRNxujMT8RS7y43zxY4coWepspQkvw" +
869 | "RDTJtCTsZ5JW+8sGvTRDzFnDeO+BcOEpP0Rte6f+HwcGxeN2dglWfgH8P0C7HkCMJOAAAAAElFTkSuQmCC").exists())//遇到❌号,则答错了,不再通过结束本局字样判断
870 | {
871 | if (conNum >= qCount) {
872 | lNum++;
873 | }
874 | if (lNum >= lCount) {
875 | if (xxset.forever) {
876 | logDefault("无限答题开启");
877 | delay(3);//等待5秒才能开始下一轮
878 | back();
879 | //desc("结束本局").click();//有可能找不到结束本局字样所在页面控件,所以直接返回到上一层
880 | delay(2);
881 | logDefault("点击 再来一局");
882 | text("再来一局").click();
883 | delay(3);
884 | continue;
885 | }
886 | logDefault("挑战答题结束!返回积分界面!");
887 | delay(2);
888 | back();
889 | delay(1);
890 | back();
891 | delay(1);
892 | break;
893 | } else {
894 | logDefault("出现错误,等5秒开始下一轮...")
895 | delay(3);//等待5秒才能开始下一轮
896 | back();
897 | //desc("结束本局").click();//有可能找不到结束本局字样所在页面控件,所以直接返回到上一层
898 | delay(2);
899 | logDefault("点击 再来一局");
900 | text("再来一局").click();
901 | delay(4);
902 | if (conNum < 5) {
903 | conNum = 0;
904 | }
905 | }
906 | } else//答对了
907 | {
908 | conNum++;
909 | }
910 | }
911 | conNum = 0;
912 | }
913 |
914 | /**
915 | * @description: 每次答题循环
916 | * @param: conNum 连续答对的次数
917 | * @return: null
918 | */
919 | function challengeQuestionLoop(conNum) {
920 | let ClickAnswer;
921 | if (className("ListView").exists()) {
922 | var question = className("ListView").findOnce().parent().child(0).text();
923 | logDefault((conNum + 1).toString() + ".题目:" + question);
924 | logDefault("------------------------");
925 | } else {
926 | logError("提取题目失败!");
927 | let listArray = className("ListView").findOnce().children();//题目选项列表
928 | let i = random(0, listArray.length - 1);
929 | listArray[i].child(0).click();//随意点击一个答案
930 | ClickAnswer = listArray[i].child(0).child(1).text();
931 | //记录已点击答案
932 | logDefault("随机点击:" + ClickAnswer);
933 | logDefault("------------------------");
934 | return;
935 | }
936 |
937 | var chutiIndex = question.lastIndexOf("出题单位");
938 | if (chutiIndex != -1) {
939 | question = question.substring(0, chutiIndex - 2);
940 | }
941 |
942 | if (conNum >= qCount)//答题次数足够退出,每轮5次
943 | {
944 | let listArray = className("ListView").findOnce().children();//题目选项列表
945 | let i = random(0, listArray.length - 1);
946 | logDefault("今天答题次数已够,随机点击一个答案");
947 | listArray[i].child(0).click();//随意点击一个答案
948 | ClickAnswer = listArray[i].child(0).child(1).text();
949 | //记录已点击答案
950 | logDefault("随机点击:" + ClickAnswer);
951 | logDefault("------------------------");
952 | //随机点击答案正确,更新到本地题库tiku表
953 | delay(0.5);//等待0.5秒,是否出现X
954 | if (!text("v5IOXn6lQWYTJeqX2eHuNcrPesmSud2JdogYyGnRNxujMT8RS7y43zxY4coWepspQkvw" +
955 | "RDTJtCTsZ5JW+8sGvTRDzFnDeO+BcOEpP0Rte6f+HwcGxeN2dglWfgH8P0C7HkCMJOAAAAAElFTkSuQmCC").exists()) {
956 | logDefault("随机点击答案正确,更新至本地题库");
957 | UpdateOrDeleteTK('up', question, ClickAnswer);//添加或更新到本地题库
958 | }
959 | return;
960 | }
961 |
962 | var options = [];//选项列表
963 | if (className("ListView").exists()) {
964 | className("ListView").findOne().children().forEach(child => {
965 | var answer_q = child.child(0).child(1).text();
966 | options.push(answer_q);
967 | });
968 | } else {
969 | logError("从页面获取答案失败!");
970 | return;
971 | }
972 |
973 | // 判断是否为字形题,网络搜题和本地搜题
974 | question = question.replace(/\s/g, "");
975 |
976 | if (question == ziXingTi.replace(/\s/g, "")) {
977 | question = question + options[0]; //字形题在题目后面添加第一选项
978 | }
979 |
980 | var answer = getAnswer(question);
981 | if (/^[a-zA-Z]{1}$/.test(answer)) {//如果为ABCD形式
982 | var indexAnsTiku = indexFromChar(answer.toUpperCase());
983 | answer = options[indexAnsTiku];
984 | }
985 |
986 | let hasClicked = false;
987 | let listArray = className("ListView").findOnce().children();//题目选项列表
988 |
989 | logInfo("答案:" + answer);
990 | //如果找到答案
991 | if (answer.length != 0)//如果到答案
992 | {
993 | var clickAns = "";
994 | listArray.forEach(item => {
995 | var listDescStr,listDescStrc;
996 | try{
997 | listDescStr = item.child(0).child(1).text();
998 | listDescStrc = listDescStr.replace(/\s/g, "");
999 | }catch(e){
1000 | logError(e);
1001 | logError("出现错误,请检查4");
1002 | }
1003 | if (listDescStr == answer || listDescStrc == answer) {
1004 | clickAns = answer;
1005 | //显示 对号
1006 | var b = item.child(0).bounds();
1007 | var tipsWindow = drawfloaty(b.left, b.top);
1008 | //随机时长点击
1009 | delay(0.1);
1010 | //点击
1011 | item.child(0).click();
1012 | hasClicked = true;
1013 | delay(0.1);
1014 | //消失 对号
1015 | tipsWindow.close();
1016 | }
1017 | });
1018 | }
1019 | if (!hasClicked || answer.length == 0) {//如果没有点击成功,或找不到题目
1020 | logError("未找到答案或未能成功点击,准备随机点击");
1021 | delay(0.3);
1022 | let i = random(0, listArray.length - 1);
1023 | listArray[i].child(0).click();//随意点击一个答案
1024 | ClickAnswer = listArray[i].child(0).child(1).text();
1025 | //记录已点击答案
1026 | logDefault("随机点击:" + ClickAnswer);
1027 | //随机点击答案正确,更新到本地题库tiku表
1028 | delay(0.5);//等待0.5秒,是否出现X
1029 | if (!text("v5IOXn6lQWYTJeqX2eHuNcrPesmSud2JdogYyGnRNxujMT8RS7y43zxY4coWepspQkvw" +
1030 | "RDTJtCTsZ5JW+8sGvTRDzFnDeO+BcOEpP0Rte6f+HwcGxeN2dglWfgH8P0C7HkCMJOAAAAAElFTkSuQmCC").exists()) {
1031 | logDefault("随机点击答案正确,正在准备更新本地题库");
1032 | UpdateOrDeleteTK('up', question, ClickAnswer);//添加或更新到本地题库
1033 | }
1034 | } else {//从题库中找到答案,点击成功,但如果错误
1035 | delay(0.5);//等待0.5秒,是否出现X
1036 | if (text("v5IOXn6lQWYTJeqX2eHuNcrPesmSud2JdogYyGnRNxujMT8RS7y43zxY4coWepspQkvw" +
1037 | "RDTJtCTsZ5JW+8sGvTRDzFnDeO+BcOEpP0Rte6f+HwcGxeN2dglWfgH8P0C7HkCMJOAAAAAElFTkSuQmCC").exists()) {
1038 | logDefault("题库答案点击错误,删除本地题库的错误答案");
1039 | UpdateOrDeleteTK('del', question, answer);//删除本地题库的错误答案
1040 | }
1041 | }
1042 | logDefault("------------------------");
1043 | }
1044 |
1045 | /***************************挑战答题部分 结束***************************/
1046 |
1047 | function main() {
1048 | console.setPosition(0, device.height / 2);
1049 | console.show();
1050 | delay(1);
1051 |
1052 | if (className("android.view.View").text("开始比赛").exists()) {//争上游答题开始页
1053 | logDefault("开始争上游答题");
1054 | zsyQuestion();
1055 | } else if (className("android.view.View").text("开始对战").exists()) {//双人对战开始页
1056 | logDefault("开始双人对战答题");
1057 | SRQuestion();
1058 | } else if ((textStartsWith("填空题").exists() || textStartsWith("多选题").exists() || textStartsWith("单选题").exists())) {//每日答题等有单选或多选题
1059 | logDefault("开始 每日/每周/专项 答题");
1060 | dailyQuestion();
1061 | } else if (className("ListView").exists()) {//答题界面
1062 | var questionNum = className("ListView").findOnce().parent().child(0).text().substring(0, 2); //争上游和对战题目前带序号1.
1063 | if (questionNum != "1.") {
1064 | //不含序号“1.”,且不提示单选或多选题,则判断为挑战答题界面
1065 | logDefault("准备开始挑战答题");
1066 | challengeQuestion();
1067 | }
1068 | } else {
1069 | logError("没有找到答题开始页!");
1070 | logDefault("");
1071 | //打开我要答题界面
1072 | logDefault("请手动打开答题界面再重试 !");
1073 | logDefault("争上游和双人挑战在 开始挑战/对战 的界面)");
1074 | }
1075 | //console.hide();
1076 | }
1077 |
1078 | //main();
1079 | module.exports = main;
1080 |
--------------------------------------------------------------------------------
/!xxqg_v3.1.3(fixall).js:
--------------------------------------------------------------------------------
1 | importClass(android.database.sqlite.SQLiteDatabase);
2 |
3 | var aCount = 6;//文章默认学习篇数
4 | var vCount = 6;//小视频默认学习个数
5 | var cCount = 1;//评论次数
6 | var sCount = 2;//分享次数
7 | var zCount = 2;//争上游答题轮数
8 | // var weekAndSpecialCount = 5 //每周答题和专项答题翻页次数
9 | var aTime = 60 + random(0, 10);//每篇文章学习-60秒 60*6≈360秒=6分钟
10 | var vTime = 15 + random(5, 10);//每个小视频学习-15秒
11 | var rTime = 360 + random(5, 10);//广播收听6分 * 60 = 360秒
12 | //随机加5-15秒学习时长
13 |
14 | var commentText = ["支持党,支持国家!", "为实现中华民族伟大复兴而不懈奋斗!", "不忘初心,牢记使命"];//评论内容,可自行修改,大于5个字便计分
15 | var num = random(0, commentText.length - 1);//随机数
16 | var xxset = JSON.parse(files.read("/sdcard/Download/config.txt"));
17 | var aCatlog = xxset.article;//文章学习类别,可自定义修改为“要闻”、“新思想”等
18 | // var aCat = ["推荐", "要闻", "综合"];
19 | // var aCatlog = aCat[0];//文章学习类别,随机取"推荐","要闻","综合","实践"
20 |
21 | var asub = 2; //订阅数
22 | var lCount = 1;//挑战答题轮数
23 | var qCount = randomNum(5, 7);//挑战答题每轮答题数(5~7随机)
24 | var myScores = {};//分数
25 | var customize_flag = true;//自定义运行标志,true:1/false:0
26 |
27 | var vCat = ["第一频道", "学习视频", "联播频道"];
28 | var vCatlog = vCat[num]; //视频学习类别,随机取 "第一频道"、"学习视频"、"联播频道"
29 |
30 | var xxScores; //累计学习积分
31 | var date_string = getTodayDateString();//获取当天日期字符串,定义为全局变量,方便其他函数调用
32 | var ziXingTi = "选择词语的正确词形。"; //字形题,已定义为全局变量
33 | var zsyDelay = 50; //单位为ms毫秒,示例为0-100的随机值,定义争上游答题延时时间,参考某些学习工具的延时时间为100ms,即0.1秒,默认的delay为随机500ms以上
34 |
35 | var user = "";
36 | var path = files.path("/sdcard/Download/tiku.db");
37 | var update2server = xxset.update2server; //上传到自己的服务器
38 | var weekdt = xxset.weekdt;
39 | var specialdt = xxset.specialdt;
40 | /**
41 | * @description: 生成从minNum到maxNum的随机数
42 | * @param: minNum-较小的数
43 | * @param: maxNum-较大的数
44 | * @return: null
45 | */
46 | function randomNum(minNum, maxNum) {
47 | switch (arguments.length) {
48 | case 1:
49 | return parseInt(Math.random() * minNum + 1, 10);
50 | case 2:
51 | return parseInt(Math.random() * (maxNum - minNum + 1) + minNum, 10);
52 | default:
53 | return 0;
54 | }
55 | }
56 | function updateToServer(question, answer) {
57 | //上传到服务器
58 | if (update2server) {
59 | logInfo("开始上传...")
60 | var res = http.post("http://bldsj.zih718.com:8088/insertOrUpdate",
61 | {"question": question, "answer": answer});
62 | var code = res.body.json();
63 | if (code == 200) {
64 | logInfo("成功");
65 | }else if (code == 202) {
66 | logInfo("已存在.");
67 | }
68 | }
69 | }
70 | /**
71 | * @description: 延时函数
72 | * @param: seconds-延迟秒数
73 | * @return: null
74 | */
75 | function delay(seconds) {
76 | sleep(1000 * seconds + randomNum(0, 500));//sleep函数参数单位为毫秒所以乘1000
77 | }
78 |
79 | function logDefault(str) {
80 | console.log(str);
81 | }
82 |
83 | function logInfo(str) {
84 | console.info(str);
85 | }
86 |
87 | function logError(str) {
88 | console.error(str);
89 | }
90 |
91 | /**
92 | * @description: 读取文章数据库
93 | * @param: title,date
94 | * @return: res
95 | */
96 | function getLearnedArticle(title, date) {
97 | rtitle = title.replace("'", "''");
98 | //创建或打开数据库
99 | var db = SQLiteDatabase.openOrCreateDatabase(path, null);
100 | var createTable = "\
101 | CREATE TABLE IF NOt EXISTS learnedArticles(\
102 | title CHAR(253),\
103 | date CHAR(100)\
104 | );";
105 | db.execSQL(createTable);
106 | var sql = "SELECT * FROM learnedArticles WHERE title = '" + user + rtitle + "' AND date = '" + date + "'";
107 | var cursor = db.rawQuery(sql, null);
108 | var res = cursor.moveToFirst();
109 | cursor.close();
110 | db.close();
111 | return res;
112 | }
113 |
114 | /**
115 | * @description: 获取的文章题目写入数据库
116 | * @param: title,date
117 | * @return: res
118 | */
119 | function insertLearnedArticle(title, date) {
120 | rtitle = title.replace("'", "''");
121 | var db = SQLiteDatabase.openOrCreateDatabase(path, null);
122 | var createTable = "\
123 | CREATE TABLE IF NOt EXISTS learnedArticles(\
124 | title CHAR(253),\
125 | date CHAR(100)\
126 | );";
127 | db.execSQL(createTable);
128 | var sql = "INSERT INTO learnedArticles VALUES ('" + user + rtitle + "','" + date + "')";
129 | db.execSQL(sql);
130 | db.close();
131 | }
132 |
133 | /**
134 | * @description: 文章学习计时(弹窗)函数
135 | * @param: n-文章标号 seconds-学习秒数
136 | * @return: null
137 | */
138 | function article_timing(n, seconds) {
139 | seconds = seconds + randomNum(0, 10)
140 | let h = device.height;//屏幕高
141 | let w = device.width;//屏幕宽
142 | let x = (w / 3) * 2;
143 | let h1 = (h / 6) * 5;
144 | let h2 = (h / 6);
145 | for (var i = 0; i < seconds; i++) {
146 | while (!textContains("欢迎发表你的观点").exists())//如果离开了文章界面则一直等待
147 | {
148 | logError("当前已离开第" + (n + 1) + "文章界面,请重新返回文章页面...");
149 | delay(2);
150 | if (textContains("欢迎发表你的观点").exists()) {
151 | break;//防止通知/下拉菜单等不改变阅读界面但误判为离开
152 | }
153 | logDefault("重新返回到学习主页,如果一直失败,请手动返回!");
154 | delay(1);
155 | logDefault("阅读失败");
156 | back();
157 | return false; //返回阅读失败
158 | }
159 | if (i % 5 == 0)//每5秒打印一次学习情况
160 | {
161 | logInfo("第" + (n + 1) + "篇文章已经学习" + (i + 1) + "秒,剩余" + (seconds - i - 1) + "秒!");
162 | }
163 | delay(1);
164 | if (i % 10 == 0)//每10秒滑动一次,如果android版本<7.0请将此滑动代码删除
165 | {
166 | toast("这是防息屏toast,请忽视-。-");
167 | if (i <= seconds / 2) {
168 | swipe(x, h1, x, h2, 500);//向下滑动
169 | } else {
170 | swipe(x, h2, x, h1, 500);//向上滑动
171 | }
172 | }
173 | }
174 | return true;//返回阅读成功
175 | }
176 |
177 | /**
178 | * @description: 视频学习计时(弹窗)函数
179 | * @param: n-视频标号 seconds-学习秒数
180 | * @return: null
181 | */
182 | function video_timing_bailing(n, seconds) {
183 | let h = device.height;//屏幕高
184 | let w = device.width;//屏幕宽
185 | let x = (w / 3) * 2;//横坐标2分之3处
186 | let h1 = (h / 6) * 5;//纵坐标6分之5处
187 | let h2 = (h / 6);//纵坐标6分之1处
188 | for (var i = 0; i < seconds; i++) {
189 | if (desc("继续播放")) {
190 | click("继续播放");
191 | }
192 | while (!textContains("分享").exists() || id("home_bottom_tab_button_work").exists())//如果离开了百灵小视频界面则一直等待
193 | {
194 | logError("当前已离开第" + (n + 1) + "个小视频界面,请重新返回视频");
195 | delay(2);
196 | if (textContains("/ 00").exists()) {
197 | break;//防止通知/下拉菜单等不改变阅读界面但误判为离开
198 | logDefault("已返回小视频播放界面");
199 | }
200 | logDefault("重新返回到学习主页,如果一直失败,请手动返回!");
201 | delay(1);
202 | logDefault("百灵视频观看失败");
203 | return false; //返回阅读失败
204 | }
205 | if (textContains("即将播放").exists()) {
206 | i = seconds - 2;
207 | //logDefault("即将播放下一个小视频"+i);
208 | }
209 | //持续学习
210 | delay(1);
211 | if (i % 10 == 0)//每10秒打印一次学习情况
212 | {
213 | logInfo("第" + (n + 1) + "个小视频已经观看" + (i + 1) + "秒,剩余" + (seconds - i - 1) + "秒!");
214 | toast("防息屏弹窗,请无视");
215 | }
216 | }
217 | delay(1);
218 | return true;//返回阅读成功
219 | }
220 |
221 | /**
222 | * @description: 新闻联播小视频学习计时(弹窗)函数
223 | * @param: n-视频标号 seconds-学习秒数
224 | * @return: null
225 | */
226 | function video_timing_news(n, seconds) {
227 | seconds = seconds + randomNum(0, 10);//加随机时间
228 | for (var i = 0; i < seconds; i++) {
229 | if (desc("继续播放")) {
230 | click("继续播放");
231 | }
232 | delay(1);
233 | var f = 0;//记录返回次数
234 | while (!textContains("欢迎发表你的观点").exists())//如果离开了联播小视频界面则一直等待
235 | {
236 | logError("当前已离开第" + (n + 1) + "个新闻小视频界面,请重新返回视频");
237 | delay(2);
238 | if (textContains("欢迎发表你的观点").exists() || textContains("展开").exists()) {
239 | break;//防止通知/下拉菜单等不改变阅读界面但误判为离开
240 | }
241 | logDefault("重新返回到学习主页,如果一直失败,请手动返回!");
242 | delay(1);
243 | logDefault("视频学习失败");
244 | return false; //返回阅读失败
245 |
246 | }
247 | if (i % 10 == 0)//每10秒打印一次学习情况
248 | {
249 | logInfo("第" + (n + 1) + "个小视频已经观看" + (i + 1) + "秒,剩余" + (seconds - i - 1) + "秒!");
250 | toast("防息屏弹窗,请无视");
251 | }
252 | }
253 | //logDefault("305阅读成功");
254 | return true; //返回阅读成功
255 | }
256 |
257 | /**
258 | * @description: 广播学习计时(弹窗)函数
259 | * @param: r_time-已经收听的时间 seconds-学习秒数
260 | * @return: null
261 | */
262 | function radio_timing(r_time, seconds) {
263 | for (var i = 0; i < seconds; i++) {
264 | delay(1);
265 | if (i % 5 == 0)//每5秒打印一次信息
266 | {
267 | logInfo("广播已经收听" + (i + 1 + r_time) + "秒,剩余" + (seconds - i - 1) + "秒!");
268 | }
269 | if (i % 15 == 0)//每15秒弹一次窗防止息屏
270 | {
271 | toast("这是防息屏弹窗,可忽略-. -");
272 | }
273 | }
274 | }
275 |
276 | /**
277 | * @description: 日期转字符串函数
278 | * @param: y,m,d 日期数字 2019 1 1
279 | * @return: s 日期字符串 "2019-xx-xx"
280 | */
281 | function dateToString(y, m, d) {
282 | var year = y.toString();
283 | if ((m + 1) < 10) {
284 | var month = "0" + (m + 1).toString();
285 | } else {
286 | var month = (m + 1).toString();
287 | }
288 | if (d < 10) {
289 | var day = "0" + d.toString();
290 | } else {
291 | var day = d.toString();
292 | }
293 | var s = year + "-" + month + "-" + day;//年-月-日
294 | return s;
295 | }
296 |
297 | /**
298 | * @description: 获取当天日期字符串函数
299 | * @param: null
300 | * @return: s 日期字符串 "2019-xx-xx"
301 | */
302 | function getTodayDateString() {
303 | var date = new Date();
304 | var y = date.getFullYear();
305 | var m = date.getMonth();
306 | var d = date.getDate();
307 |
308 | var s = dateToString(y, m, d);//年-月-日
309 | return s
310 | }
311 |
312 | /**
313 | * @description: 获取昨天日期字符串函数
314 | * @param: null
315 | * @return: s 日期字符串 "2019-xx-xx"
316 | */
317 | function getYestardayDateString() {
318 | var date = new Date();
319 | date.setDate(date.getDate() - 1);
320 | var y = date.getFullYear();
321 | var m = date.getMonth();
322 | var d = date.getDate();
323 | var s = dateToString(y, m, d);//年-月-日
324 | return s
325 | }
326 |
327 | /**
328 | * @description: 文章学习函数 (阅读文章+文章学习时长)---6+6=12分
329 | * @param: null
330 | * @return: null
331 | */
332 | function articleStudy(x) {
333 | while (!desc("工作").exists());//等待加载出主页
334 | var listView = className("ListView");//获取文章ListView控件用于翻页
335 | if (x == 0) {
336 | desc("工作").click();//点击主页正下方的"学习"按钮
337 | delay(2);
338 | click(aCatlog);
339 | }
340 | delay(2);
341 | var zt_flag = false;//判断进入专题界面标志
342 | var fail = 0;//点击失败次数
343 | var date_string = getTodayDateString();//获取当天日期字符串
344 | for (var i = 0, t = 0; i < aCount;) {
345 | try {
346 | if ((id("general_card_title_id").findOnce(t).parent().parent().click() || id("general_card_title_id").findOnce(t).parent().parent().parent().click()) == true) {
347 | delay(5);
348 | // // delay(10); //等待加载出文章页面,后面判断是否进入了视频文章播放要用到
349 | //获取当前正在阅读的文章标题
350 | let n = 0;
351 | while (!textContains("欢迎发表你的观点").exists()) {//如果没有找到评论框则认为没有进入文章界面,一直等待
352 | delay(2);
353 | console.warn("正在等待加载文章界面...");
354 | if (n > 3) {//等待超过3秒则认为进入了专题界面,退出进下一篇文章
355 | console.warn("没找到评论框!该界面非文章界面!");
356 | zt_flag = true;
357 | break;
358 | }
359 | n++;
360 | }
361 | if (text("展开").exists()) {//如果存在“展开”则认为进入了文章栏中的视频界面需退出
362 | console.warn("进入了视频界面,退出并进入下一篇文章!");
363 | t++;
364 | back();
365 | // if (rTime != 0) {
366 | // while (!desc("工作").exists());
367 | // console.info("因为广播被打断,重新收听广播...");
368 | // delay(0.5);
369 | // listenToRadio();//听电台广播
370 | // while (!desc("工作").exists());
371 | // desc("工作").click();
372 | // }
373 | // delay(2);
374 | continue;
375 | }
376 | if (zt_flag == true) {//进入专题页标志
377 | console.warn("进入了专题界面,即将退出并进下一篇文章!");
378 | t++;
379 | back();
380 | delay(2);
381 | zt_flag = false;
382 | continue;
383 | }
384 | var currentNewsTitle = ""
385 | if (id("xxqg-article-header").exists()) {
386 | currentNewsTitle = id("xxqg-article-header").findOne().child(0).text(); // 最终解决办法
387 | } else if (textContains("来源").exists()) {
388 | currentNewsTitle = textContains("来源").findOne().parent().children()[0].text();
389 | } else if (textContains("作者").exists()) {
390 | currentNewsTitle = textContains("作者").findOne().parent().children()[0].text();
391 | } else if (descContains("来源").exists()) {
392 | currentNewsTitle = descContains("来源").findOne().parent().children()[0].desc();
393 | } else if (descContains("作者").exists()) {
394 | currentNewsTitle = descContains("作者").findOne().parent().children()[0].desc();
395 | } else {
396 | logDefault("无法定位文章标题,即将退出并阅读下一篇")
397 | t++;
398 | back();
399 | delay(2);
400 | continue;
401 | }
402 | if (currentNewsTitle == "") {
403 | logDefault("标题为空,即将退出并阅读下一篇")
404 | t++;
405 | back();
406 | delay(2);
407 | continue;
408 | }
409 | var flag = getLearnedArticle(currentNewsTitle, date_string);
410 | if (flag) {
411 | //已经存在,表明阅读过了
412 | logInfo("该文章已经阅读过,即将退出并阅读下一篇");
413 | t++;
414 | back();
415 | delay(2);
416 | continue;
417 | }
418 | logDefault("正在学习第" + (i + 1) + "篇文章...");
419 | if (sCount != 0)//分享2篇文章
420 | {
421 | CollectAndShare(i);//分享 若运行到此报错请注释本行!
422 | sCount--;
423 | }
424 | if (cCount != 0)//评论1次
425 | {
426 | Comment(i);//评论
427 | cCount--;
428 | }
429 | fail = 0;//失败次数清0
430 |
431 | //开始循环进行文章学习
432 | var atiming=article_timing(i, aTime);
433 | if (atiming) {
434 | logDefault("文章阅读完成,添加到数据库...");
435 | logDefault("文章标题:" + currentNewsTitle);
436 | insertLearnedArticle(currentNewsTitle, date_string);
437 | }
438 | delay(2);
439 | back();//返回主界面
440 | while (!id("home_bottom_tab_button_work").exists()){
441 | logDefault("正在等待加载出主页...")
442 | delay(2);
443 | };//等待加载出主页
444 | delay(2);
445 | i++;
446 | t++;//t为实际点击的文章控件在当前布局中的标号,和i不同,勿改动!
447 | } else {
448 | t++;
449 | }
450 | } catch (e) {
451 | listView.scrollForward();
452 | t = 0;
453 | delay(1.5);
454 | }
455 | }
456 |
457 | }
458 |
459 | function articleStudy1(x) {
460 | while (!id("home_bottom_tab_button_work").exists()) ;//等待加载出主页
461 | var listView = className("ListView");//获取文章ListView控件用于翻页
462 | let s = "学习平台";//获取当天日期字符串
463 | if (x == 0) {
464 | id("home_bottom_tab_button_work").findOne().click();//点击主页正下方的"学习"按钮
465 | delay(2);
466 | }
467 | logDefault("点击 " + aCatlog);
468 | delay(2);
469 | click(aCatlog);
470 | delay(2);
471 | var zt_flag = false;//判断进入专题界面标志
472 | var fail = 0;//点击失败次数
473 | //logDefault('文章类别:' + aCatlog + '关键词:'+ s)
474 | for (var i = 0, t = 0; i < aCount;) {
475 | logDefault('文章类别:' + aCatlog);
476 | if (click(s, t) == true)//如果点击成功则进入文章页面,不成功意味着本页已经到底,要翻页
477 | {
478 | logDefault("点击成功,关键词:"+s+"t="+t);
479 | let n = 0;
480 | while (!textContains("欢迎发表你的观点").exists())//如果没有找到评论框则认为没有进入文章界面,一直等待
481 | {
482 | delay(2);
483 | logInfo("正在等待加载文章界面...");
484 | if (n > 3)//等待超过3秒则认为进入了专题界面,退出进下一篇文章
485 | {
486 | logInfo("没找到评论框!该界面非文章界面!");
487 | zt_flag = true;
488 | break;
489 | }
490 | n++;
491 | }
492 | if (textContains("展开").exists())//如果存在“央视网、中央广播电视总台、播放、展开”则认为进入了视频需退出。关键词测试
493 | {
494 | logInfo("进入视频界面,退出并进下一篇文章!");
495 | t++;
496 | back();
497 | delay(1);
498 | num = random(0, commentText.length - 1); //重取随机数
499 | aCatlog = aCat[num];
500 | //s = "“学习强国”学习平台";
501 | logDefault('重新选择文章类别1:' + aCatlog + ',关键词:' + s);
502 | logDefault("点击:" + aCatlog);
503 | delay(1);
504 | click(aCatlog);
505 | delay(1);
506 | continue;
507 | }
508 |
509 | if (id("v_play").exists() || id("bg_play").exists())//进入电台页面2020.09.28
510 | {
511 | logInfo("进入电台界面,退出并进下一篇文章!");
512 | t++;
513 | if (id("btn_back").exists()) {
514 | logDefault("点击 btn_back");
515 | id("btn_back").findOnce().click();//返回 2020.09.28需关闭电台收听
516 | } else {
517 | back;
518 | }//返回 2020.09.28需关闭电台收听
519 | if (!id("home_bottom_tab_button_work").exists()) {
520 | start_app(1);
521 | delay(1);
522 | id("home_bottom_tab_button_work").findOne().click();
523 | }//等待加载出主页
524 | delay(1);
525 | num = random(0, commentText.length - 1); //重取随机数
526 | aCatlog = aCat[num];
527 | //s = "“学习强国”学习平台";
528 | logDefault('重新选择文章类别2:' + aCatlog + ',关键词:' + s)
529 | logDefault("点击:" + aCatlog);
530 | delay(1);
531 | click(aCatlog);
532 | delay(1);
533 | continue;
534 | }
535 |
536 | if (zt_flag == true) {//进入专题页标志
537 | logInfo("进入了专题界面,退出并进下一篇文章!")
538 | t++;
539 | back();
540 | delay(1);
541 | zt_flag = false;
542 | continue;
543 | }
544 | delay(1);
545 | //记录已学习的文章
546 | var currentNewsTitle = ""
547 | if (id("xxqg-article-header").exists()) {
548 | currentNewsTitle = id("xxqg-article-header").findOne().child(0).text(); // 最终解决办法
549 | } else if (textContains("来源").exists()) {
550 | currentNewsTitle = textContains("来源").findOne().parent().children()[0].text();
551 | } else if (textContains("作者").exists()) {
552 | currentNewsTitle = textContains("作者").findOne().parent().children()[0].text();
553 | } else if (descContains("来源").exists()) {
554 | currentNewsTitle = descContains("来源").findOne().parent().children()[0].desc();
555 | } else if (descContains("作者").exists()) {
556 | currentNewsTitle = descContains("作者").findOne().parent().children()[0].desc();
557 | } else {
558 | logDefault("无法定位文章标题,即将退出并阅读下一篇")
559 | t++;
560 | back();
561 | delay(1.5);
562 | continue;
563 | }
564 | if (currentNewsTitle == "") {
565 | logDefault("标题为空,即将退出并阅读下一篇")
566 | t++;
567 | back();
568 | delay(1.5);
569 | continue;
570 | }
571 | var flag = getLearnedArticle(currentNewsTitle, date_string);
572 | if (flag) {
573 | //已经存在,表明阅读过了
574 | logInfo("该文章已经阅读过,即将退出并阅读下一篇");
575 | t++;
576 | back();
577 | num = random(0, commentText.length - 1);//随机数
578 | aCatlog = aCat[num];
579 | logDefault('重新选择文章类别3:' + aCatlog);
580 | logDefault("点击:" + aCatlog);
581 | delay(1);
582 | click(aCatlog);
583 | delay(2);
584 | continue;
585 | } else {
586 | //没阅读过,添加到数据库
587 | //insertLearnedArticle(currentNewsTitle, date_string);
588 | }
589 |
590 | logDefault("正在学习第" + (i + 1) + "篇文章...");
591 | fail = 0;//失败次数清0
592 |
593 | if (sCount != 0)//分享2篇文章
594 | {
595 | CollectAndShare(i);//分享 若运行到此报错请注释本行!
596 | sCount--;
597 | }
598 | if (cCount != 0)//评论1次
599 | {
600 | Comment(i);//评论
601 | cCount--;
602 | }
603 |
604 | if (article_timing(i, aTime)) { //如果阅读成功
605 | //添加标题到数据库
606 | logDefault("文章阅读成功,记录文章标题");
607 | logDefault('文章名称:' + currentNewsTitle);
608 | insertLearnedArticle(currentNewsTitle, date_string);
609 | delay(1);
610 | } else {
611 | if (!id("home_bottom_tab_button_work").exists()) {
612 | start_app(1);
613 | delay(1);
614 | id("home_bottom_tab_button_work").findOne().click();
615 | }//等待加载出主页
616 | delay(1);
617 | num = random(0, commentText.length - 1);//随机数
618 | aCatlog = aCat[num];
619 | logDefault('选择文章类别4:' + aCatlog);
620 | logDefault("点击:" + aCatlog);
621 | delay(1);
622 | click(aCatlog); //重新进入文章页面
623 | delay(2);
624 | }
625 | if (textContains("欢迎发表你的观点").exists() && !id("home_bottom_tab_button_work").exists()) {
626 | back();//返回主界面
627 | delay(1);
628 | }
629 | if (!id("home_bottom_tab_button_work").exists()) {
630 | start_app(1);
631 | delay(1);
632 | id("home_bottom_tab_button_work").findOne().click();
633 | delay(1);
634 | logDefault("点击5:" + aCatlog);
635 | delay(1);
636 | click(aCatlog); //重新进入文章页面
637 | }//等待加载出主页
638 | delay(1);
639 | i++;
640 | t++;//t为实际点击的文章控件在当前布局中的标号,和i不同,勿改动!
641 | } else {
642 | if (id("v_play").exists() || id("bg_play").exists())//进入电台页面2020.09.28
643 | {
644 | logInfo("进入电台界面,退出并进下一篇文章!");
645 | t++;
646 | if (id("btn_back").exists()) {
647 | id("btn_back").findOnce().click();//返回 2020.09.28需关闭电台收听
648 | } else {
649 | back;
650 | }
651 | if (!id("home_bottom_tab_button_work").exists()) {
652 | start_app(1);
653 | delay(1);
654 | id("home_bottom_tab_button_work").findOne().click();
655 | }//等待加载出主页
656 | delay(1);
657 | num = random(0, commentText.length - 1); //重取随机数
658 | aCatlog = aCat[num];
659 | //s = "“学习强国”学习平台";
660 | logDefault('重新选择文章类别6:' + aCatlog + ',关键词:' + s);
661 | logDefault("点击:" + aCatlog);
662 | delay(1);
663 | click(aCatlog);
664 | delay(1);
665 | continue;
666 | }
667 | /*
668 | if (i == 0)//如果第一次点击就没点击成功则认为首页无当天文章
669 | {
670 | //date_string = getYestardayDateString();
671 | //s = date_string;
672 | //s = "“学习强国”学习平台";
673 | num = random(0, commentText.length - 1) ; //重取随机数
674 | aCatlog = aCat[num] ;
675 | click(aCatlog);
676 | logInfo("首页没有找到当天文章,即将学习昨日新闻!"+aCatlog + s);
677 | continue;
678 | }
679 | */
680 | if (fail > 3)//连续翻几页没有点击成功则认为今天的新闻还没出来,学习昨天的
681 | {
682 | /*date_string = getYestardayDateString();
683 | s = date_string;*/
684 | //s = "学习平台";
685 | num = random(0, commentText.length - 1); //重取随机数
686 | aCatlog = aCat[num];
687 | click(aCatlog);
688 | logInfo("重新随机阅读7!" + aCatlog + s);
689 | fail = 0;//失败次数清0
690 | continue;
691 | }
692 |
693 | if (!textContains(s).exists())//当前页面当天新闻
694 | {
695 | fail++;//失败次数加一
696 | }
697 | listView.scrollForward();//向下滑动(翻页)
698 | t = 0;
699 | delay(1.5);
700 | }
701 | }
702 | }
703 |
704 | /**
705 | * @description: “百灵”小视频学习函数
706 | * @param: vCount,vTime
707 | * @return: null
708 | */
709 | function videoStudy_bailing(vCount, vTime) {
710 | let h = device.height;//屏幕高
711 | let w = device.width;//屏幕宽
712 | let x = (w / 3) * 2;//横坐标2分之3处
713 | let h1 = (h / 6) * 5;//纵坐标6分之5处
714 | let h2 = (h / 6);//纵坐标6分之1处
715 | logDefault("开始观看百灵小视频,返回主页");
716 | while (!id("home_bottom_tab_button_work").exists()) ;//等待加载出主页
717 | logDefault("点击 学习 按钮");
718 | id("home_bottom_tab_button_work").findOne().click();//点击主页正下方的"学习"按钮
719 | delay(2);
720 | logDefault("点击 百灵");
721 | click("百灵");
722 | delay(2);
723 | logDefault("点击 竖");
724 | click("竖");
725 | delay(2);
726 | logDefault("根据坐标点击第一个视频");
727 | var a = className("FrameLayout").depth(23).findOnce(0);//根据控件搜索视频框,但部分手机不适配,改用下面坐标点击
728 | a.click();
729 | // click((w / 2) + random() * 10, h / 4);//坐标点击第一个视频
730 | delay(2);
731 |
732 | for (var i = 0; i < vCount;) {
733 | logDefault("正在观看第" + (i + 1) + "个小视频");
734 | let nextVideo = false;
735 | var currentNewsTitle = ""
736 | while (true) {
737 | try {
738 | if (textContains("分享").exists) {//百灵视频
739 | currentNewsTitle = textContains("分享").findOne().parent().parent().parent().children()[1].text(); //10.29测试,央视网/中央广播电视总台 视频标题
740 | //logDefault('视频名称1:'+currentNewsTitle);
741 | } else {
742 | logDefault("无法定位视频标题,即将退出并观看下一个")
743 | nextVideo = true;
744 | }
745 | if (currentNewsTitle == "") {
746 | logDefault("标题为空,即将退出并观看下一个")
747 | nextVideo = true;
748 | } else {
749 | var flag = getLearnedArticle(currentNewsTitle, date_string);
750 | if (flag) {
751 | //已经存在,表明阅读过了
752 | logInfo("该视频已观看过,即将退出并阅读下一篇");
753 | nextVideo = true;
754 | } else {
755 | logDefault('视频名称:' + currentNewsTitle);
756 | //观看的视频
757 | nextVideo = false;
758 | delay(1);
759 | break;
760 | }
761 | }
762 | if (nextVideo) {//滑动下一个视频
763 | if (textContains("竖").exists && textContains("炫").exists) {
764 | delay(2);
765 | click("竖");
766 | delay(2);
767 | click((w / 2) + random() * 10, h / 4);//坐标点击第一个视频
768 | }
769 | delay(1);
770 | swipe(x, h1, x, h2, 500);//往下翻(纵坐标从5/6处滑到1/6处)
771 | }
772 | } catch (e) {
773 | logDefault(e);
774 | logError("出现错误,请检查1!");
775 | break;
776 | }
777 | }
778 |
779 | if (video_timing_bailing(i, vTime)) {//观看百灵小视频成功
780 | //观看成功,记录已观看的视频
781 | insertLearnedArticle(currentNewsTitle, date_string);
782 | //logDefault('623记录视频名称:'+currentNewsTitle);
783 | i++;
784 | delay(1);
785 | if (i != vCount - 1) {
786 | swipe(x, h1, x, h2, 500);//往下翻(纵坐标从5/6处滑到1/6处)
787 | }
788 | } else {
789 | //观看失败
790 | logInfo("566已离开阅读界面,将退出并阅读下一篇");
791 | start_app(1);
792 | //while (!id("home_bottom_tab_button_work").exists());//等待加载出主页
793 | //id("home_bottom_tab_button_work").findOne().click();//点击主页正下方的"学习"按钮
794 | delay(2);
795 | click("百灵");
796 | delay(2);
797 | click("竖");
798 | delay(2);
799 | var a = className("FrameLayout").depth(23).findOnce(0);//根据控件搜索视频框,但部分手机不适配,改用下面坐标点击
800 | a.click();
801 | //click((w / 2) + random() * 10, h / 4);//坐标点击第一个视频
802 | delay(1);
803 | }
804 | }
805 | back();
806 | delay(2);
807 | }
808 |
809 | /**
810 | * @description:新闻联播小视频学习函数
811 | * @param: null
812 | * @return: null
813 | */
814 | function videoStudy_news() {
815 | while (!id("home_bottom_tab_button_work").exists()) ;//等待加载出主页
816 | id("home_bottom_tab_button_work").findOne().click();//点击主页正下方的"学习"按钮
817 | delay(2);
818 | logDefault("点击 电视台");
819 | click("电视台");
820 | vCatlog = vCat[num]; //视频学习类别,随机取 "第一频道"、"学习视频"、"联播频道"
821 | if (num == 0) {
822 | var s = "央视网";
823 | } else if (num == 1) {
824 | var s = "央视新闻";
825 | } else {
826 | var s = "中央广播电视总台";
827 | }
828 | delay(1);
829 | logDefault("视频学习类别随机取 " + vCatlog);
830 | delay(1);
831 | logDefault("点击 " + vCatlog);
832 | click(vCatlog);
833 | delay(2);
834 | var listView = className("ListView");//获取listView视频列表控件用于翻页
835 | var fail = 0;//点击失败次数
836 | delay(1);
837 |
838 | for (var i = 0, t = 0; i < vCount;) {
839 | logDefault('视频类别: ' + vCatlog + ',关键词: ' + s);
840 | if (click(s, t) == true) {
841 | logDefault("点击成功:s=" + s, "t=" + t)
842 | fail = 0;//失败次数清0
843 | //记录已学习的视频
844 | var currentNewsTitle = "";
845 | logDefault("")
846 | if (textContains("展开").exists) {
847 | if (s == "央视网" || s == "中央广播电视总台") {
848 | currentNewsTitle = textContains("展开").findOne().parent().parent().parent().children()[1].text(); //10.29测试,央视网/中央广播电视总台 视频标题
849 | // logDefault('视频名称1:'+currentNewsTitle);
850 | }
851 |
852 | if (s == "央视新闻") {
853 | currentNewsTitle = textContains("展开").findOne().parent().parent().parent().children()[2].text(); //10.29测试,央视新闻 视频标题
854 | //logDefault('视频名称2:'+currentNewsTitle);
855 | let currentNewsTitle1 = currentNewsTitle.substr(0, 4);
856 | //logDefault('视频名称2:'+currentNewsTitle1);
857 | if (currentNewsTitle1 == "央视新闻") {
858 | currentNewsTitle = textContains("展开").findOne().parent().parent().parent().children()[1].text();
859 | // logDefault('视频名称2:'+currentNewsTitle);
860 | }
861 | }
862 | } else {
863 | logDefault("无法定位视频标题,即将退出并观看下一个")
864 | t++;
865 | back();
866 | delay(1);
867 | continue;
868 | }
869 | if (currentNewsTitle == "") {
870 | logDefault("标题为空,即将退出并阅读下一篇")
871 | t++;
872 | back();
873 | num = random(0, commentText.length - 1);//随机数
874 | if (num == 0) {
875 | var s = "央视网";
876 | } else if (num == 1) {
877 | var s = "央视新闻";
878 | } else {
879 | var s = "中央广播电视总台";
880 | }
881 | vCatlog = vCat[num];
882 | logDefault('视频频道:' + vCatlog + ';关键词:' + s);
883 | click(vCatlog);
884 | delay(1.5);
885 | continue;
886 | }
887 | var flag = getLearnedArticle(currentNewsTitle, date_string);
888 | if (flag) {
889 | //已经存在,表明阅读过了
890 | logInfo("该视频已经阅读过,即将退出并阅读下一篇");
891 | t++;
892 | back();
893 | delay(2);
894 | continue;
895 | }
896 | logDefault("正在观看第" + (i + 1) + "个视频...");
897 | logDefault('视频名称:' + currentNewsTitle);
898 | if (sCount != 0)//分享2篇文章
899 | {
900 | CollectAndShare(i);//分享 若运行到此报错请注释本行!
901 | sCount--;
902 | }
903 | if (cCount != 0)//评论1次
904 | {
905 | Comment(i);//评论
906 | cCount--;
907 | }
908 | if (video_timing_news(i, vTime)) {
909 | //如果阅读成功
910 | //没阅读过,添加到数据库
911 | logDefault("观看视频成功,记录视频标题");
912 | logDefault('视频名称:' + currentNewsTitle);
913 | insertLearnedArticle(currentNewsTitle, date_string);
914 | delay(1);
915 | } else {
916 | start_app(1);
917 | delay(1.5);
918 | click("电视台");
919 | delay(1.5);
920 | num = random(0, commentText.length - 1);//随机数
921 | if (num == 0) {
922 | var s = "央视网";
923 | } else if (num == 1) {
924 | var s = "央视新闻";
925 | } else {
926 | var s = "中央广播电视总台";
927 | }
928 | vCatlog = vCat[num];
929 | logDefault('视频频道:' + vCatlog + ';关键词:' + s);
930 | click(vCatlog); //重新进入文章页面
931 | }
932 | if (textContains("展开").exists && !id("home_bottom_tab_button_work").exists()) {
933 | back();//返回主界面
934 | delay(1);
935 | }
936 | if (!id("home_bottom_tab_button_work").exists()) {
937 | start_app(1);
938 | delay(1.5);
939 | click("电视台");
940 | delay(1.5);
941 | click(vCatlog);
942 | }//等待加载出主页
943 | delay(1);
944 | i++;
945 | t++;
946 | if (t >= 2) {//如果是平板等设备,请尝试修改i为合适值!
947 | logDefault("翻页");
948 | listView.scrollForward();//翻页
949 | delay(2);
950 | t = 0;
951 | }
952 | } else {
953 | logDefault("点击失败:s=" + s, "t=" + t)
954 | if (fail > 3)//连续翻几页没有点击成功则改换频道
955 | {
956 | num = random(0, commentText.length - 1); //重取随机数
957 | vCatlog = vCat[num];
958 | click(vCatlog);
959 | delay(2);
960 | if (num == 0) {
961 | var s = "央视网";
962 | } else if (num == 1) {
963 | var s = "央视新闻";
964 | } else {
965 | var s = "中央广播电视总台";
966 | }
967 | delay(1);
968 | logInfo("改换:" + vCatlog + '关键词:' + s);
969 | fail = 0;//失败次数清0
970 | continue;
971 | }
972 | if (!textContains(s).exists())//未找到关键词
973 | {
974 | fail++;//失败次数加一
975 | }
976 | logDefault("翻页了");
977 | listView.scrollForward();//翻页
978 | delay(2);
979 | t = 0;
980 | }
981 | }
982 | }
983 |
984 |
985 | /**
986 | * @description: 听“电台”新闻广播函数 (视听学习+视听学习时长)---6+6=12分
987 | * @param: null
988 | * @return: null
989 | */
990 | function listenToRadio() {
991 | while (!id("home_bottom_tab_button_work").exists()) ;//等待加载出主页
992 | id("home_bottom_tab_button_work").findOne().click();//点击主页正下方的"学习"按钮
993 | delay(2);
994 | logDefault("点击 电台");
995 | click("电台");
996 | delay(1);
997 | logDefault("点击 听广播");
998 | click("听广播");
999 | delay(2);
1000 | if (textContains("最近收听").exists()) {
1001 | logDefault("点击 最近收听");
1002 | click("最近收听");
1003 | logDefault("896正在收听广播...");
1004 | delay(1);
1005 | } else if (textContains("推荐收听").exists()) {
1006 | logDefault("点击 推荐收听");
1007 | click("推荐收听");
1008 | logDefault("900正在收听广播...");
1009 | delay(1);
1010 | } else if (textContains("正在收听").exists()) {
1011 | //click("正在收听");
1012 | logDefault("已经正在收听了");
1013 | logDefault("905正在收听广播...");
1014 | delay(1);
1015 | }
1016 | logDefault("已开始收听,准备返回");
1017 | if (!id("home_bottom_tab_button_work").exists()) {
1018 | logDefault("返回主界面");
1019 | start_app(1);
1020 | }
1021 | delay(1);
1022 | }
1023 |
1024 | /**
1025 | * @description: 收藏加分享函数 (收藏+分享)---1+1=2分
1026 | * @param: i-文章标号
1027 | * @return: null
1028 | */
1029 | function CollectAndShare(i) {
1030 | while (!textContains("欢迎发表你的观点").exists())//如果没有找到评论框则认为没有进入文章界面,一直等待
1031 | {
1032 | delay(1);
1033 | logDefault("等待进入文章界面")
1034 | }
1035 | logDefault("正在进行第" + (i + 1) + "次分享...");
1036 |
1037 | var textOrder = text("欢迎发表你的观点").findOnce().drawingOrder();
1038 | // var collectOrder = textOrder + 2;
1039 | var shareOrder = textOrder + 3;
1040 | // var collectIcon = className("ImageView").filter(function (iv) {
1041 | // return iv.drawingOrder() == collectOrder;
1042 | // }).findOnce();
1043 |
1044 | var shareIcon = className("ImageView").filter(function (iv) {
1045 | return iv.drawingOrder() == shareOrder;
1046 | }).findOnce();
1047 | //var collectIcon = classNameContains("ImageView").depth(10).findOnce(0);//右下角收藏按钮
1048 | // collectIcon.click();//点击收藏
1049 | // logInfo("收藏成功!");
1050 | // delay(1);
1051 | //var shareIcon = classNameContains("ImageView").depth(10).findOnce(1);//右下角分享按钮
1052 | shareIcon.click();//点击分享
1053 | while (!textContains("分享到学习强").exists()) ;//等待弹出分享选项界面
1054 | delay(1);
1055 | click("分享到学习强国");
1056 | delay(2);
1057 | logInfo("分享成功!");
1058 | back();//返回文章界面
1059 | delay(1);
1060 | // collectIcon.click();//再次点击,取消收藏
1061 | // logInfo("取消收藏!");
1062 | // delay(1);
1063 | }
1064 |
1065 | /**
1066 | * @description: 评论函数---2分
1067 | * @param: i-文章标号
1068 | * @return: null
1069 | */
1070 | function Comment(i) {
1071 | while (!textContains("欢迎发表你的观点").exists())//如果没有找到评论框则认为没有进入文章界面,一直等待
1072 | {
1073 | delay(1);
1074 | logDefault("等待进入文章界面")
1075 | }
1076 | click("欢迎发表你的观点");//单击评论框
1077 | logDefault("正在进行第" + (i + 1) + "次评论...");
1078 | delay(1);
1079 | var num = random(0, commentText.length - 1)//随机数
1080 | setText(commentText[num]);//输入评论内容
1081 | delay(1);
1082 | click("发布");//点击右上角发布按钮
1083 | logInfo("评论成功!");
1084 | delay(2);
1085 | click("删除");//删除该评论
1086 | delay(2);
1087 | click("确认");//确认删除
1088 | logInfo("评论删除成功!");
1089 | delay(1);
1090 | }
1091 |
1092 |
1093 | /**
1094 | * @description: 本地频道
1095 | * @param: null
1096 | * @return: null
1097 | */
1098 | function localChannel() {
1099 | delay(1)
1100 | while (!id("home_bottom_tab_button_work").exists()) ;//等待加载出主页
1101 | id("home_bottom_tab_button_work").findOne().click();
1102 | logDefault("点击本地频道");
1103 | if (text("新思想").exists()) {
1104 | text("新思想").findOne().parent().parent().child(3).click();
1105 | delay(3);
1106 | className("android.support.v7.widget.RecyclerView").findOne().child(2).click();
1107 | delay(2);
1108 | logDefault("返回主界面");
1109 | back();
1110 | text("新思想").findOne().parent().parent().child(0).click();
1111 | } else {
1112 | logDefault("请手动点击本地频道!");
1113 | }
1114 | }
1115 |
1116 | /**
1117 | * @description: 获取积分
1118 | * @param: null
1119 | * @return: null
1120 | */
1121 | function getScores(i) {
1122 | while (!id("home_bottom_tab_button_work").exists()) ;//等待加载出主页
1123 | logDefault("正在获取积分...");
1124 | while (!id("comm_head_xuexi_score").exists());
1125 | try {
1126 | // id("comm_head_xuexi_score").findOnce().click();
1127 | // 为了获取用户名称及段位改为下面的点击方式
1128 | if (user) {
1129 | id("comm_head_xuexi_score").findOnce().click();
1130 | }else{
1131 | id("comm_head_xuexi_mine").findOnce().click();
1132 | while (!id("user_item_avatar").exists());
1133 | var name = className("android.widget.TextView").depth(16).findOnce(0).text();
1134 | var duanwei = className("android.widget.TextView").depth(16).findOnce(2).text();
1135 | user = name + duanwei;
1136 | delay(1);
1137 | back();
1138 | delay(1);
1139 | id("comm_head_xuexi_score").findOnce().click();
1140 | }
1141 | } catch (e) {
1142 | logDefault(e);
1143 | }
1144 | delay(2);
1145 |
1146 | let err = false;
1147 | while (!err) {
1148 | try {
1149 | className("android.widget.ListView").findOnce().children().forEach(item => {
1150 | let name = item.child(0).child(0).text();
1151 | let str = item.child(2).text().split("/");
1152 | let score = str[0].match(/[0-9][0-9]*/g);
1153 | myScores[name] = score;
1154 | let t = textStartsWith("今日已累积").findOnce().text();
1155 | xxScores = t.match(/\d+/g)[0];//累计学习积分
1156 | });
1157 | err = true;
1158 | } catch (e) {
1159 | logDefault("正在重试获取积分...");
1160 | }
1161 | delay(1.5);
1162 | }
1163 | // logDefault(myScores);
1164 |
1165 | aCount = Math.ceil((12 - myScores["我要选读文章"]) / 2); //文章个数
1166 | if (i == 1) {
1167 | aCount = 12 - myScores["我要选读文章"];
1168 | if (aCount != 0) {
1169 | logDefault("还需要阅读:" + aCount.toString() + "篇文章!");
1170 | } else {
1171 | logInfo("文章阅读已满分!");
1172 | }
1173 | delay(1);
1174 | back();
1175 | return;
1176 | }
1177 |
1178 | // if (aCount != 0) {
1179 | // aCount = aCount + randomNum(0, 1)
1180 | // }
1181 |
1182 | vCount = 6 - myScores["视听学习"];
1183 | rTime = (6 - myScores["视听学习时长"]) * 60;
1184 | asub = 2 - myScores["订阅"];
1185 | sCount = 2 - myScores["分享"] * 2
1186 | cCount = 1 - myScores["发表观点"]
1187 |
1188 | if (i == 2) {//视频是否满分
1189 | if (vCount != 0) {
1190 | logDefault('还需要观看:' + vCount.toString() + '个视频!');
1191 | } else {
1192 | logInfo("观看视频已满分!");
1193 | }
1194 | delay(1);
1195 | back();
1196 | return;
1197 | }
1198 | logDefault('今日已获得:' + xxScores + '分');
1199 | delay(1);
1200 | back();
1201 | delay(1);
1202 | }
1203 |
1204 | /**
1205 | * @description: 启动app
1206 | * @param: null
1207 | * @return: null
1208 | */
1209 | function start_app(x) {
1210 | //重写start_app函数,使其适合多个场景
1211 | //启动强国主页,回退到主页并点击正下方的"学习"按钮
1212 | let err = false;
1213 | let f = 0
1214 | while (!err) { //等待强国主页加载
1215 | try {
1216 | if (app.getAppName(currentPackage()) != "学习强国") {//如果强国未启动
1217 | if (x == undefined) {//不带参数时输出信息
1218 | logDefault("启动学习强国");
1219 | }
1220 |
1221 | if (!launchApp("学习强国")) {//启动学习强国app
1222 | logError("找不到学习强国App!");
1223 | return;
1224 | }
1225 |
1226 | } else {
1227 | if (currentActivity() != "com.alibaba.android.user.login.SignUpWithPwdActivity") {//如果强国界面不为密码登录页
1228 | if (currentActivity() == "android.widget.FrameLayout") {//强国主界面
1229 | if (id("home_bottom_tab_button_work").exists()) {//如果发现"学习"按钮
1230 | if (x == undefined) {//不带参数时
1231 | id("home_bottom_tab_button_work").findOne().click();//点击主页正下方的"学习"按钮
1232 | }
1233 | err = true;
1234 | }
1235 | } else {
1236 | if (text("退出").exists()) {//退出按钮
1237 | //logDefault('退出');
1238 | let clickExit = text("退出").findOnce().click();
1239 | //logDefault(clickExit);
1240 | if (!clickExit) {
1241 | if (className("Button").exists()) {//退出按钮
1242 | className("Button").findOnce().click();
1243 | }
1244 | }
1245 | }
1246 | back();
1247 | }
1248 | //delay(0.5);
1249 | } else {
1250 | logError("未登录学习强国账号,请登录后重试!");
1251 | return;
1252 | }
1253 | if (x == undefined) {//不带参数时输出信息
1254 | if (f % 3 == 0) {
1255 | logDefault("等待加载出主页");
1256 | }
1257 | }
1258 | }
1259 | delay(1);
1260 | f++;
1261 | } catch (e) {//如果出错?
1262 | if (x == undefined) {//不带参数时输出信息
1263 | logDefault(e);
1264 | }
1265 | logError("出现错误,请检查2!");
1266 | return;
1267 | }
1268 | }
1269 |
1270 | /*有误触发的情况
1271 | if (x ==undefined) {//不带参数时开启线程
1272 | //停止线程和脚本
1273 | //threads.shutDownAll();
1274 | //开启新线程检测学习强国是否在前台
1275 | var thread = threads.start(function(){
1276 | while(true){
1277 | if (app.getAppName(currentPackage()) != "学习强国" ){//如果强国不在前台运行
1278 | if (!className("ListView").exists() || !textContains("欢迎发表你的观点").exists()) {//好像答题界面有时会误触发,故判断非
1279 | logDefault("学习强国不在前台,准备切换到前台!");
1280 | toast("学习强国不在前台,准备切换到前台!");
1281 | launchApp("学习强国");
1282 | delay(2);
1283 | }
1284 | }
1285 | delay(10);//每10秒检测一次
1286 | }
1287 | });
1288 | }
1289 | */
1290 | }
1291 |
1292 | /**
1293 | * @description: 从数据库中搜索答案,没有答案就添加(存在即更新),或删除题库中的问题列
1294 | * @param: upOrdel,question,answer;upOrdel:'up'=1,'del'=0
1295 | * @return: null
1296 | */
1297 | function UpdateOrDeleteTK(upOrdel, question, answer) {//只针对tiku表,添加/更新或删除相应的列
1298 | if (question == undefined) {
1299 | logDefault("题目为空,返回!");
1300 | return;
1301 | }
1302 | if (upOrdel == "up" || upOrdel == 1) {//更新题库
1303 | let db = SQLiteDatabase.openOrCreateDatabase(path, null);
1304 | if (answer == undefined) {
1305 | logDefault("答案为空,返回!");
1306 | return;
1307 | }
1308 | let sql1 = "SELECT answer FROM tiku WHERE question LIKE '%" + question + "%'"// 关键词前后都加%,增加搜索准确率
1309 | let cursor = db.rawQuery(sql1, null);//查找是否存在
1310 | if (!cursor.moveToFirst()) { //不存在,添加到题库
1311 | sql1 = "INSERT INTO tiku VALUES ('" + question + "','" + answer + "','')";
1312 | logDefault("更新答案到本地题库...");
1313 | updateToServer(question,answer);
1314 | db.execSQL(sql1);
1315 | } else { //修正题库答案
1316 | if (cursor.getString(0) != answer) { //题库答案和目的答案不一致
1317 | //logDefault('题库答案:'+cursor.getString(0)); //调试用
1318 | sql1 = "UPDATE tiku SET answer='" + answer + "' WHERE question LIKE '" + question + "'";
1319 | logDefault("修正本地题库答案...");
1320 | updateToServer(question,answer);
1321 | db.execSQL(sql1);
1322 | }
1323 | }
1324 | cursor.close();
1325 | db.close(); //关闭数据库
1326 | delay(1);
1327 | } else if (upOrdel == "del" || upOrdel == 0) {
1328 | let db = SQLiteDatabase.openOrCreateDatabase(path, null);
1329 | let sql2 = "SELECT answer FROM tiku WHERE question LIKE '%" + question + "%'"// 关键词前后都加%,增加搜索准确率
1330 | let cursor = db.rawQuery(sql2, null);//查找是否存在
1331 | if (cursor.moveToFirst()) { //题库存在,删除该列
1332 | sql2 = "DELETE FROM tiku WHERE question LIKE '" + question + "'";//删库语句
1333 | logDefault("删除本地题库的相关题目列...");
1334 | db.execSQL(sql2);
1335 | } else {
1336 | logDefault("本地题库找不到对应的题目,删除失败。");
1337 | }
1338 | cursor.close();
1339 | db.close(); //关闭数据库
1340 | delay(1);
1341 | }
1342 | }
1343 |
1344 | function getAnswer(question) {
1345 | let db = SQLiteDatabase.openOrCreateDatabase(path, null);
1346 | let sql1 = "SELECT answer FROM tiku WHERE question LIKE '%" + question + "%'";// 关键词前后都加%,增加搜索准确率
1347 | let sql2 = "SELECT answer FROM tikuNet WHERE question LIKE '%" + question + "%'";
1348 | let answer = "";
1349 | let cursor = db.rawQuery(sql1, null);
1350 | if (cursor.moveToFirst()) {
1351 | answer = cursor.getString(0);
1352 | cursor.close();
1353 | logDefault("tiku答案:" + answer);
1354 | return answer;
1355 | } else {
1356 | cursor = db.rawQuery(sql2, null);
1357 | if (cursor.moveToFirst()) {
1358 | answer = cursor.getString(0);
1359 | cursor.close();
1360 | db.close();
1361 | logDefault("tikuNet答案:" + answer);
1362 | return answer.replace(/(^\s*)|(\s*$)/g, "");
1363 | ;
1364 | } else {
1365 | let netTiku = "http://sg89.cn/api/tk1.php"; //在线题库
1366 | let netziXingTi = "选择词语的正确词形%。"; //字形题网络原题,含空格+第一选项,改为通配%
1367 | let netquestion = question.replace(ziXingTi, netziXingTi);//还原字形题的原题目(含空格)+第一个选项
1368 | try {
1369 | let zxda = http.post(netTiku, {//在线答案
1370 | "t": "da",
1371 | "q": netquestion
1372 | });
1373 | //判断发送是否成功
1374 | // (zxda.statusCode = 200) {//post成功info
1375 | let zxanswer = zxda.body.json();
1376 | if (zxanswer.code == -1) { //未找到答案
1377 | logError("网络请求未找到答案...");
1378 | return '';
1379 | } else {//找到答案 (0||1)
1380 | let answer = zxanswer.as;//在线答案
1381 | //添加或更新本地题库答案
1382 | logDefault("网络答案:" + answer);
1383 | UpdateOrDeleteTK('up', question, answer);//添加或更新到本地题库
1384 | return answer;//返回答案
1385 | }
1386 | } catch (e) {
1387 | logError("网络请求出错,请检查!");
1388 | return '';
1389 | }
1390 | }
1391 | }
1392 | }
1393 |
1394 |
1395 | function indexFromChar(str) {
1396 | return str.charCodeAt(0) - "A".charCodeAt(0);
1397 | }
1398 |
1399 | /**
1400 | @description: 停止广播
1401 | @param: null
1402 | @return: null
1403 | */
1404 | function stopRadio() {
1405 | while (!id("home_bottom_tab_button_work").exists()) ;//等待加载出主页
1406 | id("home_bottom_tab_button_work").findOne().click();//点击主页正下方的"学习"按钮
1407 | delay(2);
1408 | logDefault("停止收听广播!");
1409 | click("电台");
1410 | delay(1);
1411 | click("听新闻广播");
1412 | delay(2);
1413 | while (!(textContains("正在收听").exists() || textContains("最近收听").exists() || textContains("推荐收听").exists())) {
1414 | log("等待加载");
1415 | delay(2);
1416 | }
1417 | if (textContains("正在收听").exists()) {
1418 | click("正在收听");
1419 | logDefault("正在停止广播...");
1420 | delay(2);
1421 | id("v_play").findOnce(0).click();//点击暂停播放按钮
1422 | delay(2);
1423 | if (id("btn_back").findOne().click() == 0) {//后退
1424 | delay(2);
1425 | back();
1426 | }
1427 | }
1428 | logDefault("广播已停止播放...");
1429 | delay(1);
1430 | if (!id("home_bottom_tab_button_work").exists()) {
1431 | start_app(1);
1432 | }
1433 | delay(1);
1434 | }
1435 |
1436 | /**
1437 | @description: 学习平台订阅
1438 | @param: null
1439 | @return: null
1440 | */
1441 | function sub1() {
1442 | id("home_bottom_tab_button_work").findOne().click();
1443 | logDefault("点击 订阅");
1444 | delay(2);
1445 | click("订阅");
1446 | logDefault("点击 添加");
1447 | delay(2);
1448 | click("添加");
1449 | // logDefault("点击 学习平台");
1450 | // delay(2);
1451 | // click("学习平台", 0); // text("学习平台").findOne().click() == click("学习平台", 0) 解决订阅问题
1452 | delay(2)
1453 | // logDefault("点击 强国号");
1454 | // a=click("强国号", 0)
1455 | // logError("a"+a);
1456 | let sublist = className("ListView").findOnce(0);
1457 | logDefault("sublist"+sublist);
1458 | var i = 0;
1459 | while (i < asub) {
1460 | let object = desc("订阅").find();
1461 | if (!object.empty()) {
1462 | object.forEach(function (currentValue) {
1463 | if (currentValue && i < asub) {
1464 | let like = currentValue.parent()
1465 | //logDefault("currentValue",currentValue,"like",like)
1466 | if (like.click()) {
1467 | logDefault("订阅成功");
1468 | i++;
1469 | delay(2);
1470 | } else {
1471 | logError("订阅失败");
1472 | }
1473 | }
1474 | })
1475 | } else if (text("你已经看到我的底线了").exists()) {
1476 | logDefault("尝试订阅学习平台")
1477 | back();
1478 | delay(1);
1479 | click("添加");
1480 | delay(1);
1481 | click("学习平台", 0);
1482 | delay(2);
1483 | let sublist = className("ListView").findOnce(1);
1484 | while (i < asub) {
1485 | let object = desc("订阅").find();
1486 | if (!object.empty()) {
1487 | object.forEach(function (currentValue) {
1488 | if (currentValue && i < asub) {
1489 | let like = currentValue.parent()
1490 | if (like.click()) {
1491 | logDefault("订阅成功");
1492 | i++;
1493 | delay(2);
1494 | } else {
1495 | logError("订阅失败");
1496 | }
1497 | }
1498 | })
1499 | } else if (text("你已经看到我的底线了").exists()) {
1500 | logDefault("没有可订阅的强国号了,退出!!!")
1501 | back();
1502 | delay(2);
1503 | return;
1504 | } else {
1505 | delay(1);
1506 | sublist.scrollForward();
1507 | }
1508 | }
1509 | } else {
1510 | delay(1);
1511 | sublist.scrollForward();
1512 | }
1513 | }
1514 | back();
1515 | delay(2);
1516 | }
1517 |
1518 | function sub() {
1519 | requestScreenCapture();
1520 | id("home_bottom_tab_button_work").findOne().click();
1521 | logDefault("点击 订阅");
1522 | delay(2);
1523 | click("订阅");
1524 | logDefault("点击 添加");
1525 | delay(2);
1526 | click("添加");
1527 | while(!textContains("推荐").exists());
1528 | var leftList=text("推荐").findOne().parent();
1529 | for(var i=0;i
1803 |
1804 |
1805 | );
1806 | window.setPosition(x, y - 45);
1807 | return window;
1808 | }
1809 |
1810 | /***************************争上游、双人对战答题部分 开始***************************/
1811 | /**
1812 | * @description: 争上游答题 20200928增加
1813 | * @param: null
1814 | * @return: null
1815 | */
1816 | function zsyQuestion() {
1817 | while (!id("home_bottom_tab_button_work").exists()) ;//等待加载出主页
1818 | id("home_bottom_tab_button_work").findOne().click();//点击主页正下方的"学习"按钮
1819 | delay(2);
1820 | text("我的").click();
1821 | if (!textContains("我要答题").exists()) {
1822 | delay(1);
1823 | click("我要答题");
1824 | } else {
1825 | (!text("我要答题").exists());
1826 | delay(1);
1827 | text("我要答题").click();
1828 | }
1829 | while (!text("答题练习").exists()) ;//可用词:排行榜 答题竞赛
1830 | delay(1);
1831 | className("android.view.View").text("答题练习").findOne().parent().child(8).click();
1832 | logDefault("开始争上游答题")
1833 | delay(2);
1834 |
1835 | if (className("android.view.View").text("开始比赛").exists()) {
1836 | className("android.view.View").text("开始比赛").findOne().click();
1837 | }
1838 | delay(5);
1839 | let zNum = 1;//轮数
1840 | logInfo("第" + zNum.toString() + "轮争上游答题开始...")
1841 | while (true) {
1842 | if (className("android.view.View").text("继续挑战").exists() || textContains("继续挑战").exists())//遇到继续挑战,则本局结束
1843 | {
1844 | logInfo("争上游答题本局结束!");
1845 | zNum++;
1846 | //当天上限两次
1847 | if (className("android.view.View").text("非积分奖励局").exists()) {
1848 | logInfo("今天已完成争上游答题!");
1849 | zNum++;
1850 | }//
1851 | if (zNum > zCount) {
1852 | logDefault("争上游答题结束");
1853 | //回退返回主页
1854 | back();
1855 | delay(1);
1856 | back();
1857 | delay(1);
1858 | back();
1859 | delay(1);
1860 | back();
1861 | delay(1);
1862 | break;
1863 | } else {
1864 | logDefault("即将开始下一轮...")
1865 | delay(2);//等待2秒开始下一轮
1866 | back();
1867 | delay(1);
1868 | back();
1869 | while (!text("答题练习").exists()) ;//排行榜 答题竞赛
1870 | delay(1);
1871 | className("android.view.View").text("答题练习").findOne().parent().child(8).click();
1872 | logDefault("开始争上游答题")
1873 | delay(2);
1874 | if (className("android.view.View").text("开始比赛").exists()) {
1875 | className("android.view.View").text("开始比赛").findOne().click();
1876 | }
1877 | delay(6);
1878 | }
1879 | logInfo("第" + zNum.toString() + "轮开始...")
1880 | } else if (!text("继续挑战").exists()) {
1881 | zsyQuestionLoop();
1882 | }
1883 | }
1884 | }
1885 |
1886 | /**
1887 | * @description: 双人对战答题 20200928增加
1888 | * @param: null
1889 | * @return: null
1890 | */
1891 | function SRQuestion() {
1892 | while (!id("home_bottom_tab_button_work").exists()) ;//等待加载出主页
1893 | id("home_bottom_tab_button_work").findOne().click();//点击主页正下方的"学习"按钮
1894 | delay(2);
1895 | text("我的").click();
1896 | if (!textContains("我要答题").exists()) {
1897 | delay(1);
1898 | click("我要答题");
1899 | } else {
1900 | (!text("我要答题").exists());
1901 | delay(1);
1902 | text("我要答题").click();
1903 | }
1904 | while (!text("答题练习").exists()) ;//可用词:排行榜 答题竞赛
1905 | delay(1);
1906 | className("android.view.View").text("答题练习").findOne().parent().child(9).click();
1907 | logDefault("开始双人对战")
1908 | delay(2);
1909 |
1910 | if (className("android.view.View").text("邀请对手").exists()) {
1911 | className("android.view.View").text("邀请对手").findOne().parent().child(0).click();
1912 | }
1913 | delay(1);
1914 | if (className("android.view.View").text("开始对战").exists()) {
1915 | className("android.view.View").text("开始对战").findOne().click();
1916 | }
1917 | delay(5);
1918 | let zNum = 1;//轮数
1919 | //logInfo("第" + zNum.toString() + "轮开始...") //双人对战只一局得分
1920 | while (true) {
1921 | if (className("android.view.View").text("继续挑战").exists() || textContains("继续挑战").exists() || textContains("请明日再来").exists() || className("android.view.View").text("非积分奖励局").exists()) {//遇到继续挑战,则本局结束
1922 | logInfo("双人对战本局结束!");
1923 | zNum++;
1924 | if (zNum >= zCount) {
1925 | logDefault("双人对战结束!返回主页!");
1926 | if (textContains("知道了").exists()) {//今日次数已超过
1927 | className("android.widget.Button").text("知道了").findOne().click();
1928 | delay(1);
1929 | //back(); delay(1);
1930 | //back(); delay(1);
1931 | break;
1932 | }
1933 | //回退返回主页
1934 | back();
1935 | delay(1);
1936 | back();
1937 | delay(1);
1938 | if (text("退出").exists()) {
1939 | className("android.widget.Button").text("退出").findOne().click();
1940 | delay(1);
1941 | }
1942 | back();
1943 | delay(1);
1944 | back();
1945 | delay(1);
1946 | break;
1947 | } else {
1948 | logDefault("即将开始下一轮...")
1949 | back();
1950 | delay(1);
1951 | back();
1952 | delay(1);
1953 | if (textContains("退出").exists()) {
1954 | className("android.widget.Button").text("退出").findOne().click();
1955 | delay(1);
1956 | }
1957 | while (!text("答题练习").exists()) ;//排行榜 答题竞赛
1958 | delay(1);
1959 | logDefault("开始双人对战")
1960 | delay(2);
1961 | if (className("android.view.View").text("邀请对手").exists()) {
1962 | className("android.view.View").text("邀请对手").findOne().parent().child(0).click();
1963 | }
1964 | delay(1);
1965 | if (className("android.view.View").text("开始对战").exists()) {
1966 | className("android.view.View").text("开始对战").findOne().click();
1967 | }
1968 | delay(5);
1969 | }
1970 | //logInfo("第" + zNum.toString() + "轮开始...")
1971 | } else if (!text("继续挑战").exists()) {
1972 | zsyQuestionLoop();
1973 | }
1974 | }
1975 | }
1976 |
1977 | /**
1978 | * @description: 争上游答题 双人对战答题循环
1979 | * @param: null
1980 | * @return: null
1981 | */
1982 | function zsyQuestionLoop() {
1983 | let ClickAnswer;
1984 | while (className("ListView").exists() && !text("继续挑战").exists()) {
1985 | try {
1986 | if (className("ListView").exists() && !text("继续挑战").exists()) {
1987 | var aquestion = className("ListView").findOnce().parent().child(0).text();
1988 | var question = aquestion.substring(3); //争上游和对战题目前带1.2.3.需去除
1989 | }
1990 | if (aquestion != oldaquestion && question != "") {
1991 | logDefault("题目:" + question);
1992 | logDefault("------------------------");
1993 | var chutiIndex = question.lastIndexOf("出题单位");
1994 | if (chutiIndex != -1) {
1995 | question = question.substring(0, chutiIndex - 2);
1996 | }
1997 |
1998 | var options = [];//选项列表
1999 | if (className("ListView").exists()) {
2000 | className("ListView").findOne().children().forEach(child => {
2001 | var answer_q = child.child(0).child(1).text();
2002 | options.push(answer_q);
2003 | });
2004 | } else {
2005 | logError("答案获取失败!");
2006 | return;
2007 | }
2008 |
2009 | // 判断是否为字形题,网络搜题和本地搜题
2010 | question = question.replace(/\s/g, "");
2011 |
2012 | if (question == ziXingTi.replace(/\s/g, "")) {
2013 | question = question + options[0].substring(3); //字形题在题目后面添加第一选项
2014 | }
2015 |
2016 | var answer = getAnswer(question);
2017 | if (/^[a-zA-Z]{1}$/.test(answer)) {//如果为ABCD形式
2018 | var indexAnsTiku = indexFromChar(answer.toUpperCase());
2019 | answer = options[indexAnsTiku];
2020 | //toastLog("answer from char=" + answer);
2021 | }
2022 |
2023 | let hasClicked = false;
2024 | let listArray = className("ListView").findOnce().children();//题目选项列表
2025 |
2026 | logInfo("答案:" + answer);
2027 | logDefault("------------------------");
2028 | //如果找到答案
2029 | if (answer.length != 0) {//如果找到了答案 该部分问题: 选项带A.B.C.D.,题库返回答案不带,char返回答案带
2030 | var answer_a = answer.substring(0, 2);//定义answer_a,获取答案前两个字符对比A.B.C.D.应该不会出现E选项
2031 | if (answer_a == "A." || answer_a == "B." || answer_a == "C." || answer_a == "D.") {
2032 | listArray.forEach(item => {
2033 | var listDescStrb = item.child(0).child(1).text();
2034 | if (listDescStrb == answer) {
2035 | //显示 对号
2036 | //var b = item.child(0).bounds();
2037 | //var tipsWindow = drawfloaty(b.left, b.top);
2038 | item.child(0).click();//点击答案
2039 | //sleep(randomNum(0, zsyDelay)/2);
2040 | hasClicked = true;
2041 | //消失 对号
2042 | //sleep(randomNum(0, zsyDelay)/2);
2043 | //tipsWindow.close();
2044 | }
2045 | });
2046 | } else {
2047 | listArray.forEach(item => {
2048 | var listDescStra = item.child(0).child(1).text();
2049 | var listDescStrb = listDescStra.substring(3);//选项去除A.B.C.D.再与answer对比
2050 | var listDescStrc = listDescStrb.replace(/\s/g, "");
2051 | if (listDescStrb == answer || listDescStrc == answer) {
2052 | //显示 对号
2053 | //var b = item.child(0).bounds();
2054 | //var tipsWindow = drawfloaty(b.left, b.top);
2055 | item.child(0).click();//点击答案
2056 | //sleep(randomNum(0, zsyDelay)/2);
2057 | hasClicked = true;
2058 | //消失 对号
2059 | //sleep(randomNum(0, zsyDelay)/2);
2060 | //tipsWindow.close();
2061 | }
2062 | });
2063 | }
2064 | }
2065 | if (!hasClicked || answer.length == 0) {//如果没有点击成功,或找不到题目
2066 | if (!hasClicked) {
2067 | logError("未能成功点击,随机点击");
2068 | }
2069 | if (answer.length == 0) {
2070 | logError("未找到答案,随机点击");
2071 | }
2072 | let i = random(0, listArray.length - 1);
2073 | listArray[i].child(0).click();//随意点击一个答案
2074 | hasClicked = true;
2075 | ClickAnswer = listArray[i].child(0).child(1).text();
2076 | ;//记录已点击答案
2077 | logDefault("随机点击:" + ClickAnswer);
2078 | logDefault("------------------------");
2079 | }
2080 |
2081 | var oldaquestion = aquestion; //对比新旧题目
2082 | sleep(randomNum(0, zsyDelay));
2083 | //完成一道题目作答
2084 | }
2085 | } catch (e) {
2086 | logDefault(e); //输出错误信息,调试用
2087 | logError("出现错误,请检查3!");
2088 | return;
2089 | }
2090 | }
2091 | }
2092 |
2093 | /***************************争上游、双人对战答题部分 结束***************************/
2094 |
2095 | /***************************每日、每周、专项答题部分 开始***************************/
2096 | /**
2097 | * @description: 获取填空题题目数组
2098 | * @param: null
2099 | * @return: questionArray
2100 | */
2101 | function getFitbQuestion() {
2102 |
2103 | var questionCollections = className("EditText").findOnce().parent().parent();
2104 | var questionArray = [];
2105 | var findBlank = false;
2106 | var blankCount = 0;
2107 | var blankNumStr = "";
2108 | var i = 0;
2109 | questionCollections.children().forEach(item => {
2110 | if (item.className() != "android.widget.EditText") {
2111 | if (item.text() != "") {//题目段
2112 | if (findBlank) {
2113 | blankNumStr = "|" + blankCount.toString();
2114 | questionArray.push(blankNumStr);
2115 | findBlank = false;
2116 | }
2117 | questionArray.push(item.text());
2118 | } else {
2119 | findBlank = true;
2120 | blankCount = (className("EditText").findOnce(i).parent().childCount() - 1);
2121 | i++;
2122 | }
2123 | }
2124 | });
2125 | return questionArray;
2126 |
2127 | /*
2128 | var questionArray = [];
2129 | let questionCollections = className("EditText").findOnce().parent().parent();
2130 | if (questionCollections.childCount() == 1) {//法1
2131 | questionCollections = className("EditText").findOnce().parent();
2132 | let findBlank = false;
2133 | let blankCount = 0;
2134 | let blankNumStr = "";
2135 | questionCollections.children().forEach(item => {
2136 | if (item.className() != "android.widget.EditText") {
2137 | if (item.text() != "") { //题目段
2138 | if (findBlank) {
2139 | blankNumStr = "|" + blankCount.toString();
2140 | //log(blankNumStr);
2141 | questionArray.push(blankNumStr);
2142 | findBlank = false;
2143 | blankCount=0;
2144 | }
2145 | //log(item.desc());
2146 | questionArray.push(item.text());
2147 | } else {
2148 | findBlank = true;
2149 | blankCount += 1;
2150 | }
2151 | }
2152 | });
2153 | logDefault("法1" + questionArray);
2154 | } else {//法2
2155 | questionCollections.children().forEach(item => {
2156 | if (item.childCount() == 0) { //题目段
2157 | questionArray.push(item.text());
2158 | } else {
2159 | let blankNumStr = "|" + (item.childCount() - 1).toString();
2160 | questionArray.push(blankNumStr);
2161 | }
2162 | });
2163 | logDefault("法2" + questionArray);
2164 | }
2165 | return questionArray;
2166 | */
2167 | }
2168 |
2169 | /**
2170 | * @description: 获取选择题题目数组
2171 | * @param: null
2172 | * @return: questionArray
2173 | */
2174 | function getChoiceQuestion() {
2175 | var questionCollections = className("ListView").findOnce().parent().child(1);
2176 | var questionArray = [];
2177 | questionArray.push(questionCollections.text());
2178 | return questionArray;
2179 | }
2180 |
2181 |
2182 | /**
2183 | * @description: 获取提示字符串
2184 | * @param: null
2185 | * @return: tipsStr
2186 | */
2187 | function getTipsStr() {
2188 | var tipsStr = "";
2189 | while (tipsStr == "") {
2190 | if (text("查看提示").exists()) {
2191 | var seeTips = text("查看提示").findOnce();
2192 | seeTips.click();
2193 | delay(1);
2194 | click(device.width * 0.5, device.height * 0.41);
2195 | delay(1);
2196 | click(device.width * 0.5, device.height * 0.35);
2197 | } else {
2198 | logError("未找到查看提示");
2199 | }
2200 | if (text("提示").exists()) {
2201 | var tipsLine = text("提示").findOnce().parent();
2202 | //获取提示内容
2203 | var tipsView = tipsLine.parent().child(1).child(0);
2204 | tipsStr = tipsView.text();
2205 | //关闭提示
2206 | tipsLine.child(1).click();
2207 | break;
2208 | }
2209 | delay(1);
2210 | }
2211 | return tipsStr;
2212 | }
2213 |
2214 |
2215 | /**
2216 | * @description: 从提示中获取填空题答案
2217 | * @param: timu, tipsStr
2218 | * @return: ansTips
2219 | */
2220 | function getAnswerFromTips(timu, tipsStr) {
2221 | var ansTips = "";
2222 | for (var i = 1; i < timu.length - 1; i++) {
2223 | if (timu[i].charAt(0) == "|") {
2224 | var blankLen = timu[i].substring(1);
2225 | var indexKey = tipsStr.indexOf(timu[i + 1]);
2226 | var ansFind = tipsStr.substr(indexKey - blankLen, blankLen);
2227 | ansTips += ansFind;
2228 | }
2229 | }
2230 | return ansTips;
2231 | }
2232 |
2233 | /**
2234 | * @description: 根据提示点击选择题选项
2235 | * @param: tipsStr
2236 | * @return: clickStr
2237 | */
2238 | function clickByTips(tipsStr) {
2239 | var clickStr = "";
2240 | var isFind = false;
2241 | if (className("ListView").exists()) {
2242 | var listArray = className("ListView").findOne().children();
2243 | listArray.forEach(item => {
2244 | var ansStr = item.child(0).child(2).text();
2245 | if (tipsStr.indexOf(ansStr) >= 0) {
2246 | //显示 对号
2247 | var b = item.child(0).bounds();
2248 | var tipsWindow = drawfloaty(b.left, b.top);
2249 | //时长点击
2250 | sleep(300);
2251 | //点击
2252 | item.child(0).click();
2253 | sleep(300);
2254 | //消失 对号
2255 | tipsWindow.close();
2256 | clickStr += item.child(0).child(1).text().charAt(0);
2257 | isFind = true;
2258 | }
2259 | });
2260 | if (!isFind) { //没有找到 点击第一个
2261 | listArray[0].child(0).click();
2262 | clickStr += listArray[0].child(0).child(1).text().charAt(0);
2263 | }
2264 | }
2265 | return clickStr;
2266 | }
2267 |
2268 |
2269 | /**
2270 | * @description: 根据答案点击选择题选项,10.29修改返回点击成功与否
2271 | * @param: answer
2272 | * @return: null
2273 | */
2274 | function clickByAnswer(answer) {
2275 | let hasClicked = false;
2276 | if (className("ListView").exists()) {
2277 | var listArray = className("ListView").findOnce().children();
2278 | listArray.forEach(item => {
2279 | var listIndexStr = item.child(0).child(1).text().charAt(0);
2280 | //单选答案为非ABCD
2281 | var listDescStr = item.child(0).child(2).text();
2282 | var listDescStrc = listDescStr.replace(/\s/g, "");
2283 | if (answer.indexOf(listIndexStr) >= 0 || answer == listDescStr || listDescStrc == answer) {
2284 | //显示 对号
2285 | var b = item.child(0).bounds();
2286 | var tipsWindow = drawfloaty(b.left, b.top);
2287 | //随机时长点击
2288 | sleep(300);
2289 | //点击
2290 | item.child(0).click();
2291 | sleep(300);
2292 | //消失 对号
2293 | tipsWindow.close();
2294 | hasClicked = true;
2295 |
2296 | }
2297 | });
2298 | return hasClicked;
2299 | }
2300 | }
2301 |
2302 | /**
2303 | * @description: 检查答案是否正确,并更新数据库
2304 | * @param: question, ansTiku, answer
2305 | * @return: null
2306 | */
2307 | function checkAndUpdate(question, ansTiku, answer) {
2308 | if (text("答案解析").exists()) {//答错了
2309 | swipe(100, device.height - 100, 100, 100, 500);
2310 | var nCout = 0
2311 | while (nCout < 5) {
2312 | if (textStartsWith("正确答案").exists()) {
2313 | var correctAns = textStartsWith("正确答案").findOnce().text().substr(6);
2314 | logInfo("正确答案是:" + correctAns);
2315 | UpdateOrDeleteTK('up', question, correctAns);//添加或更新到本地题库
2316 | updateToServer(question,correctAns);
2317 | break;
2318 |
2319 | } else {
2320 | var clickPos = className("android.webkit.WebView").findOnce().child(2).child(0).child(1).bounds();
2321 | click(clickPos.left + device.width * 0.13, clickPos.top + device.height * 0.1);
2322 | logError("未捕获正确答案,尝试修正");
2323 | }
2324 | nCout++;
2325 | }
2326 | //按钮点击
2327 | var clickNextOk = false;
2328 | if (text("下一题").exists()) {
2329 | //logDefault('点击下一题');
2330 | clickNextOk = text("下一题").findOnce().click();
2331 | //logDefault(clickNextOk);
2332 | delay(1);
2333 | } else if (text("确定").exists()) {
2334 | //logDefault('点击确定');
2335 | clickNextOk = text("确定").findOnce().click();
2336 | //logDefault(clickNextOk);
2337 | delay(1);
2338 | } else if (text("完成").exists()) {
2339 | //logDefault('点击完成');
2340 | clickNextOk = text("完成").findOnce().click();
2341 | //logDefault(clickNextOk);
2342 | delay(1);
2343 | }
2344 |
2345 | if (!clickNextOk) { //按钮点击不成功,坐标点击
2346 | logInfo("未找到右上角确定按钮控件,根据坐标点击");
2347 | click(device.width * 0.85, device.height * 0.06);//右上角确定按钮,根据自己手机实际修改
2348 | delay(1);
2349 | }
2350 |
2351 | } else { //正确后进入下一题,或者进入再来一局界面
2352 | if (ansTiku == "" && answer != "") {
2353 | UpdateOrDeleteTK('up', question, answer);//添加或更新到本地题库
2354 | updateToServer(question,answer);
2355 | /*
2356 | if (ansTiku == "" && answer != "") { //正确进入下一题,且题库答案为空
2357 | var sql = "INSERT INTO tiku VALUES ('" + question + "','" + answer + "','')";
2358 | insertOrUpdate(sql);
2359 | logDefault("更新题库答案...");
2360 | }
2361 | */
2362 | }
2363 | }
2364 | }
2365 |
2366 |
2367 | /**
2368 | * @description: 每日答题循环
2369 | * @param: null
2370 | * @return: null
2371 | */
2372 | function dailyQuestionLoop() {
2373 | if (textStartsWith("填空题").exists()) {
2374 | var questionArray = getFitbQuestion();
2375 | } else if (textStartsWith("多选题").exists() || textStartsWith("单选题").exists()) {
2376 | var questionArray = getChoiceQuestion();
2377 | }
2378 |
2379 | var blankArray = [];
2380 | var question = "";
2381 | questionArray.forEach(item => {
2382 | if (item != null && item.charAt(0) == "|") { //是空格数
2383 | blankArray.push(item.substring(1));
2384 | } else { //是题目段
2385 | question += item;
2386 | }
2387 | });
2388 | logDefault("题目:" + question);
2389 | logDefault("------------------------");
2390 |
2391 | var chutiIndex = question.lastIndexOf("出题单位");
2392 | if (chutiIndex != -1) {
2393 | question = question.substring(0, chutiIndex - 2);
2394 | }
2395 |
2396 | var options = [];//选项列表
2397 | if (!textStartsWith("填空题").exists()) {//选择题提取答案,为字形题准备
2398 | if (className("ListView").exists()) {
2399 | className("ListView").findOne().children().forEach(child => {
2400 | var answer_q = child.child(0).child(2).text();
2401 | options.push(answer_q);
2402 | });
2403 | } else {
2404 | logError("答案获取失败!");
2405 | return;
2406 | }
2407 | }
2408 |
2409 | // 判断是否为字形题,网络搜题和本地搜题
2410 | question = question.replace(/\s/g, "");
2411 |
2412 | if (question == ziXingTi.replace(/\s/g, "")) {
2413 | question = question + options[0]; //字形题在题目后面添加第一选项
2414 | }
2415 |
2416 | var answer = getAnswer(question);
2417 | if (textStartsWith("填空题").exists()) {
2418 | if (answer == "") { //答案空,前面题库未找到答案,找提示
2419 | var tipsStr = getTipsStr();
2420 | answer = getAnswerFromTips(questionArray, tipsStr);
2421 | logInfo("提示答案:" + answer);
2422 | //updateToServer(question,answer);
2423 | var answerinput = className("EditText").findOnce().parent().child(0);//10.28修改填空题的输入方法
2424 | answerinput.setText(answer);//10.28修改填空题的输入方法
2425 | delay(0.1);
2426 | /*
2427 | setText(0, answer.substr(0, blankArray[0]));
2428 | if (blankArray.length > 1) {
2429 | for (var i = 1; i < blankArray.length; i++) {
2430 | setText(i, answer.substr(blankArray[i - 1], blankArray[i]));
2431 | }
2432 | }
2433 | */
2434 | } else { //答案非空,题库中已找到答案
2435 | logInfo("填空题答案:" + answer);
2436 | //updateToServer(question,answer);
2437 | var answerinput = className("EditText").findOnce().parent().child(0);//10.28修改填空题的输入方法
2438 | answerinput.setText(answer);//10.28修改填空题的输入方法
2439 | delay(0.1);
2440 | /*
2441 | setText(0, answer.substr(0, blankArray[0]));
2442 | if (blankArray.length > 1) {
2443 | for (var i = 1; i < blankArray.length; i++) {
2444 | setText(i, answer.substr(blankArray[i - 1], blankArray[i]));
2445 | }
2446 | }
2447 | */
2448 | }
2449 | } else if (textStartsWith("多选题").exists() || textStartsWith("单选题").exists()) {
2450 | if (answer == "") {
2451 | var tipsStr = getTipsStr();
2452 | answer = clickByTips(tipsStr);
2453 | logInfo("提示答案:" + answer);
2454 | } else {
2455 | //logInfo("答案1:" + ansTiku);
2456 | logInfo("选择题答案:" + answer);
2457 | var clickAnswerOK = clickByAnswer(answer);
2458 | if (!clickAnswerOK) {//题库答案有误,选项无法点击,进行提示作答
2459 | //ansTiku = '';//为checkAndUpdate准备,更新本地题库答案
2460 | var tipsStr = getTipsStr(); //根据提示找答案
2461 | answer = clickByTips(tipsStr);
2462 | logInfo("重新选择提示的答案:" + answer);
2463 | delay(1);
2464 | }
2465 | }
2466 | }
2467 |
2468 | //按钮点击
2469 | var clickNextOk = false;
2470 | if (text("下一题").exists()) {
2471 | //logDefault('点击下一题');
2472 | clickNextOk = text("下一题").findOnce().click();
2473 | //logDefault(clickNextOk);
2474 | delay(1);
2475 | } else if (text("确定").exists()) {
2476 | //logDefault('点击确定');
2477 | clickNextOk = text("确定").findOnce().click();
2478 | //logDefault(clickNextOk);
2479 | delay(1);
2480 | } else if (text("完成").exists()) {
2481 | //logDefault('点击完成');
2482 | clickNextOk = text("完成").findOnce().click();
2483 | //logDefault(clickNextOk);
2484 | delay(1);
2485 | }
2486 |
2487 | if (!clickNextOk) { //按钮点击不成功,坐标点击
2488 | logInfo("未找到右上角确定按钮控件,根据坐标点击");
2489 | click(device.width * 0.85, device.height * 0.06);//右上角确定按钮,根据自己手机实际修改
2490 | delay(1);
2491 | }
2492 |
2493 | checkAndUpdate(question, "", answer);//检查提示答案,更新本地题库
2494 | logDefault("------------------------");
2495 | delay(2);
2496 | }
2497 |
2498 | /**
2499 | * @description: 每日答题
2500 | * @param: null
2501 | * @return: null
2502 | */
2503 | function dailyQuestion() {
2504 | while (!id("home_bottom_tab_button_work").exists()) ;//等待加载出主页
2505 | id("home_bottom_tab_button_work").findOne().click();//点击主页正下方的"学习"按钮
2506 | delay(2);
2507 | text("我的").click();
2508 | if (!textContains("我要答题").exists()) {
2509 | delay(1);
2510 | click("我要答题");
2511 | } else {
2512 | (!text("我要答题").exists());
2513 | delay(1);
2514 | text("我要答题").click();
2515 | }
2516 | while (!text("答题练习").exists()) ;//可用词:排行榜 答题竞赛
2517 | delay(1);
2518 | text("每日答题").click();
2519 | logDefault("开始每日答题")
2520 | delay(2);
2521 | let dlNum = 0;//每日答题轮数
2522 | while (true) {
2523 | delay(1)
2524 | if (!(textStartsWith("填空题").exists() || textStartsWith("多选题").exists() || textStartsWith("单选题").exists())) {
2525 | toastLog("没有找到题目!请检查是否进入答题界面!");
2526 | logError("没有找到题目!请检查是否进入答题界面!");
2527 | logDefault("停止");
2528 | break;
2529 | }
2530 | dailyQuestionLoop();
2531 | if (text("再练一次").exists()) {
2532 | logDefault("每周答题结束!")
2533 | text("返回").click();
2534 | delay(2);
2535 | back();
2536 | break;
2537 | } else if (text("查看解析").exists()) {
2538 | logDefault("专项答题结束!")
2539 | back();
2540 | delay(1);
2541 | back();
2542 | delay(1);
2543 | break;
2544 | } else if (text("再来一组").exists()) {
2545 | delay(2);
2546 | dlNum++;
2547 | if (!text("领取奖励已达今日上限").exists()) {
2548 | text("再来一组").click();
2549 | logInfo("第" + (dlNum + 1).toString() + "轮答题:");
2550 | delay(1);
2551 | } else {
2552 | logDefault("每日答题结束!")
2553 | text("返回").click();
2554 | delay(2);
2555 | back();
2556 | delay(1);
2557 | back();
2558 | delay(1);
2559 | break;
2560 | }
2561 | }
2562 | }
2563 | }
2564 |
2565 | /***************************每日、每周、专项答题部分 结束***************************/
2566 |
2567 | /***************************挑战答题部分 开始***************************/
2568 | /**
2569 | * @description: 挑战答题
2570 | * @param: null
2571 | * @return: null
2572 | */
2573 | function challengeQuestion() {
2574 | while (!id("home_bottom_tab_button_work").exists()) ;//等待加载出主页
2575 | id("home_bottom_tab_button_work").findOne().click();//点击主页正下方的"学习"按钮
2576 | delay(2);
2577 | text("我的").click();
2578 | while (!textContains("我要答题").exists()) ;
2579 | delay(1);
2580 | click("我要答题");
2581 | while (!text("每日答题").exists()) ;
2582 | delay(1);
2583 | className("android.view.View").text("每日答题").findOne().parent().parent().child(10).click();
2584 | logDefault("开始挑战答题")
2585 | delay(4);
2586 | let conNum = 0;//连续答对的次数
2587 | let lNum = 0;//轮数
2588 | while (true) {
2589 | delay(1)
2590 | while (!className("RadioButton").exists()) {
2591 | logError("没有找到题目!请检查是否进入答题界面!");
2592 | delay(2);
2593 | }
2594 | challengeQuestionLoop(conNum);
2595 | delay(2);
2596 | if (text("v5IOXn6lQWYTJeqX2eHuNcrPesmSud2JdogYyGnRNxujMT8RS7y43zxY4coWepspQkvw" +
2597 | "RDTJtCTsZ5JW+8sGvTRDzFnDeO+BcOEpP0Rte6f+HwcGxeN2dglWfgH8P0C7HkCMJOAAAAAElFTkSuQmCC").exists())//遇到❌号,则答错了,不再通过结束本局字样判断
2598 | {
2599 | if (conNum >= qCount) {
2600 | lNum++;
2601 | }
2602 | if (lNum >= lCount) {
2603 | logDefault("挑战答题结束!返回主界面!");
2604 | delay(2);
2605 | back();
2606 | delay(2);
2607 | back();
2608 | delay(2);
2609 | back();
2610 | delay(2);
2611 | back();
2612 | delay(2);
2613 | break;
2614 | } else {
2615 | logDefault("出现错误,等5秒开始下一轮...")
2616 | delay(3);//等待5秒才能开始下一轮
2617 | back();
2618 | //desc("结束本局").click();//有可能找不到结束本局字样所在页面控件,所以直接返回到上一层
2619 | delay(2);
2620 | text("再来一局").click()
2621 | delay(4);
2622 | if (conNum < 5) {
2623 | conNum = 0;
2624 | }
2625 | }
2626 | } else//答对了
2627 | {
2628 | conNum++;
2629 | }
2630 | }
2631 | conNum = 0;
2632 | }
2633 |
2634 | /**
2635 | * @description: 每次答题循环
2636 | * @param: conNum 连续答对的次数
2637 | * @return: null
2638 | */
2639 | function challengeQuestionLoop(conNum) {
2640 | let ClickAnswer;
2641 | if (className("ListView").exists()) {
2642 | var question = className("ListView").findOnce().parent().child(0).text();
2643 | logDefault((conNum + 1).toString() + ".题目:" + question);
2644 | logDefault("------------------------");
2645 | } else {
2646 | logError("提取题目失败!");
2647 | let listArray = className("ListView").findOnce().children();//题目选项列表
2648 | let i = random(0, listArray.length - 1);
2649 | listArray[i].child(0).click();//随意点击一个答案
2650 | ClickAnswer = listArray[i].child(0).child(1).text();
2651 | ;//记录已点击答案
2652 | logDefault("随机点击:" + ClickAnswer);
2653 | logDefault("------------------------");
2654 | return;
2655 | }
2656 |
2657 | var chutiIndex = question.lastIndexOf("出题单位");
2658 | if (chutiIndex != -1) {
2659 | question = question.substring(0, chutiIndex - 2);
2660 | }
2661 |
2662 | if (conNum >= qCount)//答题次数足够退出,每轮5次
2663 | {
2664 | let listArray = className("ListView").findOnce().children();//题目选项列表
2665 | let i = random(0, listArray.length - 1);
2666 | logDefault("今天答题次数已够,随机点击一个答案");
2667 | listArray[i].child(0).click();//随意点击一个答案
2668 | ClickAnswer = listArray[i].child(0).child(1).text();
2669 | //记录已点击答案
2670 | logDefault("随机点击:" + ClickAnswer);
2671 | logDefault("------------------------");
2672 | //随机点击答案正确,更新到本地题库tiku表
2673 | delay(1);//等待0.5秒,是否出现X
2674 | if (!text("v5IOXn6lQWYTJeqX2eHuNcrPesmSud2JdogYyGnRNxujMT8RS7y43zxY4coWepspQkvw" +
2675 | "RDTJtCTsZ5JW+8sGvTRDzFnDeO+BcOEpP0Rte6f+HwcGxeN2dglWfgH8P0C7HkCMJOAAAAAElFTkSuQmCC").exists()) {
2676 | logDefault("随机点击答案正确,更新至本地题库");
2677 | UpdateOrDeleteTK('up', question, ClickAnswer);//添加或更新到本地题库
2678 | updateToServer(question,ClickAnswer);
2679 | }
2680 | return;
2681 | }
2682 |
2683 | var options = [];//选项列表
2684 | if (className("ListView").exists()) {
2685 | className("ListView").findOne().children().forEach(child => {
2686 | var answer_q = child.child(0).child(1).text();
2687 | options.push(answer_q);
2688 | });
2689 | } else {
2690 | logError("答案获取失败!");
2691 | return;
2692 | }
2693 |
2694 | // 判断是否为字形题,网络搜题和本地搜题
2695 | question = question.replace(/\s/g, "");
2696 |
2697 | if (question == ziXingTi.replace(/\s/g, "")) {
2698 | question = question + options[0]; //字形题在题目后面添加第一选项
2699 | }
2700 |
2701 | var answer = getAnswer(question);
2702 | if (/^[a-zA-Z]{1}$/.test(answer)) {//如果为ABCD形式
2703 | var indexAnsTiku = indexFromChar(answer.toUpperCase());
2704 | answer = options[indexAnsTiku];
2705 | //toastLog("answer from char=" + answer);
2706 | }
2707 |
2708 | let hasClicked = false;
2709 | let listArray = className("ListView").findOnce().children();//题目选项列表
2710 |
2711 | logInfo("答案:" + answer);
2712 | updateToServer(question,answer);
2713 | //如果找到答案
2714 |
2715 | if (answer.length != 0)//如果到答案
2716 | {
2717 | var clickAns = "";
2718 | listArray.forEach(item => {
2719 | var listDescStr,listDescStrc;
2720 | try{
2721 | listDescStr = item.child(0).child(1).text();
2722 | listDescStrc = listDescStr.replace(/\s/g, "");
2723 | }catch(e){
2724 | logError(e);
2725 | logError("出现错误,请检查4");
2726 | }
2727 |
2728 | if (listDescStr == answer || listDescStrc == answer) {
2729 | clickAns = answer;
2730 | //显示 对号
2731 | var b = item.child(0).bounds();
2732 | var tipsWindow = drawfloaty(b.left, b.top);
2733 | //随机时长点击
2734 | delay(0.1);
2735 | //点击
2736 | item.child(0).click();
2737 | hasClicked = true;
2738 | delay(0.1);
2739 | //消失 对号
2740 | tipsWindow.close();
2741 | }
2742 | });
2743 | }
2744 | if (!hasClicked || answer.length == 0) {//如果没有点击成功,或找不到题目
2745 | logError("未找到答案或未能成功点击,准备随机点击");
2746 | delay(0.3);
2747 | let i = random(0, listArray.length - 1);
2748 | listArray[i].child(0).click();//随意点击一个答案
2749 | ClickAnswer = listArray[i].child(0).child(1).text();
2750 | //记录已点击答案
2751 | logDefault("随机点击:" + ClickAnswer);
2752 | //随机点击答案正确,更新到本地题库tiku表
2753 | delay(1);//等待0.5秒,是否出现X
2754 | if (!text("v5IOXn6lQWYTJeqX2eHuNcrPesmSud2JdogYyGnRNxujMT8RS7y43zxY4coWepspQkvw" +
2755 | "RDTJtCTsZ5JW+8sGvTRDzFnDeO+BcOEpP0Rte6f+HwcGxeN2dglWfgH8P0C7HkCMJOAAAAAElFTkSuQmCC").exists()) {
2756 | logDefault("随机点击答案正确,正在准备更新本地题库");
2757 | UpdateOrDeleteTK('up', question, ClickAnswer);//添加或更新到本地题库
2758 | }
2759 | } else {//从题库中找到答案,点击成功,但如果错误
2760 | //点击答案错误,从本地题库tiku表删除
2761 | //logDefault('Test')
2762 | delay(1);//等待0.5秒,是否出现X
2763 | if (text("v5IOXn6lQWYTJeqX2eHuNcrPesmSud2JdogYyGnRNxujMT8RS7y43zxY4coWepspQkvw" +
2764 | "RDTJtCTsZ5JW+8sGvTRDzFnDeO+BcOEpP0Rte6f+HwcGxeN2dglWfgH8P0C7HkCMJOAAAAAElFTkSuQmCC").exists()) {
2765 | logDefault("题库答案点击错误,删除本地题库的错误答案");
2766 | UpdateOrDeleteTK('del', question, answer);//删除本地题库的错误答案
2767 | }
2768 | }
2769 | logDefault("------------------------");
2770 | }
2771 |
2772 | /***************************挑战答题部分 结束***************************/
2773 |
2774 | //各个学习模块,除广播电台先开始听,其他各个学习模块随机顺序执行
2775 | function xx1() {
2776 | if (myScores['每日答题'] != 5) {
2777 | logDefault("正在准备每日答题");
2778 | dailyQuestion();//每日答题
2779 | }
2780 | }
2781 |
2782 | function xx2() {
2783 | if (myScores['挑战答题'] != 6) {
2784 | logDefault("正在准备挑战答题");
2785 | challengeQuestion();//挑战答题
2786 | }
2787 | }
2788 |
2789 | function xx3() {
2790 | if (myScores['订阅'] != 2) {
2791 | logDefault("正在准备进行订阅");
2792 | //sub();//订阅
2793 | logDefault("订阅暂不可用...")
2794 | }
2795 | }
2796 |
2797 | function xx4() {
2798 | if (myScores['本地频道'] != 1) {
2799 | logDefault("正在准备本地频道");
2800 | localChannel();//本地频道
2801 | }
2802 | }
2803 |
2804 | function xx5() {
2805 | if (myScores["争上游答题"] < 2) {
2806 | logDefault("正在准备争上游答题");
2807 | zsyQuestion();//争上游答题
2808 | }
2809 | }
2810 |
2811 | function xx6() {
2812 | if (myScores["双人对战"] < 1) {
2813 | logDefault("正在准备双人对战");
2814 | SRQuestion();//双人对战
2815 | }
2816 | }
2817 |
2818 | function xx7() {
2819 | if (weekdt) {
2820 | if (myScores['每周答题'] == 0) {//无分值即尝试答题
2821 | logDefault("正在准备每周答题");
2822 | weeklyQuestion();//每周答题
2823 | }
2824 | }
2825 | }
2826 |
2827 | function xx8() {
2828 | if (specialdt) {
2829 | if (myScores['专项答题'] == 0) {//无分值即尝试答题
2830 | logDefault("正在准备专项答题");
2831 | specialQuestion();//专项答题
2832 | }
2833 | }
2834 | }
2835 |
2836 | function xx9() {
2837 | if (vCount != 0) {
2838 | logDefault("正在准备视频学习");
2839 | }
2840 | let x = 0;
2841 | while (vCount != 0) {
2842 | if (customize_flag && x == 1) {//自定义学习和第二次补充看视频才看百灵
2843 | videoStudy_bailing(vCount, vTime);//百灵视频
2844 | } else {
2845 | videoStudy_news();//看视频
2846 | }
2847 | logInfo("等待5秒,然后确认视频是否已满分。");
2848 | delay(5);
2849 | getScores(2);
2850 | x++;
2851 | if (x > 3) {//尝试三次
2852 | logInfo("已尝试3次,跳过。");
2853 | break;
2854 | }
2855 | delay(1);
2856 | num = random(0, commentText.length - 1);//随机数
2857 | vCatlog = vCat[num];
2858 | }
2859 | }
2860 |
2861 | function xx10() {
2862 | if (aCount != 0) {
2863 | logDefault("正在准备文章学习" + aCount + "篇");
2864 | }
2865 | let x = 0;
2866 | while (aCount != 0) {
2867 | articleStudy(x);//学习文章,包含点赞、分享和评论
2868 | logInfo("等待5秒,然后确认文章是否已满分。");
2869 | delay(5);
2870 | getScores(1);
2871 | x++;
2872 | if (x > 2) {//尝试三次
2873 | logInfo("尝试3次未满分,暂时跳过。");
2874 | break;
2875 | }
2876 | delay(1);
2877 | num = random(0, commentText.length - 1);//随机数
2878 | aCatlog = "要闻";
2879 | }
2880 | }
2881 |
2882 | function main() {
2883 | auto.waitFor();//等待获取无障碍辅助权限
2884 |
2885 | //开启悬浮窗口
2886 | console.setPosition(0, device.height / 2);//部分华为手机console有bug请注释本行
2887 | console.show();//部分华为手机console有bug请注释本行
2888 | logDefault("执行!xxqg_v3.1.3(fixall).js");
2889 | user = "";//重置,用于多账号学习
2890 | //文件路径
2891 |
2892 |
2893 | //
2894 | //
2895 | //
2896 | /////////////////////////////////////////////////////////////////////////////////////////
2897 | ////////////////////////////////////测试区开始////////////////////////////////////////////
2898 | // logInfo("文章阅读"+aCount+",视听学习"+vCount+",视听学习时长"+rTime+",订阅"+asub);
2899 | // aCount =0 //文章阅读
2900 | // vCount =0 //视听学习
2901 | // rTime =0 //视听学习时长
2902 | // // asub =0 //订阅
2903 | // // myScores['订阅'] = 2
2904 | // sCount =0 //分享
2905 | // cCount =0 //发表观点
2906 | // console.log("准备开始测试")
2907 | // while (!id("home_bottom_tab_button_work").exists()) ;//等待加载出主页
2908 |
2909 | // console.log("开始测试")
2910 | // if(!requestScreenCapture()){
2911 | // toastLog("请先开启截图权限,以执行订阅任务!");
2912 | // }
2913 | // sleep(3000);
2914 |
2915 | // sub();
2916 | // console.log("完成了")
2917 | // exit();
2918 | //////////////////////////////////////////////////////////////////////////////////////
2919 | ///////////////////////////////////测试区结束//////////////////////////////////////////////
2920 | //
2921 | //
2922 | //
2923 | start_app();//启动强国app
2924 | var start = new Date().getTime();//程序开始时间
2925 | getScores();//获取积分
2926 |
2927 | //听电台广播
2928 | var needRadio = true;
2929 | if (myScores['视听学习时长'] != 6) {
2930 | logDefault("正在准备电台广播");
2931 | listenToRadio();//听电台广播
2932 | } else {
2933 | var needRadio = false;//如果电台广播已完成
2934 | }
2935 |
2936 | //原来学习文章,包含点赞、分享和评论改为随机顺序学习
2937 | if (customize_flag) {//自定义
2938 | var funArr = [xx1, xx2, xx3, xx4, xx5, xx6, xx7, xx8, xx9, xx10], func;//随机学习所有模块,即含每周答题和专项答题
2939 | } else {
2940 | var funArr = [xx1, xx2, xx3, xx4, xx5, xx6, xx9, xx10], func;//随机学习各模块,不含每周答题和专项答题
2941 | }
2942 |
2943 | while (funArr.length != 0) {//随机学习各模块
2944 | func = funArr.splice(random(0, funArr.length - 1), 1)[0];
2945 | if (!id("home_bottom_tab_button_work").exists()) {
2946 | start_app(1);
2947 | }
2948 | func();
2949 | }
2950 |
2951 | var end = new Date().getTime();//重新开始广播时间
2952 | if (needRadio) {
2953 | if (rTime != 0) {
2954 | logDefault("重新开始电台广播");
2955 | listenToRadio();//听电台广播
2956 | //var end = new Date().getTime();//重新开始广播时间
2957 | var radio_time = (parseInt((end) / 1000));//广播已经收听的时间
2958 | radio_timing(parseInt((end) / 1000), rTime - radio_time);//广播剩余需收听时间
2959 | if (rTime == 0) {//停止播放广播
2960 | logDefault("正在准备停止广播");
2961 | stopRadio();
2962 | }
2963 | }
2964 | }
2965 |
2966 | end = new Date().getTime();//结束时间
2967 | logInfo("您今日学习获得" + xxScores + "分");
2968 | logDefault("运行结束,共耗时" + (parseInt(end - start)) / 1000 + "秒");
2969 |
2970 | //停止线程和脚本
2971 | threads.shutDownAll();
2972 |
2973 | }
2974 |
2975 | //main();
2976 | module.exports = main;
2977 |
--------------------------------------------------------------------------------