Auto.js零散例子

飞行模式切换IP

function 打开飞行模式() {
  // 打开飞行模式
  new Shell().exec("su -c 'settings put global airplane_mode_on 1; am broadcast -a android.intent.action.AIRPLANE_MODE --ez state true'")
};

function 关闭飞行模式() {
  //关闭飞行模式
  new Shell().exec("su -c 'settings put global airplane_mode_on 0; am broadcast -a android.intent.action.AIRPLANE_MODE --ez state false'")
};

点击指定区域

while (true) {
 click(500, 380);
}
//或者用
for (var i = 0; i < 7; i++) {
    click(500, 380);
}

自动打开网址

"Auto"
app.openUrl("http://chapai.act.qq.com/ph2");

微信轰炸机


"auto";
//进入短信发送信息界面,自动进行轰炸
//自行更改需要发送的内容
//土豪专用轰炸机
launchApp("短信");

waitForPackage("com.android.mms");
toast("轰炸机已准备");

while(true){
    
    setText("你好世界!");
id("send_button").click();

}

防检测按键脚本(范围选点)

random(X,Y)是数值区间,
调出手机指针位置后可以找出适合的区间
脚本例子:

"auto";
launchApp("appname")
sleep(1000)
click(random(60, 1000), random(60, 1660))
sleep(500);
click(random(60, 1000), random(60, 1660))
sleep(500);
click(random(870, 1030), random(130, 400))

无限每隔10毫秒点击手机屏幕任意位置

auto();
console.show();
console.info("按音量上键开始,按音量下键结束");
events.observeKey();
//按音量上键结束
events.onKeyDown("volume_down", function(event){
    threads.shutDownAll();
console.info("已结束");
exit();
});

events.onKeyDown("volume_up", function(event){
    threads.start(function(){
    //无限每隔10ms点击屏幕任意位置一次
while(true){
    var x = random(0, device.width);
var y = random(0, device.height);
click(x, y);
console.log("(%d, %d)", x, y);
sleep(1000);
}
});
});

屏幕解锁

sleep(5000)//设定时间
//////////唤醒手机///////////

/*判断屏幕锁定,解锁屏幕(数字密码)*/

if (!device.isScreenOn()) {//息屏状态将屏幕唤醒
    
    device.wakeUp();//唤醒设备

sleep(1000); // 等待屏幕亮起

//miui锁屏滑动不能唤出密码输入 通过下拉通知栏点击时间进入密码解锁

swipe(500, 30, 500, 1000, 300);

sleep(400);

//点击时间

click(100, 120);

//解锁 密码1234

desc(1).findOne().click();

desc(2).findOne().click();

desc(3).findOne().click();

desc(4).findOne().click();

//等待解锁完成,返回并退出

back();
exit()
}


抖音弹窗处理

//监听弹窗事件(异常处理)
threads.start(function(){
    while(true){
        sleep(1200);
        if(text('发现通讯录好友').exists()){
            text('取消').click();
        };
    };
    });

百度手机分辨率

log("脚本有时测得分辨率不对 导致用户无法使用 可以用此方法");
var 正确的分辨率高=百度手机分辨率();


function 百度手机分辨率(){
    var fblheight;
    var mmm2="https://www.so.com/s?q="+device.device+"+分辨率";
    thread1=threads.start(function(){  
        log("百度手机分辨率 开始");
        try {
            var res = http.get(mmm2);
            if(res.statusCode == 200){
                log("网页打开成功...");
                var httpstr = res.body.string();
                var sousuostr="x"+device.width;
                var index = httpstr.indexOf(sousuostr);
                if(index>0){
                    fblheight = parseInt(httpstr.substring(index-4,index));
                    log("百度成功 分辨率高为:"+fblheight);
                }else{
                    fblheight="百度失败";
                    log("没有检索到分辨率信息");
                }
            }
        } catch (error) {
            log("百度手机分辨率 异常!!!");
            fblheight="查找异常";
        }
        log("百度手机分辨率 结束");
    });
    thread1.join(2000);
    thread1.interrupt();
    return fblheight;
}

log("正确的分辨率高:"+正确的分辨率高);
log("脚本测得分辨率高:"+device.height);


禁止脚本多次运行

/*
 * Author:TimeOut
 * Date: 2018.12.18
 */
 
 //获取当前所运行的脚本
var list = engines.all();
//双循环比较
for (var i = 0; i < list.length; i++) {
    for (var j = i + 1; j < list.length; j++) {
       //比较是否只有一个运行
        if (list[i].getSource().toString() == list[j].getSource().toString()) {
            //停止二次运行的脚本
            list[j].forceStop();
        };
    };
};

[Http代理] 讯代理动态转发示例

/** 
 * 使用时传入url和端口即可 
 * 例如: httpProxy("forward.xdaili.cn", 80);
 *   此函数生效后,在此函数后的所有 Http 请求都会通过该代理去完成
 *  @param {string} url 
 *  @param {int} prot 
 * */
 function httpProxy(url, prot) {
    var Proxy = java.net.Proxy;
    var InetSocketAddress = java.net.InetSocketAddress;
    var okhttp = new Packages.okhttp3.OkHttpClient.Builder().proxy(new Proxy(Proxy.Type.HTTP, new InetSocketAddress(url, prot)));
    http.__okhttp__.muteClient(okhttp);
}
/** 
 * 以下是讯代理的 动态转发 请求示例 
 * 讯代理官方网站: http://www.xdaili.cn 
 * 20元 10万次 请求 
 * */
 var orderNo = ""; //动态转发的订单号 
var secret = ""; //讯代理的secret,个人中心查看 
var getMd5 = http.get('https://script.iqqclub.com/md5.js');
eval(getMd5.body.string());
httpProxy("forward.xdaili.cn", 80);
var html = http.get("http://www.diaoyu.com", getHeaders());
log(html.body.string());
function getHeaders() {
    var timestamp = Math.round(new Date() / 1000);
    var planText = "orderno=" + orderNo + ",secret=" + secret + ",timestamp=" + timestamp;
    var sign = hex_md5(planText).toLocaleUpperCase(); //将拼接的字符串MD5后,转换成大写 
    var header = {
        headers: { 'Proxy-Authorization': 'sign=' + sign + '&orderno=' + orderNo + '×tamp=' + timestamp, }
    };
    return header;
}

[Http代理]讯代理优质代理示例

/** * 讯代理 优质代理 示例 * 
 * 不支持多线程获取 * 
 * 脚本中的订单 有效日期截止到: 2018-10-15 15:28 过期后将不可用 * 
 * 讯代理官方网站: http://www.xdaili.cn
 * */
 var spiderId = "7ab204de5b7e403caada6398f29c2831"; //spiderId 
var orderNo = "YZ20188145457DGCJTP"; //订单号 
var getIp_api = http.get('http://pv.sohu.com/cityjson?ie=utf-8');
var InetIP = getIp_api.body.string();
eval(InetIP);
log("使用代理前的外网IP:" + returnCitySN.cip);
var xdailiUrl = "http://api.xdaili.cn/xdaili-api//greatRecharge/getGreatIp?spiderId=" + spiderId + "&orderno=" + orderNo + "&returnType=2&count=1";
for (let i = 0; i < 3; i++) {
    try {
        var getProxy_json = http.get(xdailiUrl).body.json();
        if (getProxy_json.ERRORCODE == "10036" || getProxy_json.ERRORCODE == "10038" || getProxy_json.ERRORCODE == "10055") {
            throw {
                "code": "-1",
                "msg": "提取速度过快"
            }
        }
        if (getProxy_json.ERRORCODE == "10036") {
            throw {
                "code": "-2",
                "msg": "提取次数已达上限"
            }
        }
        break;
    } catch (e) {
        if (e.code == "-1") {
            log(e.msg);
            sleep(5000);
        }
        if (e.code == "-2") {
            log(e.msg);
            exit();
        }
        if (i == 2) { //运行3次后,没有拿到IP和端口 程序结束 log("发生了未知错误,请检查网络..."); 
            exit();
        }
    }
}
//log(getProxy_json); 
var xdaili_proxyIP = getProxy_json.RESULT[0].ip;
var xdaili_proxyPort = parseInt(getProxy_json.RESULT[0].port); //log(xdaili_proxyIP+":"+xdaili_proxyPort); 
httpProxy(xdaili_proxyIP, xdaili_proxyPort);
var getIp_api = http.get('http://pv.sohu.com/cityjson?ie=utf-8');
var InetIP = getIp_api.body.string();
eval(InetIP);
log("使用代理后的外网IP:" + returnCitySN.cip);
function httpProxy(url, prot) {
    var Proxy = java.net.Proxy;
    var InetSocketAddress = java.net.InetSocketAddress;
    var okhttp = new Packages.okhttp3.OkHttpClient.Builder().proxy(new Proxy(Proxy.Type.HTTP, new InetSocketAddress(url, prot)));
    http.__okhttp__.muteClient(okhttp);
}

获取指定应用的版本号

/*
* 获取指定应用的版本号
* @param {string} packageName 应用包名
*/
function getPackageVersion(packageName) {
    importPackage(android.content);
    var pckMan = context.getPackageManager();
    var packageInfo = pckMan.getPackageInfo(packageName, 0);
    return packageInfo.versionName;
};

停止APP

// 停止APP
function killApp(packageName) {
    shell('am force-stop ' + packageName, true);
};

卸载APP

// 卸载APP
function uninstallApp(packageName) {
    shell("pm uninstall " + packageName, true)
};

清除App数据

// 清除App数据
function clearApp(packageName) {
    shell('pm clear ' + packageName, true);
};

卸载最新安装的app

// 卸载最新安装的app
function uninstallAppLast() {
    var pm = context.getPackageManager()
    var appList = pm.getInstalledApplications(0)
    var appInfoList = []
    for (let i = 0; i < appList.size(); i++) {
        var app = appList.get(i)
        var appInfo = {
            appName: app.loadLabel(pm),
            packageName: app.packageName,
            isSystemApp: app.isSystemApp(),
            firstInstallTime: pm.getPackageInfo(app.packageName, 0).firstInstallTime
        }
        appInfoList.push(appInfo)
        
    }
    appInfoList.sort((a, b) => {
        return b.firstInstallTime - a.firstInstallTime
    })
    log('最新安装的app是=%j', appInfoList[0])
    
    var packageName = appInfoList[0].packageName
    shell("pm uninstall " + packageName, true)
    return appInfoList[0].appName
};

清除最新安装的APP数据

// 清除最新安装的APP数据
function clearAppLast() {
    var pm = context.getPackageManager()
    var appList = pm.getInstalledApplications(0)
    var appInfoList = []
    for (let i = 0; i < appList.size(); i++) {
        var app = appList.get(i)
        var appInfo = {
            appName: app.loadLabel(pm),
            packageName: app.packageName,
            isSystemApp: app.isSystemApp(),
            firstInstallTime: pm.getPackageInfo(app.packageName, 0).firstInstallTime
        }
        appInfoList.push(appInfo)
        
    }
    appInfoList.sort((a, b) => {
        return b.firstInstallTime - a.firstInstallTime
    })
    log('最新安装的app是=%j', appInfoList[0])
    
    var packageName = appInfoList[0].packageName
    shell('pm clear ' + packageName, true);
    return appInfoList[0].appName
};

停止最新安装的APP

// 停止最新安装的APP
function killAppLast {
    var pm = context.getPackageManager()
    var appList = pm.getInstalledApplications(0)
    var appInfoList = []
    for (let i = 0; i < appList.size(); i++) {
        var app = appList.get(i)
        var appInfo = {
            appName: app.loadLabel(pm),
            packageName: app.packageName,
            isSystemApp: app.isSystemApp(),
            firstInstallTime: pm.getPackageInfo(app.packageName, 0).firstInstallTime
        }
        appInfoList.push(appInfo)
        
    }
    appInfoList.sort((a, b) => {
        return b.firstInstallTime - a.firstInstallTime
    })
    log('最新安装的app是=%j', appInfoList[0])
    
    var packageName = appInfoList[0].packageName
    shell('am force-stop ' + packageName, true);
    return appInfoList[0].appName
};

启动最新安装的APP

// 启动最新安装的APP
function launchAppLast() {
    var pm = context.getPackageManager()
    var appList = pm.getInstalledApplications(0)
    var appInfoList = []
    for (let i = 0; i < appList.size(); i++) {
        var app = appList.get(i)
        var appInfo = {
            appName: app.loadLabel(pm),
            packageName: app.packageName,
            isSystemApp: app.isSystemApp(),
            firstInstallTime: pm.getPackageInfo(app.packageName, 0).firstInstallTime
        }
        appInfoList.push(appInfo)
        
    }
    appInfoList.sort((a, b) => {
        return b.firstInstallTime - a.firstInstallTime
    })
    log('最新安装的app是=%j', appInfoList[0])
    
    var packageName = appInfoList[0].packageName
    launch(packageName)
    return appInfoList[0].appName
};

获取用户安装的app

function getUserAppList() {
    var pm = context.getPackageManager()
    var appList = pm.getInstalledApplications(0)
    var appInfoList = []
    for (let i = 0; i < appList.size(); i++) {
        var app = appList.get(i)
        var appInfo = {
            appName: app.loadLabel(pm),
            packageName: app.packageName,
            isSystemApp: app.isSystemApp(),
            firstInstallTime: pm.getPackageInfo(app.packageName, 0).firstInstallTime
        }
        if (!app.isSystemApp()) {
            appInfoList.push(appInfo)
        }
        
        log(appInfoList)
    }
};

失去焦点

// 失去焦点
window.disableFocus();

系统是否ROOT

// 系统是否ROOT
function isRoot() {
    var r = shell("ls /system/bin", true).result.toString()
    if (r.length > 50) {
        return true
    } else {
        return false
    }
};

获取指定应用的版本号

/*
* 获取指定应用的版本号
* @param {string} packageName 应用包名
*/
function getPackageVersion(packageName) {
    importPackage(android.content);
    var pckMan = context.getPackageManager();
    var packageInfo = pckMan.getPackageInfo(packageName, 0);
    return packageInfo.versionName;
};


打开QQ群名片

// 打开QQ群名片
function (qqGroupNum) {
    app.startActivity({
        action: "android.intent.action.VIEW",
        data: "mqqapi://card/show_pslcard?card_type=group&uin=" + qqGroupNum,
        packageName: "com.tencent.mobileqq",
    });
};


QQ强制聊天

// QQ强制聊天
function qqChat(qqNum) {
    app.startActivity({
        action: "android.intent.action.VIEW",
        data: "mqq://im/chat?chat_type=wpa&version=1&src_type=web&uin=" + qqNum,
        packageName: "com.tencent.mobileqq",
    });
};

取md5

// 取md5
function getMd5(string) {
    return java.math.BigInteger(1, java.security.MessageDigest.getInstance("MD5").digest(java.lang.String(string).getBytes())).toString(16);
};


网络检测

// 网络检测
function internetCheck() {
    var intent = new Intent();
    importClass(android.content.BroadcastReceiver);
    importClass(android.content.ContextWrapper);
    importClass(android.content.IntentFilter);
    importClass(android.net.ConnectivityManager);
    var filter = new IntentFilter();
    filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
    new ContextWrapper(context).registerReceiver(a = new BroadcastReceiver({
        onReceive: function (context, intent) {
            var action = intent.getAction();
            if (action.equals(ConnectivityManager.CONNECTIVITY_ACTION)) {
                var mConnectivityManager = context.getSystemService(context.CONNECTIVITY_SERVICE);
                netInfo = mConnectivityManager.getActiveNetworkInfo();
                if (netInfo != null && netInfo.isAvailable()) {
                    
                    /////////////网络连接
                    var name = netInfo.getTypeName();
                    
                    if (netInfo.getType() == ConnectivityManager.TYPE_WIFI) {
                        /////WiFi网络
                        toastLog("WiFi网络");
                        return "WiFi网络"
                    } else if (netInfo.getType() == ConnectivityManager.TYPE_ETHERNET) {
                        /////有线网络
                        toastLog("有线网络");
                        return "有线网络"
                        
                    } else if (netInfo.getType() == ConnectivityManager.TYPE_MOBILE) {
                        /////////3g网络
                        toastLog("3g网络");
                        return "3g网络"
                        
                    }
                } else {
                    ////////网络断开
                    toastLog("网络断开");
                    return "网络断开"
                    
                }
            }
            
        }
    }), filter);
};


// 获取手机ip地理位置
function getAction() {
    var ip地理位置 = false
    var ip地理位置正则 = /本机IP: \d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}<\/span>([\s\S]*?)<\/td/
    var ipUrl = "http://www.baidu.com/s?ie=UTF-8&wd=ip%E5%BD%92%E5%B1%9E%E5%9C%B0%E6%9F%A5%E8%AF%A2"
    var r = http.get(ipUrl);
    log("code = " + r.statusCode);
    var htmlResult = r.body.string()
    ip地理位置 = ip地理位置正则.exec(htmlResult)
    if (ip地理位置) {
        ip地理位置 = ip地理位置正则.exec(ip地理位置)
        ip地理位置 = ip地理位置[1]
        toastLog(ip地理位置)
        return ip地理位置
    } else {
        log('没有查询到Ip地理位置,脚本停止')
        return false
    }
};

自定义位置提示块

//自定义位置提示块
function toastEx(msg, x, y) {
    importClass(android.widget.Toast);
    importClass(android.view.Gravity);
    var toast = Toast.makeText(context, msg, Toast.LENGTH_SHORT);
    toast.setGravity(Gravity.TOP | Gravity.LEFT, x, y);
    toast.show();
};


比较日期大小


let begintime = '2019-11-25'
let endtime = getNowFormatDate()
log(endtime)
log(compareDate(begintime, endtime))

// 比较日期大小
function compareDate(begintime, endtime) {
    return ((new Date(begintime.replace(/-/g, "\/"))) < (new Date(endtime.replace(/-/g, "\/"))));
};

// 获取当前日期2019-11-26
function getNowFormatDate() {
    var date = new Date();
    var seperator1 = "-";
    var year = date.getFullYear();
    var month = date.getMonth() + 1;
    var strDate = date.getDate();
    if (month >= 1 && month <= 9) {
        month = "0" + month;
    }
    if (strDate >= 0 && strDate <= 9) {
        strDate = "0" + strDate;
    }
    var currentdate = year + seperator1 + month + seperator1 + strDate;
    return currentdate;
}


你可能感兴趣的:(Auto.js零散例子)