Skip to content

Commit 6e08c5c

Browse files
committed
更新
1 parent 1d9279b commit 6e08c5c

File tree

3 files changed

+37
-39
lines changed

3 files changed

+37
-39
lines changed

lib/OcrTool.js

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,49 @@
11
function OcrTool() {
22
this.img = null;
3+
this.offset = [0, 0];
34

4-
this.prepare = function() {
5+
this.prepare = function(landscape) {
56
// 请求截图并点击开始
67
threads.start(function () {
78
let sel = packageName('com.android.systemui').text('立即开始');
89
let btn = sel.findOne(3000);
910
if (btn) btn.click();
1011
});
11-
if (!requestScreenCapture(false)) {
12+
if (!requestScreenCapture(landscape)) {
1213
throw new Error("请求截图失败");
1314
}
1415
sleep(500);
1516
}
1617

17-
this.captureOrClip = function(rect) {
18-
toastLog("截图");
19-
let img = images.captureScreen();
20-
this.img = rect ? images.clip(img, rect[0], rect[1], rect[2], rect[3]) : img;
21-
}
18+
this.capture = function() {
19+
log("截图");
20+
this.offset = [0, 0];
21+
this.img = images.captureScreen();
22+
return this.img;
23+
};
24+
25+
this.clip = function(rect) {
26+
log("裁剪");
27+
this.offset = [rect[0], rect[1]];
28+
return images.clip(this.img, rect[0], rect[1], rect[2], rect[3]);
29+
};
30+
31+
this.captureAndClip = function(rect) {
32+
this.capture();
33+
return this.clip(rect);
34+
};
35+
36+
this.setOffset = function(x, y) {
37+
this.offset = [x, y];
38+
};
39+
40+
this.getOffset = function() {
41+
return this.offset;
42+
};
2243

23-
this.findText = function(keywords) {
24-
toastLog("OCR开始");
25-
let list = ocr.detect(this.img);
26-
toastLog("OCR结束");
27-
this.img.recycle();
44+
this.findText = function(img, keywords, recycle) {
45+
let list = ocr.detect(img);
46+
if (recycle) img.recycle();
2847
let n = keywords.length;
2948
let result = [];
3049
let found = 0;
@@ -34,7 +53,7 @@ function OcrTool() {
3453
if (obj.label.indexOf(keywords[i]) === -1) {
3554
result[i] = [];
3655
} else {
37-
result[i] = [obj.bounds.left, obj.bounds.top];
56+
result[i] = [obj.bounds.left + this.offset[0], obj.bounds.top + this.offset[1]];
3857
++found;
3958
}
4059
}

京东签到.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ sleep(10000);
2525

2626
// 点击签到
2727
let flag = false;
28-
ocrTool.prepare();
28+
ocrTool.prepare(false);
2929
for (let i = 0;i < 3;i++) {
3030
flag = false;
31-
ocrTool.captureOrClip([0, 0, 1080, 520]);
31+
let tpl = ocrTool.captureAndClip([0, 0, 1080, 900]);
3232
let keywords = ["去登录", "明天", "赚更多京豆", "签到领豆"];
33-
let result = ocrTool.findText(keywords);
33+
let result = ocrTool.findText(tpl, keywords, true);
3434
if (result[0].length > 0) {
3535
robot.click(result[0][0], result[0][1]);
3636
toastLog("点击登录");

支付宝签到.js

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
11
require("./解锁.js");
22
let Robot = require("./lib/Robot.js");
33
let WidgetAutomator = require("./lib/WidgetAutomator.js");
4-
//let OcrTool = require("./lib/OcrTool.js");
54
let robot = new Robot();
65
let widget = new WidgetAutomator(robot);
7-
//let ocrTool = new OcrTool();
86

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

1311
// 关闭更新弹窗
14-
if (id("update_cancel_tv").exists()) {
15-
widget.clickCenterId("update_cancel_tv");
12+
if (id("btn_close").exists()) {
13+
widget.clickCenterId("btn_close");
1614
sleep(1000);
1715
}
1816

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

2725
let keywords = ["每日签到", "全部领取"];
28-
// 使用OCR识别文字
29-
/*ocrTool.prepare();
30-
ocrTool.captureOrClip([0, 0, 1080, 1200]);
31-
let result = ocrTool.findText(keywords);
32-
if (result[1].length > 0) {
33-
robot.click(result[1][0], result[1][1]);
34-
toastLog("全部领取");
35-
sleep(1000);
36-
}
37-
if (result[0].length > 0) {
38-
robot.click(result[0][0], result[0][1]);
39-
toastLog("签到成功");
40-
sleep(3000);
41-
} else {
42-
toastLog("签到失败");
43-
log(selector().visibleToUser(true).find().toList());
44-
45-
}
46-
*/
4726
// 使用控件点击
4827
if (text(keywords[1]).exists()) {
4928
widget.clickCenterText(keywords[1]);

0 commit comments

Comments
 (0)