-
Notifications
You must be signed in to change notification settings - Fork 13
/
main.js
181 lines (170 loc) · 5.01 KB
/
main.js
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
//新版基础函数
var f = {
init:function() {
log("程序初始化")
},
//post
post : function(url,data){
var res = http.post(url, data);
var data = res.body.string();
if(data){
// log(data);
return data;
}
},
//get
get : function(url){
var res = http.get(url);
var data = res.body.string();
if(data){
return data;
}
},
//读取本地数据
getLocal:function ( name, key) {
const storage = storages.create(name); //创建storage对象
if (storage.contains(key)) {
return storage.get(key);
};
//默认返回undefined
},
//基础函数
active:function(pkg,n){
if(!n){n=5}
if( currentPackage() == pkg ){
log("应用在前端");
return true;
}else{
log("启动一次应用");
app.launch(pkg);
sleep(1000)
f.ms({"textMatches":"允许|始终允许"},true)
sleep(1000*n)
}
},
//准备点击
click:function (x,y,sleeptime,name){
if ( ! sleeptime ){sleeptime = 1}
if ( name ){
log('准备点击->'+name,"x:",x,"y:",y);
}else{
log('准备点击坐标->', "x:",x,"y:",y);
}
if( x > 0 && y > 0 ){
threads.start(function(){
//在新线程执行的代码
click(x,y);
});
// click(x,y);
sleep(sleeptime*1000);
return true
}else{
log('坐标错误');
}
},
//点击obj
clickObj:function (obj,sleeptime,name){
if ( ! sleeptime ){ sleeptime == 1 }
log( name ? ("准备点击对象->" + name) : "点击未命名对象" )
x = obj.bounds().centerX()
y = obj.bounds().centerY()
return f.click(x,y,sleeptime,name)
},
//穿透点击
clickTrue:function(obj,sleeptime,name,lun){
sleeptime ? sleeptime : 1
let result = false;
lun ? lun : 3
for (let i=0;i<lun;i++){
if ( obj && obj.clickable() ){
obj.click();
log( name ? ("准备穿透点击对象->" + name) : "准备穿透点击未命名对象" )
result = true
break
}
obj = obj.parent()
}
if ( result ) { sleep(sleeptime * 1000) }
return result
},
//正则点击
ms:function (obj,clicks,sleeptimes,name,findtime,lun){
if (!sleeptimes) { sleeptimes = 1}
if (!findtime) { findtime = 200}
if (!lun) { lun = 3}
var txt = '';
for(let key in obj){
if ( key.search("Matches") > 0 ){
eval("var matches = /" + obj[key] + "/")
txt = txt + key+'('+matches+').'
}else if( key == 'boundsInside' ){
txt = txt + key+'('+obj[key]+').'
}else{
txt = txt + key+'("'+obj[key]+'").'
}
}
var txt = "let objs = "+txt+"findOne("+findtime+");"
log(txt)
eval(txt)
if ( objs ) {
log( '找到==>' + objs.text() || objs.desc() || objs.id() || objs.className() )
if ( clicks ){
name = obj['textMatches'] || obj['descMatches'] || obj['idMatches'] || obj['text'] || obj['desc'] || obj['id']
if (lun < 1 || !f.clickTrue( objs,sleeptimes,name,lun )){
log('准备坐标点击')
return f.clickObj( objs,sleeptimes,name );
}
}
return true;
}
},
rd:function (min,max){
if (min<=max){
return random(min,max)
}else{
return random(max,min)
}
},
moveTo:function (x,y,x1,y1,times){
swipe(x,y,x1,y1,times);
sleep(1000);
}
}
f.init()
//批查打印app参数
function printAll( ways ) {
if (!ways){
ways = 'className'
}
if (ways = 'className'){
var all_Info = classNameMatches(/.*/).find();
}else
if (ways == 'text'){
var all_Info = textMatches(/.*/).find();
}else
if (ways == 'id'){
var all_Info = idMatches(/.*/).find();
}else{
eval( 'var all_Info = ' + ways + '.find();' )
}
if ( all_Info ){
for (var i = 0;i<all_Info.length;i++){
var d = all_Info[i];
log(i,d.id(),d.text(),"desc:"+d.desc(),'"className":"'+d.className()+'"',
"clickable->"+d.clickable(),'selected->'+selected(),"depth->"+d.depth(),
d.bounds().centerX(),d.bounds().centerY())
}
}else{
log('没有找到任何相关的节点')
}
}
// printAll()
f.ms({"desc":"搜索,按钮"},true,3)
setText(0,"878608426")
f.ms({"desc":"搜索"},true,3)
f.ms({"textMatches":"直播中.*"},true,3)
//在直播间
f.ms({"id":"b++"})
f.ms({"desc":"商品"},true,5)
f.ms({"textMatches":"说点什么..."},true,3)
f.ms({"desc":"发送"},true,3)