封装大世界
```
****** textClick("换现金", false, 1500) 用法
function textClick(parameter, status, time) {
let resultObject = textMatches(parameter).visibleToUser(true).findOnce()
if (resultObject) {
if (status) {
if (无指针点击(parameter, resultObject, time)) {
return true
}
} else {
if (有指针点击(parameter, resultObject, time)) {
return true
}
}
}
return false
}
```
```
******** 有指针点击("关闭广告", guanBi, 2000) 用法
function 无指针点击(提示语, 控件, 延时) {
if (!延时) {
延时 = 1000;
}
for (let i = 0; i < 5; i++) {
if (控件) {
if (控件.click()) {
log("[父" + i + "成功]控件点击:" + 提示语);
sleep(延时);
return true;
}
控件 = 控件.parent();
} else {
return false;
}
}
log("[失败]控件点击:" + 提示语);
}
```
```
******** 有指针点击("关闭广告", guanBi, 2000) 用法
function 有指针点击(nodeName, node, sleepTime) {
if (!sleepTime) {
sleepTime = 1000;
}
if (node) {
try {
if (click(node.bounds().centerX(), node.bounds().centerY())) {
sleep(sleepTime);
log("[成功]指针点击:" + nodeName);
return true;
} else {
log("[失败]指针点击:" + nodeName);
}
} catch (e) {
log("[失败]指针点击" + nodeName + "失败:" + e);
}
}
return false;
}
```
## 随机坐标点击
```
let 关闭 = idMatches(/.+dza/).visibleToUser(true).findOne()
if (关闭) {
randomClick(关闭)
log("关闭成功")
}
function randomClick(canShu) {
let bound = canShu.bounds()
let randX = bound.left + random(1, bound.right - bound.left)
let randY = bound.top + random(1, bound.bottom - bound.top)
// log(randX, randY)
click(randX, randY)
}
```
## #控件 文本 id 点击等...
```
控件点击(idMatches, /.+dza/, "点赞")
// 控件点击(textMatches, /我/, "我")
// 控件点击(idMatches, /我/, "我")
function 控件点击(canshu, canshu1, canshu2) {
try {
var a = canshu(canshu1).boundsInside(0, 0, device.width, device.height).findOnce();
if (a != null) {
if (a.clickable()) {
a.click();
} else {
var bounds = a.bounds();
var x1 = bounds.left;
var x2 = bounds.right;
var y1 = bounds.top;
var y2 = bounds.bottom;
var x = random(x1 + 1, x2 - 1);
var y = random(y1 + 1, y2 - 1);
var timedelay = random(50, 150);
press(x, y, timedelay);
}
log("点击[" + canshu2 + "]成功");
sleep(2000);
return true;
}
} catch (error) {
log(error);
}
return false;
}
```
## 点击函数
```
let 点赞 = idMatches(/.+dza/).visibleToUser(true).findOnce()
if (点赞) {
real_click("点赞", 点赞, 1000)
}
function real_click(提示语, 控件, 延时) {
if (控件) {
if (click(控件.bounds().centerX(), 控件.bounds().centerY())) {
// sleep(延时)
log("[成功]指针点击:" + 提示语)
sleep(1000)
return true
}
}
for (let i = 1; i <= 5; i++) {
if (控件) {
// console.warn("控件无法正常点击:");
// log("尝试再次点击");
if (控件.click()) {
log("[" + i + "成功]控件点击:" + 提示语)
sleep(延时)
return true
}
// 控件 = 控件.parent()
// sleep(300);
} else {
return true
}
sleep(800)
}
return false;
}
```
## 手机关闭应用(1)--->慢
```
exit_app("快手")//应用名字
function exit_app(name) {
var packageName = getPackageName(name);
if (!packageName) {
if (getAppName(name)) {
packageName = name;
} else {
return false;
}
}
log("打开应用设置界面");
app.openAppSetting(packageName);
var appName = app.getAppName(packageName);
log("等待加载界面")
// text(appName).findOne(5000);
sleep(1000);
log("查找结束按钮")
let stop = textMatches(/(强.停止$|.*停止$|结束运行|停止运行|[Ff][Oo][Rr][Cc][Ee] [Ss][Tt][Oo][Pp])/).findOne();
log("stop:", stop.enabled())
if (stop.enabled()) {
real_click("", stop, 1000);
// sleep(1000);
log("等待确认弹框")
let sure = textMatches(/(确定|.*停止.*|[Ff][Oo][Rr][Cc][Ee] [Ss][Tt][Oo][Pp]|O[Kk])/).clickable().findOne(1500);
if (!sure) {
fInfo(appName + "应用已关闭");
back();
return false;
}
log("sure click:", sure.click());
sleep(1000);
back();
} else {
// fInfo(appName + "应用不能被正常关闭或不在后台运行");
sleep(1000);
back();
}
return true;
}
```
## 手机关闭应用(1)--->快
```
关闭应用('百度极速版')
关闭应用("com.smile.gifmaker");
function 关闭应用(packageName) {
// let packageName = currentPackage(); //参数app名字
// var packageName = getPackageName(name);
// if (!packageName) {
// if (getAppName(name)) {
// packageName = name;
// } else {
// return false;
// }
// }
app.openAppSetting(packageName);
text(app.getAppName(packageName)).waitFor();
let is_sure = textMatches(/(.*强.*|.*停.*|.*结.*|.*行.*)/).findOne();
if (is_sure.enabled()) {
textMatches(/(.*强.*|.*停.*|.*结.*|.*行.*)/).findOne().click();
sleep(1200)
textMatches(/(.*确.*|.*定.*)/).findOne().click();
log(app.getAppName(packageName) + "应用已被关闭");
sleep(1000);
back();
} else {
log(app.getAppName(packageName) + "应用不能被正常关闭或不在后台运行");
back();
}
}
```
## 随机滑动
```
for (let i = 0; i < 500; i++) {
MaintenanceAccount(i)
// log("评论的逻辑")
}
function MaintenanceAccount(i) {
let time = random(5000, 8000);//设置滑动延迟时间
toastLog("第" + (i + 1) + "个视频,请等待" + time / 1000 + "秒");
sleep(time);
//开始滑动视频
let x1 = random(device.width / 4, (device.width / 4) * 3);
let y1 = random((device.height / 4) * 3.1, (device.height / 4) * 3.3);
let x2 = random(device.width / 4, (device.width / 4) * 3);
let y2 = random((device.height / 4) * 0.7, (device.height / 4) * 0.5);
let s = random(100, 150);//设置滑动时长
// RandomSwipe(x1, y1, x2, y2, s);//向上滑
// RandomSwipe(x2, y2, x1, y1, s);//向下滑
}
function RandomSwipe(qx, qy, zx, zy, time) {
var xxy = [time];
var point = [];
var dx0 = {
"x": qx,
"y": qy
};
var dx1 = {
"x": random(qx - (device.width / 4) * 0.25, qx + (device.width / 4) * 0.25),
"y": random(qy, qy + 50),
}
var dx2 = {
"x": random(zx - (device.width / 4) * 0.25, zx + (device.width / 4) * 0.25),
"y": random(zy, zy + 50)
};
var dx3 = {
"x": zx,
"y": zy
};
for (let i = 0; i < 4; i++) {
eval("point.push(dx" + i + ")");
}
for (let i = 0; i < 1; i += 0.08) {
xxyy = [parseInt(bezier_curves(point, i).x), parseInt(bezier_curves(point, i).y)]
xxy.push(xxyy)
}
gesture.apply(null, xxy)
}
function bezier_curves(cp, t) {
cx = 3.0 * (cp[1].x - cp[0].x);
bx = 3.0 * (cp[2].x - cp[1].x) - cx;
ax = cp[3].x - cp[0].x - cx - bx;
cy = 3.0 * (cp[1].y - cp[0].y);
by = 3.0 * (cp[2].y - cp[1].y) - cy;
ay = cp[3].y - cp[0].y - cy - by;
tSquared = t * t;
tCubed = tSquared * t;
result = {
"x": 0,
"y": 0
}
result.x = (ax * tCubed) + (bx * tSquared) + (cx * t) + cp[0].x;
result.y = (ay * tCubed) + (by * tSquared) + (cy * t) + cp[0].y;
return result;
}
```
### 申请root 权限
```
let uiPkg = context.getPackageName();
let cmd = "enabled=$(settings get secure enabled_accessibility_services)\n" +
"pkg=" + uiPkg + "/com.stardust.autojs.core.accessibility.AccessibilityService\n" +
"if [[ \$enabled == *\$pkg* ]]\n" +
"then\n" +
"echo already_enabled\n" +
"else\n" +
"enabled=\$pkg:\$enabled\n" +
"settings put secure enabled_accessibility_services \$enabled\n" +
"fi";
try {
$shell(cmd, true);
} catch (error) {
toastLog("没有root权限");
}
sleep(2000)
KeyCode(66)//回车
```