forked from maxwellyue/autojs_script
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommon.js
More file actions
137 lines (120 loc) · 2.82 KB
/
common.js
File metadata and controls
137 lines (120 loc) · 2.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
var util = {};
//唤醒主屏幕
util.wakeUp = function(){
if(!device.isScreenOn()){
device.wakeUpIfNeeded();
}
}
//打开APP
util.launch = function(appName) {
//打开应用
app.launchApp(appName);
//如果存在提示,则点击允许
var loop = 0;
while(loop < 5){
loop++;
util.UITextClick("允许");
}
//设置屏幕缩放
setScreenMetrics(1080, 1920);
sleep(15000);
};
//通过坐标点击
util.boundsClick = function(item) {
var bounds = item.bounds();
click(bounds.centerX(),bounds.centerY());
sleep(1000);
}
//通过UI点击
util.UIClick = function(eleId) {
var uiele = id(eleId).findOnce();
if(uiele){
uiele.click();
}
sleep(1000);
}
util.idClick = function(eleId) {
var uiele = id(eleId).findOnce();
var flag = false;
if(uiele){
uiele.click();
flag = true;
}
sleep(1000);
return flag;
}
//通过UI文本点击
util.UITextClick = function(textContent) {
var uiele = text(textContent).findOnce();
if(uiele){
uiele.click();
}
sleep(1000);
}
util.textClick = function(textContent) {
var uiele = text(textContent).findOnce();
var flag = false;
if(uiele){
uiele.click();
flag = true;
}
sleep(1000);
return flag;
}
//通过UI文本的坐标点击
util.UITextBoundsClick = function(textContent) {
var thisEle = text(textContent).findOnce();
var flag = false;
if (thisEle) {
util.boundsClick(thisEle);
flag = true;
}
sleep(1000);
return flag;
}
util.textBoundsClick = function(textContent) {
var thisEle = text(textContent).findOnce();
var flag = false;
if (thisEle) {
util.boundsClick(thisEle);
flag = true;
}
sleep(1000);
return flag;
}
//通过UI点击
util.backToIndex = function(indexFlagText) {
var indexBtn = false;
var loop = 0;
while(!indexBtn){
back();
sleep(1000);
indexBtn = text(indexFlagText).findOnce();
//超出退出时长的,做一些特殊处理
if(loop > 5){
//无限返回的页面
var isSucc = util.textClick("关闭");
if(!isSucc){
util.textBoundsClick("关闭");
}
//系统的安装页面
if(!isSucc){
util.UITextClick("取消");
}
//成功关闭
if(isSucc){
indexBtn = true;
}
}
loop++;
}
}
//滑动阅读新闻
util.swapeToRead = function() {
//滑动阅读新闻
swipe(device.width / 2, device.height * 0.8 ,
device.width / 2, device.height * 0.5, 5000);
swipe(device.width / 2, device.height * 0.8 ,
device.width / 2, device.height * 0.5, 5000);
}
module.exports = util;