下载地址:https://www.pan38.com/share.php?code=frdRj
声明:仅用于学习参考用
Auto.js脚本会持续检测界面中的价格和距离信息,当价格低于100元且距离小于5公里时自动右滑。需要根据实际界面元素调整id选择器和正则表达式。使用时请确保已开启无障碍服务。
// Auto.js脚本:检测价格和距离,符合条件则右滑
auto.waitFor();
// 主循环
while(true) {
// 获取当前界面文本内容
let text = id("content").findOne(2000);
if (!text) {
console.log("未找到内容");
continue;
}
// 提取价格和距离信息(根据实际界面调整正则)
let priceMatch = text.text().match(/¥(\d+)/);
let distanceMatch = text.text().match(/(\d+)km/);
if (priceMatch && distanceMatch) {
let price = parseInt(priceMatch[1]);
let distance = parseInt(distanceMatch[1]);
console.log("当前价格:", price, "距离:", distance);
// 判断条件:价格低于100且距离小于5km
if (price < 100 && distance < 5) {
console.log("符合条件,执行右滑");
// 右滑操作(根据实际界面调整坐标)
swipe(device.width * 0.8, device.height / 2,
device.width * 0.2, device.height / 2, 500);
sleep(2000); // 滑动后等待
}
}
sleep(3000); // 每次检测间隔
}
无障碍部分模块:
function checkAccessibility() {
let am = context.getSystemService(android.content.Context.ACCESSIBILITY_SERVICE);
return am.isEnabled();
}
console.log("无障碍服务状态:" + checkAccessibility());
// 方法2:检测特定包名的无障碍服务
function isMyAccessibilityEnabled() {
let am = context.getSystemService(android.content.Context.ACCESSIBILITY_SERVICE);
let services = am.getEnabledAccessibilityServiceList(
android.accessibilityservice.AccessibilityServiceInfo.FEEDBACK_GENERIC
);
for(let i=0; i if(services.get(i).getId().includes(context.getPackageName())) { return true; } } return false; } console.log("本应用无障碍服务状态:" + isMyAccessibilityEnabled()); 价格判断以及UI部分: "ui"; // 主界面布局 ui.layout( ); // 变量定义 let running = false; let detectionThread = null; // 开始按钮事件 ui.btnStart.on("click", function(){ if(!auto.service){ toast("请先开启无障碍服务"); return; } running = true; ui.btnStart.enabled = false; ui.btnStop.enabled = true; detectionThread = threads.start(function(){ while(running){ detectAndProcess(); sleep(3000); } }); }); // 停止按钮事件 ui.btnStop.on("click", function(){ running = false; if(detectionThread) detectionThread.interrupt(); ui.btnStart.enabled = true; ui.btnStop.enabled = false; }); // 价格检测处理函数 function detectAndProcess(){ let priceElem = id("price").findOne(2000); let distanceElem = id("distance").findOne(2000); if(priceElem && distanceElem){ let currentPrice = parseFloat(priceElem.text().replace(/[^\d.]/g, "")); let currentDist = parseFloat(distanceElem.text().match(/\d+/)[0]); ui.run(() => { ui.currentPrice.text = currentPrice + "元"; ui.currentPrice.textColor = currentPrice < ui.targetPrice.text ? "#4CAF50" : "#F44336"; }); if(ui.chkToast.checked){ toast("当前价格: " + currentPrice + "元, 距离: " + currentDist + "km"); } // 条件判断 if(currentPrice <= ui.targetPrice.text && currentDist <= ui.swipeDistance.text && ui.chkAutoSwipe.checked){ swipeRight(); } } } // 右滑操作 function swipeRight(){ let width = device.width; let height = device.height; swipe(width * 0.8, height / 2, width * 0.2, height / 2, 500); }