Skip to content

Commit

Permalink
更新
Browse files Browse the repository at this point in the history
  • Loading branch information
e1399579 committed Aug 21, 2024
1 parent 1d9279b commit 6e08c5c
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 39 deletions.
45 changes: 32 additions & 13 deletions lib/OcrTool.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,49 @@
function OcrTool() {
this.img = null;
this.offset = [0, 0];

this.prepare = function() {
this.prepare = function(landscape) {
// 请求截图并点击开始
threads.start(function () {
let sel = packageName('com.android.systemui').text('立即开始');
let btn = sel.findOne(3000);
if (btn) btn.click();
});
if (!requestScreenCapture(false)) {
if (!requestScreenCapture(landscape)) {
throw new Error("请求截图失败");
}
sleep(500);
}

this.captureOrClip = function(rect) {
toastLog("截图");
let img = images.captureScreen();
this.img = rect ? images.clip(img, rect[0], rect[1], rect[2], rect[3]) : img;
}
this.capture = function() {
log("截图");
this.offset = [0, 0];
this.img = images.captureScreen();
return this.img;
};

this.clip = function(rect) {
log("裁剪");
this.offset = [rect[0], rect[1]];
return images.clip(this.img, rect[0], rect[1], rect[2], rect[3]);
};

this.captureAndClip = function(rect) {
this.capture();
return this.clip(rect);
};

this.setOffset = function(x, y) {
this.offset = [x, y];
};

this.getOffset = function() {
return this.offset;
};

this.findText = function(keywords) {
toastLog("OCR开始");
let list = ocr.detect(this.img);
toastLog("OCR结束");
this.img.recycle();
this.findText = function(img, keywords, recycle) {
let list = ocr.detect(img);
if (recycle) img.recycle();
let n = keywords.length;
let result = [];
let found = 0;
Expand All @@ -34,7 +53,7 @@ function OcrTool() {
if (obj.label.indexOf(keywords[i]) === -1) {
result[i] = [];
} else {
result[i] = [obj.bounds.left, obj.bounds.top];
result[i] = [obj.bounds.left + this.offset[0], obj.bounds.top + this.offset[1]];
++found;
}
}
Expand Down
6 changes: 3 additions & 3 deletions 京东签到.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ sleep(10000);

// 点击签到
let flag = false;
ocrTool.prepare();
ocrTool.prepare(false);
for (let i = 0;i < 3;i++) {
flag = false;
ocrTool.captureOrClip([0, 0, 1080, 520]);
let tpl = ocrTool.captureAndClip([0, 0, 1080, 900]);
let keywords = ["去登录", "明天", "赚更多京豆", "签到领豆"];
let result = ocrTool.findText(keywords);
let result = ocrTool.findText(tpl, keywords, true);
if (result[0].length > 0) {
robot.click(result[0][0], result[0][1]);
toastLog("点击登录");
Expand Down
25 changes: 2 additions & 23 deletions 支付宝签到.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
require("./解锁.js");
let Robot = require("./lib/Robot.js");
let WidgetAutomator = require("./lib/WidgetAutomator.js");
//let OcrTool = require("./lib/OcrTool.js");
let robot = new Robot();
let widget = new WidgetAutomator(robot);
//let ocrTool = new OcrTool();

toastLog("支付宝签到");
// 启动APP
widget.launchLikeName("支付宝", 5000);

// 关闭更新弹窗
if (id("update_cancel_tv").exists()) {
widget.clickCenterId("update_cancel_tv");
if (id("btn_close").exists()) {
widget.clickCenterId("btn_close");
sleep(1000);
}

Expand All @@ -25,25 +23,6 @@ widget.clickCenterClass("android.view.ViewGroup");
sleep(8000);

let keywords = ["每日签到", "全部领取"];
// 使用OCR识别文字
/*ocrTool.prepare();
ocrTool.captureOrClip([0, 0, 1080, 1200]);
let result = ocrTool.findText(keywords);
if (result[1].length > 0) {
robot.click(result[1][0], result[1][1]);
toastLog("全部领取");
sleep(1000);
}
if (result[0].length > 0) {
robot.click(result[0][0], result[0][1]);
toastLog("签到成功");
sleep(3000);
} else {
toastLog("签到失败");
log(selector().visibleToUser(true).find().toList());
}
*/
// 使用控件点击
if (text(keywords[1]).exists()) {
widget.clickCenterText(keywords[1]);
Expand Down

0 comments on commit 6e08c5c

Please sign in to comment.