88 * 3.Auto.js软件版本3.0以上
99 *
1010 * 使用方法:
11- * 1.将take.png与脚本放置于同目录下
12- * 2.目前支持PIN解锁(5.0+)和图案解锁(7.0+,从1开始),若手机设置了密码,请将password改为实际密码 ;若无密码,则无需修改
11+ * 1.将take.png(找图所需)、config.js(配置文件)与脚本放置于同目录下
12+ * 2.目前支持PIN解锁(5.0+)和图案解锁(7.0+,从1开始),若手机设置了密码,请将config.js中的password改为实际密码 ;若无密码,则无需修改
1313 * 3.直接启动脚本即可,不用点自己打开支付宝。建议先手动运行一次,成功之后再配置定时任务
1414 * 4.申请截图的权限时,不需要手动点击"立即开始",脚本会自行点击"立即开始"。
1515 * 5.脚本运行时,可以按Home键停止运行
2525 * 1.魔趣7.1系统正常,偶尔出现崩溃情况,依赖于Auto.js.apk稳定性
2626 * @author ridersam <e1399579@gmail.com>
2727 */
28- var config = require ( "config.js" ) || { } ;
28+ var config = files . isFile ( "config.js" ) ? require ( "config.js" ) : { } ;
2929var password = config . password || [ 1 , 2 , 3 , 4 ] ; // 锁屏密码
3030var takeImg = config . takeImg || files . cwd ( ) + "/take.png" ; // 收取好友能量用到的图片
3131
@@ -234,7 +234,7 @@ function AntForest(robot) {
234234 this . robot = robot ;
235235
236236 this . openApp = function ( ) {
237- toastLog ( "即将收取蚂蚁森林能量,请勿操作! " ) ;
237+ toastLog ( "即将收取蚂蚁森林能量,按Home键停止 " ) ;
238238
239239 launch ( ALIPAY ) ;
240240 //waitForPackage(ALIPAY, 500);
@@ -302,8 +302,14 @@ function AntForest(robot) {
302302 } ;
303303
304304 this . work = function ( ) {
305+ // 蚂蚁森林控件范围
306+ var bounds = className ( "android.view.View" ) . depth ( 11 ) . filter ( function ( o ) {
307+ return o . indexInParent ( ) === 1 ;
308+ } ) . findOnce ( ) . bounds ( ) ;
309+ log ( bounds ) ;
310+
305311 // 开始收取
306- this . take ( "攻略" ) ;
312+ this . take ( bounds ) ;
307313 toastLog ( "收取自己的能量完毕" ) ;
308314
309315 // 等待好友列表
@@ -332,7 +338,7 @@ function AntForest(robot) {
332338 exit ( ) ;
333339 }
334340
335- this . takeOthers ( icon , className ( "android.webkit.WebView" ) . scrollable ( true ) ) ;
341+ this . takeOthers ( bounds , icon , className ( "android.webkit.WebView" ) . scrollable ( true ) ) ;
336342
337343 var more = desc ( "查看更多好友" ) . className ( "android.view.View" ) . find ( ) ;
338344 if ( more . length ) {
@@ -342,8 +348,8 @@ function AntForest(robot) {
342348 // 等待更多列表刷新
343349 if ( id ( "com.alipay.mobile.nebula:id/h5_tv_title" ) . text ( "好友排行榜" ) . findOne ( TIMEOUT ) ) {
344350 sleep ( 2000 ) ; // 等待界面渲染
345- //this.takeOthers(icon, desc("没有更多了").className("android.view.View"));
346- this . takeOthers ( icon , className ( "android.webkit.WebView" ) . scrollable ( true ) ) ;
351+ //this.takeOthers(bounds, icon, desc("没有更多了").className("android.view.View"));
352+ this . takeOthers ( bounds , icon , className ( "android.webkit.WebView" ) . scrollable ( true ) ) ;
347353 this . robot . back ( ) ;
348354 } else {
349355 toastLog ( "进入好友排行榜失败" ) ;
@@ -356,21 +362,13 @@ function AntForest(robot) {
356362
357363 /**
358364 * 收取能量
359- * @param keyword
365+ * @param bounds
360366 */
361- this . take = function ( keyword ) {
362- var right_bottom = className ( "android.widget.Button" ) . desc ( keyword ) . findOne ( TIMEOUT ) ;
363- var left_top = id ( "com.alipay.mobile.nebula:id/h5_tv_nav_back" ) . findOne ( TIMEOUT ) ;
364-
367+ this . take = function ( bounds ) {
365368 var filters = [ ] ;
366- var left = 0 ;
367- var right = WIDTH ;
368- var top = left_top ? left_top . bounds ( ) . bottom : 215 ;
369- var bottom = right_bottom ? right_bottom . bounds ( ) . top : 1092 ;
370-
371- log ( left + "-" + top + "-" + right + "-" + bottom ) ;
372- var all = descMatches ( "^(绿色能量|\\d+k?g)$" ) . boundsInside ( left , top , right , bottom ) . clickable ( true ) . find ( ) ;
373- toastLog ( "找到" + ( all . size ( ) - 1 ) + "个能量球" ) ;
369+
370+ var all = descMatches ( "^(绿色能量|\\d+k?g)$" ) . boundsInside ( bounds . left , bounds . top , bounds . right , bounds . bottom ) . find ( ) ;
371+ toastLog ( "找到" + ( all . length - 1 ) + "个能量球" ) ;
374372 all . each ( function ( x ) {
375373 filters . push ( x ) ;
376374 } ) ;
@@ -398,10 +396,11 @@ function AntForest(robot) {
398396
399397 /**
400398 * 收取好友能量
399+ * @param bounds
401400 * @param icon
402401 * @param endSelector
403402 */
404- this . takeOthers = function ( icon , endSelector ) {
403+ this . takeOthers = function ( bounds , icon , endSelector ) {
405404 var times = 0 ;
406405 var prevTop = 0 ;
407406 var top = 0 ;
@@ -411,12 +410,12 @@ function AntForest(robot) {
411410 var x2 = WIDTH / 2 ;
412411 var y2 = row_height ;
413412 while ( times < MAX_RETRY_TIMES ) {
414- this . takeFromImage ( icon ) ;
413+ this . takeFromImage ( bounds , icon ) ;
415414
416415 this . robot . swipe ( x1 , y1 , x2 , y2 ) ;
417416 sleep ( 1500 ) ; // 等待滑动动画
418417
419- this . takeFromImage ( icon ) ;
418+ this . takeFromImage ( bounds , icon ) ;
420419
421420 // 到底部了
422421 var bottomUi = endSelector . find ( ) ;
@@ -434,9 +433,10 @@ function AntForest(robot) {
434433
435434 /**
436435 * 找图收取
436+ * @param bounds
437437 * @param icon
438438 */
439- this . takeFromImage = function ( icon ) {
439+ this . takeFromImage = function ( bounds , icon ) {
440440 var point , capture ;
441441 var row_height = 192 * ( HEIGHT / 1920 ) ; // 在1080*1920的屏幕上,一行占192,即一屏10行
442442 var options = {
@@ -462,7 +462,7 @@ function AntForest(robot) {
462462 }
463463
464464 // 收取、返回
465- this . take ( "浇水" ) ;
465+ this . take ( bounds ) ;
466466 this . robot . back ( ) ;
467467
468468 // 等待好友列表刷新
@@ -517,7 +517,7 @@ function Robot() {
517517 this . robot = ( device . sdkInt < 24 ) ? new LollipopRobot ( ) : new NougatRobot ( ) ;
518518
519519 this . click = function ( x , y , duration ) {
520- duration = duration || 50 ;
520+ duration = duration || 10 ;
521521
522522 return this . robot . click ( x , y , duration ) ;
523523 } ;
0 commit comments