1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > Auto.js 脚本自动收取自己和好友的蚂蚁森林能量

Auto.js 脚本自动收取自己和好友的蚂蚁森林能量

时间:2023-12-06 17:15:19

相关推荐

Auto.js 脚本自动收取自己和好友的蚂蚁森林能量

用autoJS写的能量收取脚本软件.说一下达到的效果,把蚂蚁森林按钮要设置在常用应用中.先收取自己主页的能量,然后进入排行榜收集好友的能量.中途可以按下音量下键提前结束脚本运行.改改测测基本上现在运行完美的了,充分衡量了网络延迟和程序运行正常的平衡性.并且支持支持运动能量生成时间段执行,等待自己的运动能量生成收集.我是配合tasker设置的定时执行脚本,由Tasker唤醒设备教程链接,调用autojs插件执行任务.总之我觉得要想下载下来直接使用的话可能由于运行环境因素,你可能要调整一下.这个作为参考的价值还是稍微比较好的.

说明:

我的设备是6.0的,因为click及很多函数7.0以上才能用.根据搜索组件,利用UiObject组件的click点击我测试在我这失效,改用了获取到组件位置后,调用Tap(x,y).点击、滑动的处理我用的是root的处理方式,没root自行应该改为无障碍方式应该也可以话.目前只支持分辨率为1080,1920.如果分辨率不一样,可能你还有做分辨率兼容性处理.或者等我后续处理.后边会不定期更新新的功能

转载请说明出处

var myEnergeType=["线下支付","行走","共享单车","地铁购票","网络购票","网购火车票","生活缴费","ETC缴费","电子发票","绿色办公","咸鱼交易","预约挂号"];var morningTime="07:10";//自己运动能量生成时间function tLog(msg) {toast(msg);console.log(msg)}/*** 获取权限和设置参数*/function prepareThings(){setScreenMetrics(1080, 1920);//请求截图if(!requestScreenCapture()){tLog("请求截图失败");exit();}}/*** 设置按键监听 当脚本执行时候按音量减 退出脚本*/function registEvent() {//启用按键监听events.observeKey();//监听音量上键按下events.onKeyDown("volume_down", function(event){tLog("脚本手动退出");exit();});}/*** 获取截图*/function getCaptureImg(){var img0 = captureScreen();if(img0==null || typeof(img0)=="undifined"){tLog("截图失败,退出脚本");exit();}else{return img0;}}/*** 默认程序出错提示操作*/function defaultException() {tLog("程序当前所处状态不合预期,脚本退出");exit();}/*** 等待加载收集能量页面,采用未找到指定组件阻塞的方式,等待页面加载完成*/function waitPage(type){// 等待进入自己的能量主页if(type==0){desc("消息").findOne();}// 等待进入他人的能量主页else if(type==1){desc("浇水").findOne();}//再次容错处理sleep(3000);}/*** 从支付宝主页进入蚂蚁森林我的主页*/function enterMyMainPage(){launchApp("支付宝");tLog("等待支付宝启动");var i=0;sleep(1000);//五次尝试蚂蚁森林入口while (!textEndsWith("蚂蚁森林").exists() && i<=5){sleep(2000);i++;}clickByText("蚂蚁森林",true,"请把蚂蚁森林入口添加到主页我的应用");//等待进入自己的主页waitPage(0);}/*** 进入排行榜*/function enterRank(){Swipe(520,1860,520,100);sleep(2500);clickByDesc("查看更多好友",0,true,"程序未找到排行榜入口,脚本退出");var i=0;//等待排行榜主页出现sleep(2000);while (!textEndsWith("好友排行榜").exists() && i<=5){sleep(2000);i++;}if(i>=5){defaultException();}}/*** 从排行榜获取可收集好有的点击位置* @returns {*}*/function getHasEnergyfriend(type) {var img = getCaptureImg();var p=null;if(type==1){//411宽度 #a2cbb4 1032,1820 #30bf6c 1032,1787 -33#52ca84 1032,1832 12#ffffff 1032,1835 15p = images.findMultiColors(img, "#a2cbb4",[[0, -33, "#30bf6c"], [0,12, "#52ca84"],[0,15, "#ffffff"]], {region: [1032, 180, 1, 1700]});}else if(type==2){// 480宽度 基准点1775,832 #30bf6 -2,23 #ffffff -5,16 #ffffff 0,-12 #30bf6c 0,44 #30bf6cp = images.findMultiColors(img, "#30bf6c",[[-2, 23, "#ffffff"], [-5,16, "#ffffff"],[0,-12, "#30bf6c"],[0,44, "#30bf6c"]], {region: [1069, 180, 7, 1680]});}if(p!=null){return p;}else {return null;}}/*** 判断是否好有排行榜已经结束* @returns {boolean}*/function isRankEnd() {if(descEndsWith("没有更多了").exists()){var b=descEndsWith("没有更多了").findOne();var bs=b.bounds();if(bs.centerY()<1920){return true;}}return false;}/*** 在排行榜页面,循环查找可收集好友* @returns {boolean}*/function enterOthers(){tLog("开始检查排行榜");var i=1;var ePoint=getHasEnergyfriend(1);//确保当前操作是在排行榜界面while(ePoint==null && textEndsWith("好友排行榜").exists()){//滑动排行榜 root方式的的点击调用.如无root权限,7.0及其以上可采用无障碍模式的相关函数Swipe(520,1800,520,300,1000);sleep(3000);ePoint=getHasEnergyfriend(1);i++;//检测是否排行榜结束了if(isRankEnd()){return false;}//如果连续32次都未检测到可收集好友,无论如何停止查找(由于程序控制了在排行榜界面,且判断了结束标记,基本已经不存在这种情况了)else if(i>32){tLog("程序可能出错,连续"+i+"次未检测到可收集好友");exit();}}if(ePoint!=null){//点击位置相对找图后的修正Tap(ePoint.x,ePoint.y+20);waitPage(1);clickByDesc("可收取",80);//进去收集完后,递归调用enterOthersback();sleep(2000);var j=0;//等待返回好有排行榜if(!textEndsWith("好友排行榜").exists() && j<=5){sleep(2000);j++;}if(j>=5){defaultException();}enterOthers();}else{defaultException();}}/*** 根据描述值 点击* @param energyType* @param noFindExit*/function clickByDesc(energyType,paddingY,noFindExit,exceptionMsg){if(descEndsWith(energyType).exists()){descEndsWith(energyType).find().forEach(function(pos){var posb=pos.bounds();Tap(posb.centerX(),posb.centerY()-paddingY);sleep(2000);});}else{if(noFindExit!=null && noFindExit){if(exceptionMsg !=null){tLog(exceptionMsg);exit();}else{defaultException();}}}}/*** 根据text值 点击* @param energyType* @param noFindExit*/function clickByText(energyType,noFindExit,exceptionMsg){if(textEndsWith(energyType).exists()){textEndsWith(energyType).find().forEach(function(pos){var posb=pos.bounds();Tap(posb.centerX(),posb.centerY()-60);});}else{if(noFindExit!=null && noFindExit){if(exceptionMsg !=null){tLog(exceptionMsg);exit();}else{defaultException();}}}}/*** 遍历能量类型,收集自己的能量*/function collectionMyEnergy(){var energyRegex=generateCollectionType();var checkInMorning=false;//如果是早上7点10分左右的话.等待主页能量出现 每隔一秒检测一次while(isMorningTime() && descEndsWith("行走").exists()){if (!checkInMorning){tLog("等待运动能量生成中...");checkInMorning=true;}descEndsWith("行走").find().forEach(function(pos){var posb=pos.bounds();Tap(posb.centerX(),posb.centerY()-80);sleep(1500);});}if(checkInMorning){tLog("运动能量收集完成");}if(descMatches(energyRegex).exists()){if(!checkInMorning){tLog("防止小树的提示遮挡,等待中");sleep(7000);}descMatches(energyRegex).find().forEach(function(pos){var posb=pos.bounds();Tap(posb.centerX(),posb.centerY()-80);sleep(2000);});}}/*** 结束后返回主页面*/function whenComplete() {tLog("结束");back();sleep(1500);back();exit();}/*** 根据能量类型数组生成我的能量类型正则查找字符串* @returns {string}*/function generateCollectionType() {var regex="/";myEnergeType.forEach(function (t,num) {if(num==0){regex+="(\\s*"+t+"$)";}else{regex+="|(\\s*"+t+"$)";}});regex+="/";return regex;}function isMorningTime() {var now =new Date();var hour=now.getHours();var minu=now.getMinutes();var targetTime=morningTime.split(":");if(Number(targetTime[0])==hour && Math.abs(Number(targetTime[1])-minu)<=2){return true;}else{return false;}}//程序主入口function mainEntrence(){//前置操作prepareThings();//注册音量下按下退出脚本监听registEvent();//从主页进入蚂蚁森林主页enterMyMainPage();//收集自己的能量collectionMyEnergy();//进入排行榜enterRank();//在排行榜检测是否有好有的能量可以收集enterOthers();//结束后返回主页面whenComplete();}mainEntrence();

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。