zoukankan      html  css  js  c++  java
  • Auto.js 初试-Android开发JS利器

    GitHub地址:https://github.com/hyb1996/Auto.js

    文档地址:https://hyb1996.github.io/AutoJs-Docs/#/?id=%E7%BB%BC%E8%BF%B0

    Android软件下载:https://www.coolapk.com/apk/129872

      今天看今日头条无意间看到个蚂蚁森林自动收能量的脚本,于是打开看看安全性。

    下面是代码:

      1 auto();
      2 //auto.waitFor();
      3 
      4 requestScreenCapture();
      5 //解锁
      6 unlock("1111");//里面是你的锁屏密码,仅支持数字解锁,并且需要点击确定键,需要点击确定键的需要自己改一下解锁函数
      7 
      8 var friendNumber=145;//这里输入你的好友数,适当输大一点
      9 
     10 threads.start(function(){
     11     toast("按音量下键停止")
     12     //启动监听
     13     events.observeKey();
     14     //监听音量下键
     15     events.onKeyDown("volume_down",function(event){
     16         toast("已停止")
     17         exit();
     18     })
     19     
     20 });
     21 
     22 
     23 //启动app
     24 launchApp("支付宝");
     25 waitForActivity("com.eg.android.AlipayGphone.AlipayLogin");
     26 sleep(5000);
     27 var w=text("蚂蚁森林").className("android.widget.TextView").findOne();
     28 var b=w.bounds();
     29 if(w==null){
     30     log("null");
     31 }
     32 //点击蚂蚁森林
     33 if(click(b.centerX(),b.centerY())){
     34     //toast("点击成功");
     35     log("点击成功");
     36 }else{
     37     log("点击失败");
     38 }
     39 
     40 
     41 
     42 //收集自己的能量
     43 sleep(5000);
     44 //collectEnergy();
     45 
     46 var width=device.width;
     47 var i,j;
     48 
     49 //盲点收自己的能量
     50 for(i=450;i<=800;){//y方向点击范围
     51     threads.start(function(){
     52         for(j=300;j<width-200;){//x方向点击范围
     53            click(j,i);
     54            j=j+150;
     55         }
     56     });
     57     sleep(1000);
     58     i=i+100;
     59 }
     60 
     61 toastLog("收集能量完成");
     62 
     63 //偷好友能量
     64 sleep(3000);
     65 stealEnergy(friendNumber);
     66 
     67 toastLog("偷能量完成");
     68 
     69 sleep(2000);
     70 
     71 back();
     72 sleep(2000);
     73 back();
     74 sleep(2000);
     75 
     76 //关闭应用,仅有root权限下有用
     77 shell("am force-stop com.eg.android.AlipayGphone",true);
     78 
     79 exit();
     80 
     81 
     82 //解锁函数
     83 function unlock(password){
     84     var a;
     85     var b;
     86     if (!device.isScreenOn()) {
     87         device.wakeUpIfNeeded();
     88         sleep(2000);
     89         swipe(500,1000,500,100,1000);
     90         for(var i=0;i<password.length;i++){
     91             a=password.charAt(i);
     92             log(a);
     93             sleep(500);
     94             b=text(a).findOne().bounds();
     95             click(b.centerX(),b.centerY());
     96         }
     97         //需要点击确定键的可以在下面加上click(x坐标,y坐标);
     98         toast("解锁成功");
     99         sleep(500);
    100     }
    101 }
    102 
    103 //收能量
    104 function collectEnergy(){
    105     sleep(2000);
    106     var i=descContains("收集能量").find().size();
    107     toast("可以收集"+i+"个能量");
    108     //descContains("收集能量").exists();
    109     while(i!=0){
    110         b=descContains("收集能量").findOne().bounds();
    111         sleep(1000);
    112         click(b.centerX(),b.centerY());
    113         i--;
    114         sleep(1000);
    115     }
    116 }
    117 
    118 //找好友的能量
    119 function findFriendEnergy(){
    120     //截图
    121     var img = captureScreen();
    122     //toastLog("开始找色");
    123     //var point = findColor(img, "#1DA06D");
    124     var point = findColorInRegion(img,"#1DA06D", 0, 0, device.width,400);
    125     if(point){
    126        //toastLog("x = " + point.x + ", y = " + point.y);
    127        //点击进去偷能量
    128        click(point.x,point.y+50);
    129        return true;
    130     }else{
    131        //toastLog("没有找到");
    132        return false;
    133     }
    134 }
    135 
    136 
    137 //滑动屏幕找到更多好友
    138 function swipeScreenFirst(){
    139     
    140     //gesture(1000,[500,1500],[500,500])
    141     swipe(500,600,500,100,1000);
    142     var i=5;
    143     while(true){
    144         if(desc("查看更多好友").exists()){
    145            desc("查看更多好友").findOne().click();
    146            sleep(2000);
    147            swipe(500,500,500,278,1000);
    148            break;
    149         }
    150         
    151         if(i==0){
    152             toastLog("你的好友太少无法偷取");
    153             sleep(2000)
    154             back();
    155             sleep(2000);
    156             //关闭应用,仅有root权限下有用
    157             shell("am force-stop com.eg.android.AlipayGphone",true);
    158 
    159             exit();
    160         }
    161         
    162         i--;
    163     }
    164     
    165 }
    166 
    167 
    168 //滑动屏幕
    169 function swipeScreen(){
    170     //滑动一个好友的距离
    171     //gesture(1000,[500,1500],[500,500])
    172     swipe(500,500,500,290,1000);
    173     
    174 }
    175 
    176 //偷好友能量
    177 function stealEnergy(friendNumber){
    178     //滑动屏幕,找到查看更多好友进入到好友排行榜
    179     swipeScreenFirst();
    180     sleep(2000);
    181     
    182    //一个一个偷能量
    183     while(friendNumber!=0){
    184         if(findFriendEnergy()){
    185             sleep(2000);
    186             collectEnergy();
    187             back();
    188             sleep(1000);
    189             swipeScreen();
    190         }else{
    191             swipeScreen();
    192             sleep(1000);
    193         }
    194         
    195         friendNumber--;
    196         
    197     }
    198     
    199 }

     具体使用方式见下面录屏:

  • 相关阅读:
    C#yield return用法示例
    C#多线程示例
    AspNetCore.Authentication
    C#委托与事件
    按值和按引用传递参数
    基于iView的无限级菜单
    Sortable By Attribute
    未能加载文件或程序集“BLL”或它的某一个依赖项。生成此程序集的运行时比当前加载的运行时新,无法加载此程序集。
    有关导出Excel特殊字符的问题
    openFileDialog的使用
  • 原文地址:https://www.cnblogs.com/zsh-blogs/p/10581692.html
Copyright © 2011-2022 走看看