diff --git a/UI.js b/UI.js
new file mode 100644
index 0000000..c56c73f
--- /dev/null
+++ b/UI.js
@@ -0,0 +1,333 @@
+"ui";
+//auto("fast");
+importClass(android.view.View);
+var tikuCommon = require("./tikuCommon.js");
+let deviceWidth = device.width;
+
+let margin = parseInt(deviceWidth * 0.02);
+
+//记录集数组 重要!!!
+let qaArray = [];
+
+ui.layout(
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+);
+
+
+ui.emitter.on("create_options_menu", menu => {
+ menu.add("关于");
+});
+//监听选项菜单点击
+ui.emitter.on("options_item_selected", (e, item) => {
+ switch (item.getTitle()) {
+ case "关于":
+ alert("关于", "Power By Myue");
+ break;
+ }
+ e.consumed = true;
+});
+activity.setSupportActionBar(ui.toolbar);
+
+ui.toolbar.setupWithDrawer(ui.drawer);
+
+ui.menu.setDataSource([{
+ title: "帮助",
+ icon: "@drawable/ic_chat_black_48dp"
+ },
+ {
+ title: "退出",
+ icon: "@drawable/ic_exit_to_app_black_48dp"
+ }
+]);
+
+ui.menu.on("item_click", item => {
+ switch (item.title) {
+ case "帮助":
+ app.startActivity({
+ action: "android.intent.action.VIEW",
+ data: "mqqapi://card/show_pslcard?src_type=internal&source=sharecard&version=1&uin=874745954"
+ });
+ break;
+ case "退出":
+ ui.finish();
+ break;
+ }
+});
+//标签名
+// ui.viewpager.setTitles(["功能", "题库", "帮助与更新"]);
+
+// ui.viewpager.setTitles(["功能"]);
+
+//联动
+// ui.tabs.setupWithViewPager(ui.viewpager);
+
+//帮助页加载
+// var src = "https://github.com/james-bond-007/lovexuexi/blob/master/README.md";
+// ui.webview.loadUrl(src);
+
+ui.showFloating.click(() => {
+ engines.execScriptFile("floating.js");
+});
+
+// 题库条数
+let sqlStr = util.format("SELECT * FROM tiku");
+//var dbCount = tikuCommon.countDb("", "tiku", sqlStr);
+let dbCount = tikuCommon.allCaseNum("tiku");
+// log(dbCount);
+//进度条不可见
+/*ui.run(() => {
+ //ui.pbar.setVisibility(View.INVISIBLE);
+ ui.total.setText(""+dbCount);
+}); */
+
+//阅读模式切换
+/*ui.amsw.click(() => {
+ var amode = files.read("./article.txt");
+ toastLog("当前阅读模式为“" + amode + "”")
+ dialogs.select("请选择文章阅读模式:", ["推荐", "订阅"])
+ .then(i => {
+ if (i == 0) {
+ files.write("./article.txt", "推荐")
+ toastLog("阅读模式已改为推荐!")
+ } else if (i == 1) {
+ files.write("./article.txt", "订阅")
+ toastLog("阅读模式已改为订阅!")
+ } else {
+ toastLog("你没有选择!")
+ }
+ });
+});
+
+//加载悬浮窗
+
+
+//查询
+ui.search.click(() => {
+ //预先初始化
+ qaArray = [];
+ threads.shutDownAll();
+ ui.run(() => {
+ ui.question.setText("");
+ ui.answer.setText("");
+ ui.questionIndex.setText("0");
+ ui.questionCount.setText("0");
+ });
+ //查询开始
+ threads.start(function () {
+ if (ui.keyword.getText() != "") {
+ var keyw = ui.keyword.getText();
+ if (ui.rbQuestion.checked) {//按题目搜
+ var sqlStr = util.format("SELECT question,answer FROM tiku WHERE %s LIKE '%%%s%'", "question", keyw);
+ } else {//按答案搜
+ var sqlStr = util.format("SELECT question,answer FROM tiku WHERE %s LIKE '%%%s%'", "answer", keyw);
+ }
+ qaArray = tikuCommon.searchDb(keyw, "tiku", sqlStr);
+ var qCount = qaArray.length;
+ if (qCount > 0) {
+ ui.run(() => {
+ ui.question.setText(qaArray[0].question);
+ ui.answer.setText(qaArray[0].answer);
+ ui.questionIndex.setText("1");
+ ui.questionCount.setText(String(qCount));
+ });
+ } else {
+ toastLog("未找到");
+ ui.run(() => {
+ ui.question.setText("未找到");
+ });
+ }
+ } else {
+ toastLog("请输入关键字");
+ }
+ });
+});
+
+//最近十条
+ui.lastTen.click(() => {
+ threads.start(function () {
+ var keyw = ui.keyword.getText();
+ qaArray = tikuCommon.searchDb(keyw, "", "SELECT question,answer FROM tiku ORDER BY rowid DESC limit 20");
+ var qCount = qaArray.length;
+ if (qCount > 0) {
+ //toastLog(qCount);
+ ui.run(() => {
+ ui.question.setText(qaArray[0].question);
+ ui.answer.setText(qaArray[0].answer);
+ ui.questionIndex.setText("1");
+ ui.questionCount.setText(qCount.toString());
+ });
+ } else {
+ toastLog("未找到");
+ ui.run(() => {
+ ui.question.setText("未找到");
+ });
+ }
+ });
+});
+
+//上一条
+ui.prev.click(() => {
+ threads.start(function () {
+ if (qaArray.length > 0) {
+ var qIndex = parseInt(ui.questionIndex.getText()) - 1;
+ if (qIndex > 0) {
+ ui.run(() => {
+ ui.question.setText(qaArray[qIndex - 1].question);
+ ui.answer.setText(qaArray[qIndex - 1].answer);
+ ui.questionIndex.setText(String(qIndex));
+ });
+ } else {
+ toastLog("已经是第一条了!");
+ }
+ } else {
+ toastLog("题目为空");
+ }
+ });
+});
+
+//下一条
+ui.next.click(() => {
+ threads.start(function () {
+ if (qaArray.length > 0) {
+ //toastLog(qaArray);
+ var qIndex = parseInt(ui.questionIndex.getText()) - 1;
+ if (qIndex < qaArray.length - 1) {
+ //toastLog(qIndex);
+ //toastLog(qaArray[qIndex + 1].question);
+ ui.run(() => {
+ ui.question.setText(qaArray[qIndex + 1].question);
+ ui.answer.setText(qaArray[qIndex + 1].answer);
+ ui.questionIndex.setText(String(qIndex + 2));
+ });
+ } else {
+ toastLog("已经是最后一条了!");
+ }
+ } else {
+ toastLog("题目为空");
+ }
+ });
+});
+
+//修改
+ui.update.click(() => {
+ threads.start(function () {
+ if (ui.question.getText() && qaArray.length > 0 && parseInt(ui.questionIndex.getText()) > 0) {
+ var qIndex = parseInt(ui.questionIndex.getText()) - 1;
+ var questionOld = qaArray[qIndex].question;
+ var questionStr = ui.question.getText();
+ var answerStr = ui.answer.getText();
+ var sqlstr = "UPDATE tiku SET question = '" + questionStr + "' , answer = '" + answerStr + "' WHERE question= '" + questionOld + "'";
+ tikuCommon.executeSQL(sqlstr);
+ } else {
+ toastLog("请先查询");
+ }
+ });
+});
+
+//删除
+ui.delete.click(() => {
+ threads.start(function () {
+ if (qaArray.length > 0 && parseInt(ui.questionIndex.getText()) > 0) {
+ var qIndex = parseInt(ui.questionIndex.getText()) - 1;
+ var questionOld = qaArray[qIndex].question;
+ var sqlstr = "DELETE FROM tiku WHERE question = '" + questionOld + "'";
+ tikuCommon.executeSQL(sqlstr);
+ } else {
+ toastLog("请先查询");
+ }
+ });
+});
+
+//新增
+ui.insert.click(() => {
+ threads.start(function () {
+ if (ui.question.getText() != "" && ui.answer.getText() != "") {
+ var questionStr = ui.question.getText();
+ var answerStr = ui.answer.getText();
+ var sqlstr = "INSERT INTO tiku VALUES ('" + questionStr + "','" + answerStr + "','')";
+ tikuCommon.executeSQL(sqlstr);
+ } else {
+ toastLog("请先输入 问题 答案");
+ }
+ });
+});
+
+function reset() {
+
+}
+//重置
+ui.reset.click(() => {
+ threads.shutDownAll();
+ threads.start(function () {
+ qaArray = [];
+ ui.run(() => {
+ ui.keyword.setText("");
+ ui.question.setText("");
+ ui.answer.setText("");
+ ui.questionIndex.setText("0");
+ ui.questionCount.setText("0");
+ ui.rbQuestion.setChecked(true);
+ });
+ toastLog("重置完毕!");
+ });
+});
+
+//更新网络题库
+ui.updateTikuNet.click(() => {
+ dialogs.build({
+ title: "更新网络题库",
+ content: "确定更新?",
+ positive: "确定",
+ negative: "取消",
+ })
+ .on("positive", update)
+ .show();
+
+ function update() {
+ threads.start(function () {
+ ui.run(() => {
+ ui.resultLabel.setText("正在更新网络题库...");
+ ui.pbar.setVisibility(View.VISIBLE);
+ });
+ var ss = "./updateTikuNet.js";
+ let begin = require(ss);
+ var resultNum = begin();
+ var resultStr = "更新" + resultNum + "道题!";
+ ui.run(() => {
+ ui.resultLabel.setText("");
+ ui.pbar.setVisibility(View.INVISIBLE);
+ ui.resultLabel.setVisibility(View.INVISIBLE);
+ });
+ alert(resultStr);
+ });
+ }
+});*/
\ No newline at end of file
diff --git a/challengeAnswer.js b/challengeAnswer.js
new file mode 100644
index 0000000..59a3b5b
--- /dev/null
+++ b/challengeAnswer.js
@@ -0,0 +1,79 @@
+importClass(android.database.sqlite.SQLiteDatabase);
+
+var questionCommon = require("./questionCommon.js");
+
+var lCount = 1; //挑战答题轮数
+var qCount = random(6, 8); //挑战答题每轮答题数
+/**
+ * @description: 挑战答题
+ * @param: null
+ * @return: null
+ */
+function challengeQuestion(lNum) {
+ let conNum = 0; //连续答对的次数
+ // let lNum = 0;//轮数
+ while (true) {
+ // sleep(1000)
+ if (!className("RadioButton").exists()) {
+ console.error("没有找到题目!请检查是否进入答题界面!");
+ console.log("停止");
+ break;
+ }
+ // while(!className("ListView").exists());
+ questionCommon.challengeQuestionLoop(conNum, qCount);
+ sleep(questionCommon.randomNum(2, 5) * 1000);
+ // sleep(4000);
+ if (text("v5IOXn6lQWYTJeqX2eHuNcrPesmSud2JdogYyGnRNxujMT8RS7y43zxY4coWepspQkvw" +
+ "RDTJtCTsZ5JW+8sGvTRDzFnDeO+BcOEpP0Rte6f+HwcGxeN2dglWfgH8P0C7HkCMJOAAAAAElFTkSuQmCC").exists()) //遇到❌号,则答错了,不再通过结束本局字样判断
+ {
+ if (conNum >= qCount) {
+ lNum++;
+ if (lNum >= lCount) {
+ console.verbose("挑战答题结束!");
+ } else {
+ console.verbose("等5秒开始下一轮...");
+ }
+ back();
+ sleep(1000);
+ back();
+ break;
+ } else {
+ console.error("出现错误,等5秒重新开始...");
+ sleep(3000); //等待5秒才能开始下一轮
+ back();
+ //desc("结束本局").click();//有可能找不到结束本局字样所在页面控件,所以直接返回到上一层
+ sleep(2000);
+ text("再来一局").click();
+ sleep(4000);
+ conNum = 0;
+ }
+ } else //答对了
+ {
+ conNum++;
+ }
+ }
+}
+
+function main() {
+ console.setPosition(0, device.height / 2); //部分华为手机console有bug请注释本行
+ console.show();
+ if (text("每日答题").exists()) {
+ for (i = 0; i < lCount; i++) {
+ let myImage = className("android.view.View").text("每日答题").findOne();
+ // console.log(myImage.parent().parent().childCount());
+ myImage = myImage.parent().parent().child(10);
+ myImage.click();
+ console.warn("第" + (i + 1) + "轮挑战答题");
+ sleep(6000);
+ challengeQuestion(i);
+ }
+ } else {
+ console.verbose("开始挑战答题");
+ sleep(1000);
+ challengeQuestion(1);
+ }
+ // answerWrong();
+ console.hide()
+}
+
+module.exports = main;
\ No newline at end of file
diff --git a/collectCommentShare.js b/collectCommentShare.js
new file mode 100644
index 0000000..64fbd3b
--- /dev/null
+++ b/collectCommentShare.js
@@ -0,0 +1,71 @@
+/**
+ * @description: 延时函数
+ * @param: seconds-延迟秒数
+ * @return: null
+ */
+function delay(seconds)
+{
+ sleep(1000*seconds);//sleep函数参数单位为毫秒所以乘1000
+}
+
+var commentText = ["支持党,支持国家!", "为实现中华民族伟大复兴而不懈奋斗!", "紧跟党走,毫不动摇!", "不忘初心,牢记使命", "努力奋斗,回报祖国!"];//评论内容,可自行修改,大于5个字便计分
+
+function main()
+{
+ var textOrder=text("欢迎发表你的观点").findOnce().drawingOrder();
+ //toastLog("textOrder = "+textOrder);
+ var shouOrder=textOrder+2;
+ var zhuanOrder=textOrder+3;
+ /*className("ImageView").find().forEach(item=>{
+ log(item.drawingOrder());
+ if(item.drawingOrder()==shouOrder) var collectIcon=item;
+ if(item.drawingOrder()==zhuanOrder) var shareIcon=item;
+ });*/
+ var collectIcon=className("ImageView").filter(function(iv){
+ return iv.drawingOrder()==shouOrder;
+ }).findOnce();
+
+ var shareIcon=className("ImageView").filter(function(iv){
+ return iv.drawingOrder()==zhuanOrder;
+ }).findOnce();
+
+ //toastLog("正在进行收藏分享评论...");
+ //收藏
+ //var collectIcon = className("com.uc.webview.export.WebView").findOnce().parent().child(7);//右下角收藏按钮
+ collectIcon.click();//点击收藏
+ delay(2);
+ //var shareIcon = className("com.uc.webview.export.WebView").findOnce().parent().child(8);//右下角分享按钮
+ shareIcon.click();//点击分享
+ while(!textContains("分享到学习强").exists());//等待弹出分享选项界面
+ delay(2);
+ click("分享到学习强国");
+ delay(1);
+ //toastLog("分享成功!");
+ delay(1);
+ back();//返回文章界面
+ delay(2);
+ //评论
+
+ var num=random(0,commentText.length-1)//随机数
+ click("欢迎发表你的观点");
+ delay(1);
+ setText(commentText[num]);//输入评论内容
+ delay(1);
+ click("发布");//点击右上角发布按钮
+ //toastLog("评论成功!");
+ delay(2);
+ click("删除");//删除该评论
+ delay(2);
+ click("确认");//确认删除
+ //toastLog("评论删除成功!");
+ delay(2);
+ collectIcon.click();//取消收藏
+ delay(1);
+ toastLog("运行结束");
+
+ //toastLog("收藏成功!");
+ //分享
+
+}
+
+module.exports = main;
\ No newline at end of file
diff --git a/competition.js b/competition.js
new file mode 100644
index 0000000..9493282
--- /dev/null
+++ b/competition.js
@@ -0,0 +1,179 @@
+importClass(android.database.sqlite.SQLiteDatabase);
+
+var questionCommon = require("./questionCommon.js");
+
+var lCount = 2; //挑战答题轮数
+var rightCount; //正确答题次数
+
+/**
+ * @description: 争上游答题
+ * @param: null
+ * @return: null
+ */
+function competition(lNum) {
+ let conNum = 0; //连续答对的次数
+ // let lNum = 10; //轮数
+ if (text("网络较差").exists()) {
+ toastLog("网络较差!下次再战!");
+ return;
+ }
+ for (i = 0; i < lNum; i++) {
+ if (lNum > 1) {
+ console.warn("第" + (i + 1) + "轮争上游答题");
+ text("开始比赛").click();
+ while (!text("开始").exists());
+ } else if (text("开始比赛").exists()) {
+ console.verbose("开始争上游答题");
+ text("开始比赛").click();
+ while (!text("开始").exists());
+ } else if (className("android.view.View").text("").exists()) {
+ console.verbose("开始双人对战");
+ className("android.view.View").text("").findOne().click();
+ while (!text("开始").exists());
+ // text("").click();
+ // while (text("邀请对手").exists());
+ // text("开始对战").click();
+ }
+ //sleep(4000);
+ conNum = 0; //连续答对的次数
+ rightCount = 0; //答对题数
+ /* if (!className("android.view.View").depth(29).exists()) {
+ while (!text("开始").exists());
+ } */
+ // while(!className("RadioButton").exists());
+ while (rightCount < 5) {
+ // sleep(1000)
+ // while (!className("ListView").exists());
+ /*if (!className("RadioButton").exists()) {
+ console.error("没有找到题目!请检查是否进入答题界面!");
+ console.log("停止");
+ break;
+ }*/
+ try {
+ // var isRight = false;
+ // isRight = questionCommon.competitionLoop(conNum);
+ if (questionCommon.competitionLoop(conNum)) {
+ rightCount++;
+ }
+ } catch (error) {
+ // console.error(error);
+ }
+
+ // console.error("正确题数:" + rightCount)
+ if (text("100").depth(24).exists() || text("继续挑战").exists()) {
+ toastLog("有人100了");
+ break;
+ }
+ //sleep(randomNum(4, 6) * 1000);
+ //sleep(3000);
+ conNum++;
+
+ }
+ sleep(5000);
+ if ((lNum - i) > 1) {
+ text("继续挑战").click();
+ sleep(1000);
+ }
+ }
+ let listPepole = className("android.widget.Image").depth(29).find();
+ if (listPepole.length > 2) {
+ console.verbose("争上游答题结束");
+ for (i = 0; i < 2; i++) {
+ sleep(1000);
+ back();
+ }
+ } else {
+ console.verbose("双人对战结束");
+ sleep(5000);
+ back();
+ sleep(1000);
+ back();
+ text("退出").click();
+ }
+}
+
+/**
+ * @description: 争上游答题
+ * @param: null
+ * @return: null
+ */
+function competitionnew(lNum) {
+ let conNum = 0; //连续答对的次数
+ // let lNum = 10; //轮数
+ if (text("网络较差").exists()) {
+ toastLog("网络较差!下次再战!");
+ return;
+ }
+ for (i = 0; i < lNum; i++) {
+ if (lNum > 1) {
+ console.warn("第" + (i + 1) + "轮争上游答题");
+ text("开始比赛").click();
+ while (!text("开始").exists());
+ } else if (text("开始比赛").exists()) {
+ console.verbose("开始争上游答题");
+ text("开始比赛").click();
+ while (!text("开始").exists());
+ } else if (className("android.view.View").text("").exists()) {
+ console.verbose("开始双人对战");
+ className("android.view.View").text("").findOne().click();
+ while (!text("开始").exists());
+ // text("").click();
+ // while (text("邀请对手").exists());
+ // text("开始对战").click();
+ }
+ //sleep(4000);
+ conNum = 0; //连续答对的次数
+ rightCount = 0; //答对题数
+ /* if (!className("android.view.View").depth(29).exists()) {
+ while (!text("开始").exists());
+ } */
+ // while(!className("RadioButton").exists());
+
+ questionCommon.competitionLoop()
+ sleep(5000);
+ if ((lNum - i) > 1) {
+ text("继续挑战").click();
+ sleep(1000);
+ }
+ }
+ let listPepole = className("android.widget.Image").depth(29).find();
+ if (listPepole.length > 2) {
+ console.verbose("争上游答题结束");
+ for (i = 0; i < 2; i++) {
+ sleep(1000);
+ back();
+ }
+ } else {
+ console.verbose("双人对战结束");
+ sleep(5000);
+ back();
+ sleep(1000);
+ back();
+ text("退出").click();
+ }
+}
+
+function main() {
+ console.setPosition(0, device.height * 0.5); //部分华为手机console有bug请注释本行
+ console.show();
+ if (text("每日答题").exists()) {
+ let myImage = className("android.view.View").text("每日答题").findOne();
+ // console.log(myImage.parent().parent().childCount());
+ myImage = myImage.parent().parent().child(8);
+ myImage.click();
+ //sleep(1000);
+ //className("android.view.View").text("").findOne().click();
+ // console.log("开始争上游答题")
+ sleep(1000);
+ // challengeQuestion();
+ competition(lCount);
+ } else {
+ competition(1);
+ }
+
+ // answerWrong();
+ //console.hide()
+ allCount = 0;
+}
+
+module.exports = main;
\ No newline at end of file
diff --git a/dailyAnswer.js b/dailyAnswer.js
new file mode 100644
index 0000000..b79171e
--- /dev/null
+++ b/dailyAnswer.js
@@ -0,0 +1,76 @@
+importClass(android.database.sqlite.SQLiteDatabase);
+
+var questionCommon = require("./questionCommon.js");
+
+/**
+ * @description: 每日答题
+ * @param: null
+ * @return: null
+ */
+function dailyQuestion() {
+ let dlNum = 0;//每日答题轮数
+ while (true) {
+ sleep(questionCommon.randomNum(1, 4) * 1000);
+ while(!(textStartsWith("填空题").exists() || textStartsWith("多选题").exists() || textStartsWith("单选题").exists()));
+ if (!(textStartsWith("填空题").exists() || textStartsWith("多选题").exists() || textStartsWith("单选题").exists())) {
+ console.error("没有找到题目!请检查是否进入答题界面!");
+ console.log("停止");
+ break;
+ }
+ questionCommon.dailyQuestionLoop();
+ while ((!(textStartsWith("+").exists())) && (dlNum > 4)){
+ if (id("message").exists()) {
+ id("button1").findOne().click();
+ }
+ }
+ if (text("再练一次").exists()) {
+ console.verbose("每周答题结束!");
+ text("返回").click(); sleep(2000);
+ back();
+ break;
+ } else if (text("查看解析").exists()) {
+ console.verbose("专项答题结束!");
+ back();sleep(500);
+ back();sleep(500);
+ break;
+ } else if (text("再来一组").exists()) {
+ sleep(2000);
+ dlNum++;
+ if (!text("领取奖励已达今日上限").exists()) {
+ text("再来一组").click();
+ console.warn("第" + (dlNum + 1).toString() + "轮答题:");
+ sleep(1000);
+ }
+ else {
+ console.verbose("每日答题结束!");
+ while(!text("返回").exists());
+ text("返回").click(); sleep(2000);
+ break;
+ }
+ }
+ }
+}
+
+function main() {
+ console.setPosition(0, device.height * 0.5);
+ console.show();
+ if (text("每日答题").exists()) {
+ for (i = 0 ; i < 1 ; i++) {
+ console.warn("第" + (i + 1) + "轮每日答题");
+ text("每日答题").click();
+ sleep(1000);
+ dailyQuestion();
+ }
+ } else {
+ console.verbose("开始每日答题");
+ sleep(1000);
+ dailyQuestion();
+ }
+ console.hide();
+}
+// 双填空需要两个空字数相等
+// 双填空测试四月第二周(正常)
+// 复杂填空民法典专项一(已支持)
+// main() // 调试完记得注释掉
+module.exports = main;
+// exports.dailyQuestionLoop = dailyQuestionLoop;
\ No newline at end of file
diff --git a/floating.js b/floating.js
new file mode 100644
index 0000000..4bbc9df
--- /dev/null
+++ b/floating.js
@@ -0,0 +1,129 @@
+//开启截屏功能
+if (!requestScreenCapture()) {
+ console.log("请求截图失败");
+ exit();
+}
+//toastLog(" 请在无障碍中选择本 APP");
+auto.waitFor();
+
+let window = floaty.window(
+
+
+
+
+
+
+
+
+
+
+);
+
+let deviceWidth = device.width;
+let deviceHeight = device.height;
+window.setPosition(deviceWidth * 0.7, deviceHeight * 0.4);
+setInterval(() => {
+}, 1000);
+
+
+let wx, wy, downTime, windowX, windowY;
+// 这个函数是对应悬浮窗的移动
+window.move.setOnTouchListener(function (view, event) {
+ switch (event.getAction()) {
+ case event.ACTION_DOWN:
+ wx = event.getRawX();
+ wy = event.getRawY();
+ windowX = window.getX();
+ windowY = window.getY();
+ downTime = new Date().getTime();
+ return true;
+ case event.ACTION_MOVE:
+ // 如果按下的时间超过 xx 秒判断为长按,调整悬浮窗位置
+ if (new Date().getTime() - downTime > 300) {
+ window.setPosition(windowX + (event.getRawX() - wx), windowY + (event.getRawY() - wy));
+ }
+ return true;
+ case event.ACTION_UP:
+ // 手指弹起时如果偏移很小则判断为点击
+ if (Math.abs(event.getRawY() - wy) < 30 && Math.abs(event.getRawX() - wx) < 30) {
+ toastLog(" 长按调整位置 ")
+ }
+ return true;
+ }
+ return true;
+});
+
+window.switchXX.click(() => {
+ toastLog(" 切换到学习强国APP...");
+ if (!launchApp("学习强国"))//启动学习强国app
+ {
+ console.error("找不到学习强国App!");
+ return;
+ }
+});
+
+
+
+// 这个函数是对应悬浮窗的退出
+window.exit.click(() => {
+ toastLog(" 退出!");
+ exit();
+});
+
+
+let th = null;
+
+//收藏评论分享
+window.startSFP.click(() => {
+ let ss = "./collectCommentShare.js";
+ startTh(ss);
+});
+//挑战答题
+window.startDT.click(() => {
+ let ss = "./challengeAnswer.js";
+ startTh(ss);
+});
+//争上游
+window.startZSY.click(() => {
+ let ss = "./competition.js";
+ startTh(ss);
+});
+//每日答题
+window.startMR.click(() => {
+ let ss = "./dailyAnswer.js";
+ startTh(ss);
+});
+
+//停止
+window.stop.click(() => {
+ if (th == null) {
+ toastLog(" 没有进行中的脚本 ");
+ } else {
+ if (th.isAlive()) {
+ threads.shutDownAll();
+ toastLog(" 停止!");
+ } else {
+ toastLog(" 没有进行中的脚本 ");
+ }
+ }
+});
+
+function startTh(fileStr) {
+ var ss = fileStr;
+ if (th == null) {
+ th = threads.start(function () {
+ toastLog(" 开启线程");
+ let begin = require(ss);
+ begin();
+ });
+ } else {
+ if (th.isAlive()) {
+ toastLog(" 脚本都在运行了你还点!?");
+ } else {
+ th = threads.start(function () {
+ let begin = require(ss);
+ begin();
+ });
+ }
+ }
+}
\ No newline at end of file
diff --git a/main.js b/main.js
new file mode 100644
index 0000000..6dfe631
--- /dev/null
+++ b/main.js
@@ -0,0 +1,7 @@
+//开启截屏功能
+/* if (!requestScreenCapture()) {
+ console.log("请求截图失败");
+ exit();
+} */
+// requestScreenCapture();
+engines.execScriptFile("UI.js");
\ No newline at end of file
diff --git a/project.json b/project.json
new file mode 100644
index 0000000..1e91aeb
--- /dev/null
+++ b/project.json
@@ -0,0 +1,26 @@
+{
+ "assets": [],
+ "build": {
+ "build_id": "78660F54-108",
+ "build_number": 108,
+ "build_time": 1627298314247
+ },
+ "useFeatures": [],
+ "icon": "res/logo.png",
+ "launchConfig": {
+ "hideLogs": true,
+ "serviceDesc": "Auto Study Script App",
+ "splashText": "Power by Myue",
+ "stableMode": false
+ },
+ "main": "main.js",
+ "name": "AIXUE",
+ "packageName": "cc.myue.aixue",
+ "scripts": {},
+ "signingConfig": {
+ "alias": "myue",
+ "keystore": "/storage/emulated/0/脚本/.keyStore/myue.keystore"
+ },
+ "versionCode": 2,
+ "versionName": "2.3.1"
+}
\ No newline at end of file
diff --git a/questionCommon.js b/questionCommon.js
new file mode 100644
index 0000000..066be44
--- /dev/null
+++ b/questionCommon.js
@@ -0,0 +1,955 @@
+var tikuCommon = require("./tikuCommon.js");
+
+/*************************************************公共部分******************************************************/
+/**
+ * @description: 延时函数
+ * @param: seconds-延迟秒数
+ * @return: null
+ */
+function delay(seconds) {
+ sleep(1000 * seconds); //sleep函数参数单位为毫秒所以乘1000
+}
+
+/**
+ * @description: 生成从minNum到maxNum的随机数
+ * @param: minNum-较小的数
+ * @param: maxNum-较大的数
+ * @return: null
+ */
+function randomNum(minNum, maxNum) {
+ switch (arguments.length) {
+ case 1:
+ return parseInt(Math.random() * minNum + 1, 10);
+ case 2:
+ return parseInt(Math.random() * (maxNum - minNum + 1) + minNum, 10);
+ default:
+ return 0;
+ }
+}
+
+/**
+ * @description: 返回字段首字母序号
+ * @param: str
+ * @return: int 字母序号
+ */
+function indexFromChar(str) {
+ return str.charCodeAt(0) - "A".charCodeAt(0);
+}
+
+/**
+ * @description: 返回字段首字母
+ * @param: int 字母序号
+ * @return: str
+ */
+function charFromIndex(int) {
+ return String.fromCharCode("A".charCodeAt(0) + int);
+}
+
+/*************************************************挑战答题部分******************************************************/
+/**
+ * @description: 答错后查找正确答案
+ * @param: delayTime, myColor, myThreshold, listArray, options
+ * @return: correctAns 正确答案
+ */
+function findCorrectAnswer(delayTime, myColor, myThreshold, listArray, options) {
+ console.hide(); //隐藏console控制台窗口
+ sleep(delayTime); //等待截屏
+ var img = captureScreen(); //截个屏
+ // let imgName = "./ddd" + new Date().getTime() + ".png";
+ // let imgName = "./ddd.png";
+ // captureScreen(imgName);//截个屏
+ // var img = images.read(imgName);
+ // toastLog(imgName);
+ console.show(); //显示console控制台窗口
+ //delay(3);
+ // 查找绿色答案#f24650
+ var correctAns = new Array();
+ listArray.some(item => {
+ var listBounds = item.bounds();
+ // console.log(listBounds);
+ var point = findColor(img, myColor, {
+ region: [listBounds.left, listBounds.top, listBounds.right - listBounds.left, listBounds.bottom - listBounds.top],
+ threshold: myThreshold
+ });
+ if (point) {
+ correctAns.push(options[listArray.indexOf(item)]);
+ correctAns.push(charFromIndex(listArray.indexOf(item)));
+ toastLog(correctAns);
+ return true;
+ } else {
+ // console.log("没找到");
+ }
+ });
+ return correctAns;
+}
+
+/**
+ * @description: 每次答题循环
+ * @param: conNum 连续答对的次数
+ * @return: null
+ */
+function challengeQuestionLoop(conNum, qCount) {
+ if (conNum >= qCount) //答题次数足够退出,每轮5次
+ {
+ let listArray = className("ListView").findOnce().children(); //题目选项列表
+ let i = random(0, listArray.length - 1);
+ console.log("本轮次数足够,随机点击一个答案,答错进入下一轮");
+ listArray[i].child(0).click(); //随意点击一个答案
+ console.log("----------------------------------");
+ return;
+ }
+
+ if (className("ListView").exists()) {
+ var question = className("ListView").findOnce().parent().child(0).text();
+ console.log((conNum + 1).toString() + ".题目:" + question);
+ } else {
+ console.error("提取题目失败!");
+ let listArray = className("ListView").findOnce().children(); //题目选项列表
+ let i = random(0, listArray.length - 1);
+ console.log("随机点击一个");
+ listArray[i].child(0).click(); //随意点击一个答案
+ return;
+ }
+
+ var chutiIndex = question.lastIndexOf("出题单位");
+ if (chutiIndex != -1) {
+ question = question.substring(0, chutiIndex - 2);
+ }
+
+ question = question.replace(/\s/g, "");
+
+ var options = []; //选项列表
+ if (className("ListView").exists()) {
+ className("ListView").findOne().children().forEach(child => {
+ var answer_q = child.child(0).child(1).text();
+ options.push(answer_q);
+ });
+ } else {
+ console.error("答案获取失败!");
+ return;
+ }
+
+ // 特殊情况外理
+ let specialQuestion = ["选择词语的正确词形。", "选择正确的读音。", "下列词形正确的是。来源:《现代汉语词典》(商务印书馆2016年第7版)", "下列读音正确的是。来源:《现代汉语词典》(商务印书馆2016年第7版)", "选择正确的读音。来源:《现代汉语词典(第七版)》(商务印书馆2017年版)"]
+ if (specialQuestion.indexOf(question) > -1) {
+ question = question + options[0];
+ }
+
+ var answer = tikuCommon.getAnswer(question, '挑战题');
+ /* if (answer.length == 0) { //tiku表中没有则到tikuNet表中搜索答案
+ answer = getAnswer(question, 'tikuNet');
+ } */
+
+ if (/^[a-zA-Z]{1}$/.test(answer)) { //如果为ABCD形式
+ var indexAnsTiku = indexFromChar(answer.toUpperCase());
+ answer = options[indexAnsTiku];
+ var url = "https://api.myue.gq/xuexi/renew.php";
+ var res = http.post(url, {
+ "question": question,
+ "answer": answer
+ });
+ var html = res.body.string();
+ console.log(answer);
+ }
+
+ let hasClicked = false;
+ var listArray = className("ListView").findOnce().children(); //题目选项列表
+ if ((answer == "") || !textEndsWith(answer).exists()) //如果没找到答案
+ {
+ let i = random(0, listArray.length - 1);
+ console.error("没有找到答案,随机点击一个");
+ listArray[i].child(0).click(); //随意点击一个答案
+
+ var delayTime = 800;
+ var myColor = "#44BF78";
+ var myThreshold = 4;
+ var correctAns = findCorrectAnswer(delayTime, myColor, myThreshold, listArray, options);
+ console.info("正确答案是:" + correctAns[0]);
+
+ /* console.hide(); //隐藏console控制台窗口
+ sleep(100); //等待截屏
+ var img = captureScreen();//截个屏
+ // captureScreen("./ddd.png");//截个屏
+ // var img = images.read("./ddd.png");
+ console.show(); //显示console控制台窗口
+ //delay(3);
+ // 查找绿色答案#f24650
+ var correctAns = false;
+ listArray.forEach(item => {
+ var listBounds = item.bounds();
+ // console.log(listBounds);
+ var point = findColor( img, "#44BF78", {
+ region: [listBounds.left, listBounds.top, listBounds.right-listBounds.left, listBounds.bottom-listBounds.top],
+ threshold: 4
+ });
+ if(point){
+ correctAns = options[listArray.indexOf(item)];
+ console.log("正确答案是:" + correctAns);
+ }else{
+ // console.log("没找到");
+ }
+ }); */
+
+ hasClicked = true;
+ // 更新题库
+ // delay(1);
+ if (correctAns) //如果答案不是null,就更新题库
+ {
+ if (answer == "") {
+ if (correctAns[0] != undefined) {
+ var url = "https://api.myue.gq/xuexi/commit.php";
+ var res = http.post(url, {
+ "question": question,
+ "answer": correctAns[0],
+ "category": '挑战题'
+ });
+ var html = res.body.string();
+ console.log(correctAns[0]);
+ console.log(html);
+ }
+ //var sql = "INSERT INTO tiku (question, option, answer, wrongAnswer) VALUES ('" + question + "','" + correctAns[1] + "','" + correctAns[0] + "','')";
+ } else {
+ //var sql = "UPDATE tiku SET answer='" + correctAns[0] + "' option='" + correctAns[1] + "' WHERE question LIKE '" + question + "'";
+ var url = "https://api.myue.gq/xuexi/renew.php";
+ var res = http.post(url, {
+ "question": question,
+ "answer": correctAns[0]
+ });
+ var html = res.body.string();
+ console.log(question);
+ console.log(html);
+ }
+ // console.log(correctAns);
+ console.log("更新题库答案...");
+ }
+ console.log("-------------------------------");
+ } else //如果找到了答案
+ {
+ /* listArray.some(item => {
+ var listDescStr = item.child(0).child(1).text();
+ console.error(deleteNO(listDescStr));
+ if (deleteNO(listDescStr) == answer) {
+ item.child(0).click(); //点击答案
+ hasClicked = true;
+ rightCount++;
+ console.log("-------------------------------");
+ return true;
+ }
+ }); */
+ console.info("答案:" + answer);
+ var optletters = charFromIndex(options.indexOf(answer));
+ // toastLog(optletters);
+ //tikuCommon.insertOrUpdate(sql);
+ // console.log("更新题库答案...");
+ text(answer).click();
+ hasClicked = true;
+ console.log("-------------------------------");
+
+ var delayTime = 120;
+ var myColor = "#44BF78";
+ var myThreshold = 4;
+ // var correctAns = findCorrectAnswer(delayTime, myColor, myThreshold, listArray, options);
+
+ delay(1);
+ if (text("v5IOXn6lQWYTJeqX2eHuNcrPesmSud2JdogYyGnRNxujMT8RS7y43zxY4coWepspQkvw" +
+ "RDTJtCTsZ5JW+8sGvTRDzFnDeO+BcOEpP0Rte6f+HwcGxeN2dglWfgH8P0C7HkCMJOAAAAAElFTkSuQmCC").exists()) //遇到❌号,则答错了,不再通过结束本局字样判断
+ {
+ // var sql = "DELETE FROM tiku WHERE question = '" + question + "'";
+ // tikuCommon.insertOrUpdate(sql);
+ // toastLog("答案有误,删除此题!");
+ var correctAns = findCorrectAnswer(delayTime, myColor, myThreshold, listArray, options);
+ console.info("正确答案是:" + correctAns);
+ var url = "https://api.myue.gq/xuexi/renew.php";
+ var res = http.post(url, {
+ "question": question,
+ "answer": correctAns[0]
+ });
+ var html = res.body.string();
+ console.log(html);
+ toastLog("答案有误,已更正答案!");
+ }
+ }
+ if (!hasClicked) //如果没有点击成功
+ {
+ console.error("未能成功点击,随机点击一个");
+ let i = random(0, listArray.length - 1);
+ listArray[i].child(0).click(); //随意点击一个答案
+ console.log("-------------------------------");
+ }
+}
+
+/*************************************************争上游、双人对战部分*************************************************/
+/**
+ * @description: 答题争上游、双人对战,去掉题目和答案前面的序号
+ * @param: str 问题或答案
+ * @return: 去掉序号后的题目或答案
+ */
+function deleteNO(str) {
+ /* if (className("android.view.View").textStartsWith("距离答题结束").exists()) {
+ // console.log(str.slice(3));
+ return str.slice(3);
+ } else {
+ return str;
+ } */
+ return str.slice(3);
+}
+
+/*************************************************争上游答题部分******************************************************/
+/**
+ * @description: 双人对战答题循环
+ * @param: conNum 连续答对的次数
+ * @return: null
+ */
+function competitionLoop(conNum) {
+ var question = "";
+ // className("android.view.View").depth(29).waitFor();
+ while (question == "") {
+ // console.error(conNum);
+ // if (className("ListView").exists()) {
+ // question = className("ListView").findOnce().parent().child(0).text();
+ if (className("android.view.View").depth(29).exists() && !text("继续挑战").exists()) {
+ question = className("android.view.View").depth(29).findOnce().text();
+ // console.log(question);
+ if (question == "") {
+ return false;
+ }
+ if (question.slice(0, question.indexOf(".")) == conNum) {
+ question = "";
+ } else {
+ question = deleteNO(question);
+ console.log((conNum + 1).toString() + ".题目:" + question);
+
+ var chutiIndex = question.lastIndexOf("出题单位");
+ if (chutiIndex != -1) {
+ question = question.substring(0, chutiIndex - 2);
+ }
+
+ question = question.replace(/\s/g, "");
+
+
+ // className("ListView").waitFor();
+ sleep(500);
+ var listArray = className("ListView").findOnce().children(); //题目选项列表
+ // 特殊情况外理
+ let specialQuestion = ["选择词语的正确词形。", "选择正确的读音。"]
+ if (specialQuestion.indexOf(question) > -1) {
+ question = question + deleteNO(listArray[0].child(0).child(1).text());
+ }
+
+ var answer = tikuCommon.getAnswer(question, '对战题');
+ /* if (answer.length == 0) { //tiku表中没有则到tikuNet表中搜索答案
+ answer = getAnswer(question, 'tikuNet');
+ } */
+
+
+ if (/^[a-zA-Z]{1}$/.test(answer)) { //如果为ABCD形式
+ var indexAnsTiku = indexFromChar(answer.toUpperCase());
+ answer = listArray[indexAnsTiku].child(0).child(1).text();
+ answer = deleteNO(answer);
+ var url = "https://api.myue.gq/xuexi/renew.php";
+ var res = http.post(url, {
+ "question": question,
+ "answer": answer
+ });
+ var html = res.body.string();
+ console.log(answer);
+ }
+
+ if (text("100").depth(24).exists()) {
+ toastLog("有人100了");
+ return;
+ }
+
+
+ let hasClicked = false;
+ // let listArray = className("ListView").findOnce().children(); //题目选项列表
+ if (answer == "") //如果没找到答案
+ {
+ let i = random(0, listArray.length - 1);
+ console.error("没有找到答案,随机点击一个");
+ listArray[i].child(0).click(); //随意点击一个答案
+
+ var options = []; //选项列表
+ while (options.length == 0) {
+ if (className("ListView").exists()) {
+ className("ListView").findOne().children().forEach(child => {
+ var answer_q = child.child(0).child(1).text();
+ options.push(answer_q);
+ });
+ } else {
+ console.error("答案获取失败!");
+ return;
+ }
+ }
+
+ var delayTime = 1055;
+ var myColor = "#2BC87E";
+ var myThreshold = 25;
+ var correctAns = findCorrectAnswer(delayTime, myColor, myThreshold, listArray, options);
+
+ // 更新题库
+ // delay(1);
+ if (correctAns) //如果答案不是null,就更新题库
+ {
+ correctAns[0] = deleteNO(correctAns[0]);
+ console.info("正确答案是:" + correctAns[0]);
+ // console.log(correctAns);
+ var url = "https://api.myue.gq/xuexi/commit.php";
+ var res = http.post(url, {
+ "question": question,
+ "answer": correctAns[0],
+ "category": '对战题'
+ });
+ var html = res.body.string();
+ console.log(html);
+ console.log("更新题库答案...");
+ }
+ if (correctAns[0] == deleteNO(options[i])) { //listArray[i].child(0).child(1).text()
+ return true;
+ }
+ console.log("-------------------------------");
+ hasClicked = true;
+ } else //如果找到了答案
+ {
+ console.info("答案:" + answer);
+ /* listArray.some(item => {
+ var listDescStr = item.child(0).child(1).text();
+ console.error(deleteNO(listDescStr));
+ if (deleteNO(listDescStr) == answer) {
+ item.child(0).click(); //点击答案
+ hasClicked = true;
+ rightCount++;
+ console.log("-------------------------------");
+ return true;
+ }
+ }); */
+ if (textEndsWith(answer).exists()) {
+ /* var optletters = textEndsWith(answer).findOnce().text();
+ optletters = optletters[0];
+ toastLog(optletters); */
+ textEndsWith(answer).click();
+ hasClicked = true;
+ console.log("-------------------------------");
+ return true;
+ }
+ }
+ //console.error(hasClicked);
+ if (!hasClicked) //如果没有点击成功
+ {
+ console.error("未能成功点击,随机点击一个");
+ let i = random(0, listArray.length - 1);
+ listArray[i].child(0).click(); //随意点击一个答案
+ console.log("-------------------------------");
+ }
+ return false;
+ }
+ } else {
+ // console.error("提取题目失败!");
+ /* let listArray = className("ListView").findOnce().children(); //题目选项列表
+ let i = random(0, listArray.length - 1);
+ console.log("随机点击一个");
+ listArray[i].child(0).click(); //随意点击一个答案 */
+ // return false;
+ }
+ // delay(0.1);
+ }
+
+
+}
+
+/**
+ * @description: 双人对战答题循环
+ * @param: conNum 连续答对的次数
+ * @return: null
+ */
+function competitionLoopnew() {
+ // var question = "";
+ // className("android.view.View").depth(29).waitFor();
+ while (className("android.view.View").depth(29).exists() && !text("继续挑战").exists()) {
+ try {
+ if (className("android.view.View").depth(29).exists() && !text("继续挑战").exists()) {
+ var aquestion = className("android.view.View").depth(29).findOnce().text();
+ var question = deleteNO(aquestion);
+ }
+ if (aquestion != oldaquestion && question != "") {
+
+ console.log(aquestion.slice(0, aquestion.indexOf(".")) + ".题目:" + question);
+ var chutiIndex = question.lastIndexOf("出题单位");
+ if (chutiIndex != -1) {
+ question = question.substring(0, chutiIndex - 2);
+ }
+
+ question = question.replace(/\s/g, "");
+
+
+ // className("ListView").waitFor();
+ sleep(500);
+ var listArray = className("ListView").findOnce().children(); //题目选项列表
+ // 特殊情况外理
+ let specialQuestion = ["选择词语的正确词形。", "选择正确的读音。"]
+ if (specialQuestion.indexOf(question) > -1) {
+ question = question + deleteNO(listArray[0].child(0).child(1).text());
+ }
+
+ var answer = tikuCommon.getAnswer(question, '对战题');
+ /* if (answer.length == 0) { //tiku表中没有则到tikuNet表中搜索答案
+ answer = getAnswer(question, 'tikuNet');
+ } */
+
+
+ /*
+ if (/^[a-zA-Z]{1}$/.test(answer)) { //如果为ABCD形式
+ var indexAnsTiku = indexFromChar(answer.toUpperCase());
+ answer = listArray[indexAnsTiku].child(0).child(1).text();
+ answer = deleteNO(answer);
+ toastLog("answer from char=" + answer);
+ } */
+
+ if (text("100").depth(24).exists()) {
+ toastLog("有人100了");
+ return;
+ }
+
+
+ let hasClicked = false;
+ // let listArray = className("ListView").findOnce().children(); //题目选项列表
+ if (answer == "") //如果没找到答案
+ {
+ let i = random(0, listArray.length - 1);
+ console.error("没有找到答案,随机点击一个");
+ listArray[i].child(0).click(); //随意点击一个答案
+
+ var options = []; //选项列表
+ while (options.length == 0) {
+ if (className("ListView").exists()) {
+ className("ListView").findOne().children().forEach(child => {
+ var answer_q = child.child(0).child(1).text();
+ options.push(answer_q);
+ });
+ } else {
+ console.error("答案获取失败!");
+ return;
+ }
+ }
+
+ var delayTime = 1055;
+ var myColor = "#2BC87E";
+ var myThreshold = 25;
+ var correctAns = findCorrectAnswer(delayTime, myColor, myThreshold, listArray, options);
+
+ // 更新题库
+ // delay(1);
+ if (correctAns) //如果答案不是null,就更新题库
+ {
+ correctAns[0] = deleteNO(correctAns[0]);
+ console.info("正确答案是:" + correctAns[0]);
+ var sql = "INSERT INTO tiku (question, option, answer, wrongAnswer) VALUES ('" + question + "','" + correctAns[1] + "','" + correctAns[0] + "','')";
+ // console.log(correctAns);
+ var url = "https://api.myue.gq/xuexi/commit.php";
+ var res = http.post(url, {
+ "question": question,
+ "answer": correctAns[0]
+ });
+ var html = res.body.string();
+ console.log(html);
+ tikuCommon.insertOrUpdate(sql);
+ console.log("更新题库答案...");
+ }
+ /* if (correctAns[0] == deleteNO(options[i])) { //listArray[i].child(0).child(1).text()
+ return true;
+ } */
+ console.log("-------------------------------");
+ hasClicked = true;
+ } else //如果找到了答案
+ {
+ console.info("答案:" + answer);
+ /* listArray.some(item => {
+ var listDescStr = item.child(0).child(1).text();
+ console.error(deleteNO(listDescStr));
+ if (deleteNO(listDescStr) == answer) {
+ item.child(0).click(); //点击答案
+ hasClicked = true;
+ rightCount++;
+ console.log("-------------------------------");
+ return true;
+ }
+ }); */
+
+ if (textEndsWith(answer).exists()) {
+ /* var optletters = textEndsWith(answer).findOnce().text();
+ optletters = optletters[0];
+ toastLog(optletters); */
+ textEndsWith(answer).click();
+ hasClicked = true;
+ console.log("-------------------------------");
+ // return true;
+ }
+ }
+ //console.error(hasClicked);
+ if (!hasClicked) //如果没有点击成功
+ {
+ console.error("未能成功点击,随机点击一个");
+ let i = random(0, listArray.length - 1);
+ listArray[i].child(0).click(); //随意点击一个答案
+ console.log("-------------------------------");
+ }
+ // return false;
+ var oldaquestion = aquestion; //对比新旧题目
+ }
+ } catch (e) {
+ logDefault(e); //输出错误信息,调试用
+ logError("出现错误,请检查3!");
+ return;
+ }
+ }
+}
+
+/*************************************************每日答题部分***************************************************/
+/**
+ * @description: 获取填空题题目数组
+ * @param: null
+ * @return: questionArray
+ */
+function getFitbQuestion() {
+ var questionCollections = className("EditText").findOnce().parent().parent();
+ var questionArray = [];
+ var findBlank = false;
+ var blankCount = 0;
+ var blankNumStr = "";
+ var i = 0;
+ questionCollections.children().forEach(item => {
+ if (item.className() != "android.widget.EditText") {
+ if (item.text() != "") { //题目段
+ if (findBlank) {
+ blankNumStr = "|" + blankCount.toString();
+ questionArray.push(blankNumStr);
+ findBlank = false;
+ }
+ questionArray.push(item.text());
+ } else {
+ findBlank = true;
+ blankCount = (className("EditText").findOnce(i).parent().childCount() - 1);
+ i++;
+ }
+ }
+ });
+ /* questionArray.forEach( item=> {
+ console.log(item);
+ }) */
+ return questionArray;
+}
+
+/**
+ * @description: 获取选择题题目数组
+ * @param: null
+ * @return: questionArray
+ */
+function getChoiceQuestion() {
+ var questionCollections = className("ListView").findOnce().parent().child(1);
+ var questionArray = [];
+ questionArray.push(questionCollections.text());
+ return questionArray;
+}
+
+
+/**
+ * @description: 获取提示字符串
+ * @param: null
+ * @return: tipsStr
+ */
+function getTipsStr() {
+ var tipsStr = "";
+ while (tipsStr == "") {
+ if (text("查看提示").exists()) {
+ var seeTips = text("查看提示").findOnce();
+ seeTips.click();
+ delay(1);
+ click(device.width * 0.5, device.height * 0.41);
+ delay(1);
+ click(device.width * 0.5, device.height * 0.35);
+ } else {
+ console.error("未找到查看提示");
+ }
+ if (text("提示").exists()) {
+ var tipsLine = text("提示").findOnce().parent();
+ //获取提示内容
+ if (tipsLine.parent().child(1).child(0).text() == "") {
+ var tipsViewArray = tipsLine.parent().child(1).child(0).children();
+ } else {
+ var tipsViewArray = tipsLine.parent().child(1).children();
+ }
+ tipsViewArray.forEach(item => {
+ if (item.text().substr(0, 2) != "--" || item.text().substr(0, 2) != "来源") {
+ tipsStr += item.text();
+ }
+ })
+ // console.log("提示:" + tipsStr);
+ //关闭提示
+ tipsLine.child(1).click();
+ break;
+ }
+ delay(1);
+ }
+ return tipsStr;
+}
+
+
+/**
+ * @description: 从提示中获取填空题答案
+ * @param: timu, tipsStr
+ * @return: ansTips
+ */
+function getAnswerFromTips(timu, tipsStr) {
+ var ansTips = "";
+ for (var i = 1; i < timu.length - 1; i++) {
+ if (timu[i].charAt(0) == "|") {
+ var blankLen = timu[i].substring(1);
+ var indexKey = tipsStr.indexOf(timu[i + 1]);
+ var ansFind = tipsStr.substr(indexKey - blankLen, blankLen);
+ ansTips += ansFind;
+ }
+ }
+ return ansTips;
+}
+
+/**
+ * @description: 根据提示点击选择题选项
+ * @param: tipsStr
+ * @return: clickStr
+ */
+function clickByTips(tipsStr) {
+ var clickStr = "";
+ var correctAnswerStr = "";
+ var isFind = false;
+ if (className("ListView").exists()) {
+ var listArray = className("ListView").findOne().children();
+ listArray.forEach(item => {
+ var ansStr = item.child(0).child(2).text();
+ if (tipsStr.indexOf(ansStr) >= 0) {
+ item.child(0).click();
+ clickStr += item.child(0).child(1).text().charAt(0);
+ correctAnswerStr = ansStr;
+ isFind = true;
+ }
+ });
+ if (!isFind) { //没有找到 随机点击一个
+ console.error("未能成功点击,随机点击一个");
+ let i = random(0, listArray.length - 1);
+ listArray[i].child(0).click();
+ clickStr += listArray[i].child(0).child(1).text().charAt(0);
+ correctAnswerStr = listArray[i].child(0).child(2).text();
+ }
+ }
+ if (textStartsWith("单选题").exists()) {
+ return correctAnswerStr;
+ } else {
+ return clickStr;
+ }
+}
+
+
+/**
+ * @description: 根据答案点击选择题选项
+ * @param: answer
+ * @return: null
+ */
+function clickByAnswer(answer) {
+ var hasClicked = false;
+ if (className("ListView").exists()) {
+ var listArray = className("ListView").findOnce().children();
+ listArray.forEach(item => {
+ var listIndexStr = item.child(0).child(1).text().charAt(0);
+ //单选答案为非ABCD
+ var listDescStr = item.child(0).child(2).text();
+ // console.log(listDescStr)
+ if (answer == listDescStr) {
+ item.child(0).click();
+ hasClicked = true;
+ } else if (answer.indexOf(listIndexStr) >= 0) {
+ item.child(0).click();
+ hasClicked = true;
+ }
+ });
+ if (!hasClicked) { //没有找到 随机点击一个
+ console.error("未能成功点击,随机点击一个");
+ let i = random(0, listArray.length - 1);
+ listArray[i].child(0).click();
+ // clickStr += listArray[i].child(0).child(1).text().charAt(0);
+ // correctAnswerStr = listArray[i].child(0).child(2).text();
+ }
+ }
+}
+
+/**
+ * @description: 检查答案是否正确,并更新数据库
+ * @param: question, ansTiku, answer
+ * @return: null
+ */
+function checkAndUpdate(question, ansTiku, answer) {
+ if (text("下一题").exists() || text("完成").exists()) { //答错了
+ swipe(100, device.height - 100, 100, 100, 500);
+ var nCount = 0
+ while (nCount < 5) {
+ if (textStartsWith("正确答案").exists()) {
+ var correctAns = textStartsWith("正确答案").findOnce().text().substr(6);
+ if (textStartsWith("单选题").exists()) {
+ //单选题选项
+ var optletters = correctAns;
+ // 单选题答案
+ var alpha = "ABCDEF";
+ let indexList = alpha.indexOf(correctAns);
+ var listArray = className("ListView").findOne().children();
+ // 找到答案项
+ correctAns = listArray[indexList].child(0).child(2).text();
+ }
+ console.info("正确答案是:" + correctAns);
+ if (ansTiku == "") { //题库为空则插入正确答案
+ var url = "https://api.myue.gq/xuexi/commit.php";
+ var res = http.post(url, {
+ "question": question,
+ "answer": correctAns,
+ "category": "填空题"
+ });
+ var html = res.body.string();
+ console.log(html);
+ } else { //更新题库答案
+ //var sql = "UPDATE tiku SET answer='" + correctAns + "' option='" + optletters + "' WHERE question LIKE '" + question + "'";
+ var url = "https://api.myue.gq/xuexi/renew.php";
+ var res = http.post(url, {
+ "question": question,
+ "answer": correctAns
+ });
+ var html = res.body.string();
+ console.log(question);
+ console.log(html);
+ }
+ console.log("更新题库答案...");
+ delay(1);
+ break;
+ } else {
+ var clickPos = className("android.webkit.WebView").findOnce().child(2).child(0).child(1).bounds();
+ click(clickPos.left + device.width * 0.13, clickPos.top + device.height * 0.1);
+ console.error("未捕获正确答案,尝试修正");
+ }
+ nCount++;
+ }
+ if (className("Button").exists()) {
+ className("Button").findOnce().click();
+ } else {
+ click(device.width * 0.85, device.height * 0.06);
+ }
+ } else { //正确后进入下一题,或者进入再来一局界面
+ if (ansTiku == "" && answer != "") { //正确进入下一题,且题库答案为空
+ var url = "https://api.myue.gq/xuexi/commit.php";
+ var res = http.post(url, {
+ "question": question,
+ "answer": answer,
+ "category": '填空题'
+ });
+ var html = res.body.string();
+ console.log(html);
+ console.log("更新题库答案...");
+ }
+ }
+}
+
+
+/**
+ * @description: 每日答题循环
+ * @param: null
+ * @return: null
+ */
+function dailyQuestionLoop() {
+ if (textStartsWith("填空题").exists()) {
+ var questionType = "填空题:"; //questionType题型是什么
+ var questionArray = getFitbQuestion();
+ //console.log('填空题')
+ } else if (textStartsWith("多选题").exists()) {
+ var questionType = "多选题:";
+ var questionArray = getChoiceQuestion();
+ //console.log('选择题')
+ } else if (textStartsWith("单选题").exists()) {
+ var questionType = "单选题:";
+ var questionArray = getChoiceQuestion();
+ }
+
+ var blankArray = [];
+ var question = "";
+ questionArray.forEach(item => {
+ if (item != null && item.charAt(0) == "|") { //是空格数
+ blankArray.push(item.substring(1));
+ } else { //是题目段
+ question += item;
+ }
+ });
+ question = question.replace(/\s/g, "");
+ console.log(questionType + question);
+
+ // 特殊情况外理
+ let specialQuestion = ["选择词语的正确词形。", "选择正确的读音。"]
+ if (specialQuestion.indexOf(question) > -1) {
+ question = question + className("ListView").findOnce().child(0).child(0).child(2).text();
+ }
+ var ansTiku = tikuCommon.getAnswer(question, '填空题');
+
+ /* if (ansTiku.length == 0) {//tiku表中没有则到tikuNet表中搜索答案
+ ansTiku = getAnswer(question, 'tikuNet');
+ } */
+ var answer = ansTiku.replace(/(^\s*)|(\s*$)/g, "");
+
+ if (textStartsWith("填空题").exists()) {
+ if (answer == "") {
+ var tipsStr = getTipsStr();
+ answer = getAnswerFromTips(questionArray, tipsStr);
+ console.info("提示中的答案:" + answer);
+ setText(0, answer.substr(0, blankArray[0]));
+ if (blankArray.length > 1) {
+ for (var i = 1; i < blankArray.length; i++) {
+ setText(i, answer.substr(blankArray[i - 1], blankArray[i]));
+ }
+ }
+ } else {
+ console.info("答案:" + answer);
+ setText(0, answer.substr(0, blankArray[0]));
+ if (blankArray.length > 1) {
+ for (var i = 1; i < blankArray.length; i++) {
+ setText(i, answer.substr(blankArray[i - 1], blankArray[i]));
+ }
+ }
+ }
+ } else if (textStartsWith("多选题").exists() || textStartsWith("单选题").exists()) {
+ if (answer == "") {
+ var tipsStr = getTipsStr();
+ answer = clickByTips(tipsStr);
+ console.info("提示中的答案:" + answer);
+ } else {
+ console.info("答案:" + ansTiku);
+ clickByAnswer(answer);
+ }
+ }
+
+ delay(1.5);
+
+ if (text("确定").exists()) {
+ text("确定").click();
+ delay(0.5);
+ } else if (text("下一题").exists()) {
+ click("下一题");
+ delay(0.5);
+ } else if (text("完成").exists()) {
+ text("完成").click();
+ delay(0.5);
+ } else {
+ console.warn("未找到右上角确定按钮控件,根据坐标点击");
+ click(device.width * 0.85, device.height * 0.06); //右上角确定按钮,根据自己手机实际修改
+ }
+
+ checkAndUpdate(question, ansTiku, answer);
+ console.log("---------------------");
+ delay(2);
+}
+
+exports.randomNum = randomNum;
+exports.challengeQuestionLoop = challengeQuestionLoop;
+exports.competitionLoop = competitionLoop;
+exports.dailyQuestionLoop = dailyQuestionLoop;
\ No newline at end of file
diff --git a/readme.md b/readme.md
new file mode 100644
index 0000000..4aefeb5
--- /dev/null
+++ b/readme.md
@@ -0,0 +1,21 @@
+## AIXUE
+
+修改自 **[lolisaikou](https://github.com/lolisaikou) / [LazyStudy](https://github.com/lolisaikou/LazyStudy)** 自动化脚本,解放你的双手!
+
+#### 环境依赖
+
+- 安卓版本`7.0`及以上版本
+- 授权 `无障碍` 和 `悬浮窗`。
+
+#### 关于
+
+使用需严格遵守开源许可协议。严禁用于商业用途,禁止使用`AIXUE`进行任何盈利活动。对一切非法使用所产生的后果,本人概不负责。
+
+#### 觉得不错?
+
+`Star` 这个项目, `Watch` 这个项目,分享给其他小伙伴吧
+
+#### 问题提交
+
+- 发布`Issue`前检查你现在提出的`Issue`是否已经被提及,发布重复的`Issue`会让双方都降低效率。
+
diff --git a/tikuCommon.js b/tikuCommon.js
new file mode 100644
index 0000000..857cd8a
--- /dev/null
+++ b/tikuCommon.js
@@ -0,0 +1,255 @@
+importClass(android.database.sqlite.SQLiteDatabase);
+
+/**
+ * @description: 判断题库是否存在
+ * @param: null
+ * @return: boolean
+ */
+function judge_tiku_existence() {
+ var dbName = "tiku.db"; //题库文件名
+ var path = files.path(dbName);
+ if (!files.exists(path)) {
+ //files.createWithDirs(path);
+ console.error("未找到题库!请将题库文件放置与js文件同一目录下再运行!");
+ return false;
+ }
+ var db = SQLiteDatabase.openOrCreateDatabase(path, null);
+ var createTable = "\
+ CREATE TABLE IF NOT EXISTS tiku(\
+ question CHAR(253),\
+ option CHAR(10),\
+ answer CHAR(100),\
+ wrongAnswer CHAR(100)\
+ );";
+ db.execSQL(createTable);
+ db.close();
+ return true;
+}
+
+/**
+ * @description: 返回数据库列名
+ * @param: columnName
+ * @return: boolean
+ */
+function judge_tiku_columnName_existence(columnName) {
+ var dbName = "tiku.db"; //题库文件名
+ var path = files.path(dbName);
+ if (!files.exists(path)) {
+ //files.createWithDirs(path);
+ console.error("未找到题库!请将题库文件放置与js文件同一目录下再运行!");
+ return false;
+ }
+ var db = SQLiteDatabase.openOrCreateDatabase(path, null);
+ /* cursor.execute("PRAGMA table_info(t1)")
+ name = cursor.fetchall()
+ print name
+ # [(0, u'f1', u'integer', 0, None, 0)]
+ cursor.execute("SELECT sql FROM sqlite_master WHERE tbl_name = 't1' and type = 'table'")
+ name = cursor.fetchall()
+ print name
+ # [(u'CREATE TABLE t1(f1 integer)',)] */
+ // cursor.execute("SELECT * FROM tiku");
+ let sql = "SELECT count(*) from sqlite_master where name = 'tiku' and sql like '%" + columnName + "%'";
+ toastLog
+ let cursor = db.rawQuery(sql, null);
+ cursor.moveToFirst();
+ var count = cursor.getLong(0);
+ // toastLog(count);
+ var isFind = false;
+ if (count > 0) {
+ isFind = true;
+ }
+ cursor.close();
+ db.close();
+ return isFind;
+}
+
+/**
+ * @description: 从数据库中搜索答案
+ * @param: question 问题
+ * @return: answer 答案
+ */
+function getAnswer(question, types) {
+ console.log("题目类型 :" + types);
+ var url = "https://api.myue.gq/xuexi/answer.php";
+ var res = http.post(url, {
+ "question": question,
+ "category": types,
+ "version": app.versionName
+ });
+ var res = res.body.json();
+ if (res.length != 0) {
+ console.verbose('Get Success');
+ return res[0].answer;
+ } else {
+ console.error("题库中未找到答案");
+ return '';
+ }
+}
+
+/**
+ * @description: 增加或更新数据库
+ * @param: sql
+ * @return: null
+ */
+function insertOrUpdate(sql) {
+ /* var dbName = "tiku.db";
+ var path = files.path(dbName);
+ if (!files.exists(path)) {
+ //files.createWithDirs(path);
+ console.error("未找到题库!请将题库放置与js同一目录下");
+ }
+ var db = SQLiteDatabase.openOrCreateDatabase(path, null);
+ // toastLog(sql);
+ db.execSQL(sql);
+ // db.commit();
+ db.close(); */
+}
+
+function searchTiku(keyw) {
+ //表名
+ var tableName = "tiku";
+ var ansArray = searchDb(keyw, tableName, "");
+ return ansArray;
+
+}
+
+function searchDb(keyw, _tableName, queryStr) {
+ var tableName = _tableName;
+ //数据文件名
+ var dbName = "tiku.db";
+ //文件路径
+ var path = files.path(dbName);
+ //确保文件存在
+ if (!files.exists(path)) {
+ files.createWithDirs(path);
+ }
+ //创建或打开数据库
+ var db = SQLiteDatabase.openOrCreateDatabase(path, null);
+ var query = "";
+ if (queryStr == "") {
+ query = "SELECT question,answer FROM " + tableName + " WHERE question LIKE '" + keyw + "%'"; //前缀匹配
+ } else {
+ query = queryStr;
+ }
+
+ log(query);
+ //query="select * from tiku"
+ //db.execSQL(query);
+
+ var cursor = db.rawQuery(query, null);
+ cursor.moveToFirst();
+ var ansTiku = [];
+ if (cursor.getCount() > 0) {
+ do {
+ var timuObj = {
+ "question": cursor.getString(0),
+ "answer": cursor.getString(1)
+ };
+ ansTiku.push(timuObj);
+ } while (cursor.moveToNext());
+ } else {
+ log("题库中未找到: " + keyw);
+ }
+ cursor.close();
+ db.close();
+ return ansTiku;
+
+}
+
+function countDb(keyw, _tableName, queryStr) {
+ var tableName = _tableName;
+ //数据文件名
+ var dbName = "tiku.db";
+ //文件路径
+ var path = files.path(dbName);
+ //确保文件存在
+ if (!files.exists(path)) {
+ files.createWithDirs(path);
+ }
+ //创建或打开数据库
+ var db = SQLiteDatabase.openOrCreateDatabase(path, null);
+ var query = "";
+ if (queryStr == "") {
+ query = "SELECT question,answer FROM " + tableName + " WHERE question LIKE '" + keyw + "%'"; //前缀匹配
+ } else {
+ query = queryStr;
+ }
+
+ // log(query);
+ query = "select * from tiku";
+ //db.execSQL(query);
+
+ var cursor = db.rawQuery(query, null);
+ cursor.moveToFirst();
+ let count = cursor.getLong(0);
+ /* var ansTiku = [];
+ if (cursor.getCount() > 0) {
+ do {
+ var timuObj={"question" : cursor.getString(0),"answer":cursor.getString(1)};
+ ansTiku.push(timuObj);
+ } while (cursor.moveToNext());
+ } else {
+ log("题库中未找到: " + keyw);
+ } */
+ cursor.close();
+ db.close();
+ // return ansTiku.length;
+ return count;
+}
+
+/**
+ * 查询数据库中的总条数.
+ * @return count
+ */
+function allCaseNum(tableName) {
+ let dbName = "tiku.db";
+ let path = files.path(dbName);
+ if (!files.exists(path)) {
+ files.createWithDirs(path);
+ }
+ let count = 0;
+ if (judge_tiku_existence()) {
+ let db = SQLiteDatabase.openOrCreateDatabase(path, null);
+ let sql = "select count(*) from " + tableName;
+ let cursor = db.rawQuery(sql, null);
+ cursor.moveToFirst();
+ count = cursor.getLong(0);
+ cursor.close();
+ db.close();
+ }
+ return count;
+}
+
+function executeSQL(sqlstr) {
+ //数据文件名
+ var dbName = "tiku.db";
+ //文件路径
+ var path = files.path(dbName);
+ //确保文件存在
+ if (!files.exists(path)) {
+ files.createWithDirs(path);
+ }
+ //创建或打开数据库
+ var db = SQLiteDatabase.openOrCreateDatabase(path, null);
+ db.execSQL(sqlstr);
+ toastLog(sqlstr);
+ db.close();
+}
+
+function searchNet(keyw) {
+ var tableName = "tikuNet";
+ var ansArray = searchDb(keyw, tableName, "");
+ return ansArray;
+}
+
+exports.judge_tiku_existence = judge_tiku_existence;
+exports.judge_tiku_columnName_existence = judge_tiku_columnName_existence;
+exports.getAnswer = getAnswer;
+exports.insertOrUpdate = insertOrUpdate;
+exports.searchTiku = searchTiku;
+exports.searchNet = searchNet;
+exports.searchDb = searchDb;
+exports.countDb = countDb;
+exports.allCaseNum = allCaseNum;
+exports.executeSQL = executeSQL;
\ No newline at end of file