├── 201804 ├── Robot.js ├── SaveXml.js ├── ScreenShot │ ├── Screenshot_2018-04-03-19-55-21.jpg │ ├── Screenshot_2018-04-03-19-59-44.jpg │ ├── Screenshot_2018-04-03-20-01-34.jpg │ ├── Screenshot_2018-04-03-20-03-08.jpg │ └── Screenshot_2018-04-03-20-03-35.jpg ├── Script.js ├── Secure.js ├── SingleScript.jar ├── SingleScript.js ├── config.js ├── enable.js ├── readme.md ├── start.js ├── take.png ├── unlock.js ├── 投食.js ├── 蚂蚁森林.js └── 驱赶.js ├── README.md ├── take.png ├── take720p.png ├── update.js ├── 收取更多好友的能量.js ├── 脚本.js └── 蚂蚁森林收能量exposed edge 版本.js /201804/Robot.js: -------------------------------------------------------------------------------- 1 | /** 2 | * 安卓5机器人 3 | * @constructor 4 | * @author ridersam 5 | */ 6 | function LollipopRobot(max_retry_times) { 7 | this.robot = new RootAutomator(); 8 | this.max_retry_times = max_retry_times || 10; 9 | 10 | this.click = function (x, y) { 11 | Tap(x, y); 12 | sleep(10); 13 | return true; 14 | }; 15 | 16 | this.swipe = function (x1, y1, x2, y2, duration) { 17 | duration = duration || 1000; 18 | Swipe(x1, y1, x2, y2, duration); 19 | // 滑动之后有动画 20 | sleep(1500); 21 | return true; 22 | }; 23 | } 24 | 25 | /** 26 | * 安卓7机器人 27 | * @constructor 28 | */ 29 | function NougatRobot(max_retry_times) { 30 | this.max_retry_times = max_retry_times || 10; 31 | 32 | this.click = function (x, y) { 33 | return click(x, y); 34 | }; 35 | 36 | this.swipe = function (x1, y1, x2, y2, duration) { 37 | duration = duration || 50; 38 | return swipe(x1, y1, x2, y2, duration); 39 | }; 40 | } 41 | 42 | /** 43 | * 机器人工厂 44 | * @param {int} max_retry_times 最大尝试次数 45 | * @author ridersam 46 | */ 47 | function Robot(max_retry_times) { 48 | this.robot = (device.sdkInt < 24) ? new LollipopRobot(max_retry_times) : new NougatRobot(max_retry_times); 49 | 50 | this.click = function (x, y) { 51 | return this.robot.click(x, y); 52 | }; 53 | 54 | this.clickCenter = function (b) { 55 | let rect = b.bounds(); 56 | return this.click(rect.centerX(), rect.centerY()); 57 | }; 58 | 59 | this.swipe = function (x1, y1, x2, y2, duration) { 60 | this.robot.swipe(x1, y1, x2, y2, duration); 61 | }; 62 | 63 | this.back = function () { 64 | KeyCode("KEYCODE_BACK"); 65 | }; 66 | 67 | this.kill = function (package_name) { 68 | shell("am force-stop " + package_name, true); 69 | }; 70 | } 71 | 72 | module.exports = Robot; -------------------------------------------------------------------------------- /201804/SaveXml.js: -------------------------------------------------------------------------------- 1 | module.exports = function(dir, name) { 2 | dir = dir || "/sdacrd/debug/"; 3 | files.ensureDir(dir); 4 | name = name || new Date().getTime() + ".txt"; 5 | let r = visibleToUser(true).findOne(); 6 | while (r.parent()) { 7 | r = r.parent(); 8 | } 9 | //shell("uiautomator dump "+dir+name,true); 10 | let txt = xml(r, 0); 11 | files.write(dir + name, txt); 12 | }; 13 | 14 | 15 | function xml(node, i) { 16 | let self = t(i) + ""; 27 | } 28 | return self; 29 | 30 | } 31 | 32 | function t(n) { 33 | let t = ""; 34 | for (let i = 0; i < n; i++) { 35 | t += "\t"; 36 | } 37 | return t; 38 | } 39 | 40 | 41 | function formatNode(node) { 42 | //todo more 43 | return node.toString(); 44 | } -------------------------------------------------------------------------------- /201804/ScreenShot/Screenshot_2018-04-03-19-55-21.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/start201711/autojs/880563261cd250c4d61ec97fe16fe53d28fd477e/201804/ScreenShot/Screenshot_2018-04-03-19-55-21.jpg -------------------------------------------------------------------------------- /201804/ScreenShot/Screenshot_2018-04-03-19-59-44.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/start201711/autojs/880563261cd250c4d61ec97fe16fe53d28fd477e/201804/ScreenShot/Screenshot_2018-04-03-19-59-44.jpg -------------------------------------------------------------------------------- /201804/ScreenShot/Screenshot_2018-04-03-20-01-34.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/start201711/autojs/880563261cd250c4d61ec97fe16fe53d28fd477e/201804/ScreenShot/Screenshot_2018-04-03-20-01-34.jpg -------------------------------------------------------------------------------- /201804/ScreenShot/Screenshot_2018-04-03-20-03-08.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/start201711/autojs/880563261cd250c4d61ec97fe16fe53d28fd477e/201804/ScreenShot/Screenshot_2018-04-03-20-03-08.jpg -------------------------------------------------------------------------------- /201804/ScreenShot/Screenshot_2018-04-03-20-03-35.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/start201711/autojs/880563261cd250c4d61ec97fe16fe53d28fd477e/201804/ScreenShot/Screenshot_2018-04-03-20-03-35.jpg -------------------------------------------------------------------------------- /201804/Script.js: -------------------------------------------------------------------------------- 1 | module.exports = function () { 2 | let _ra = device.sdkInt < 24 ? new RootAutomator() : null; 3 | this.press = function (x, y) { 4 | if (_ra) { 5 | _ra.press(x, y, 100); 6 | return true; 7 | } else { 8 | return press(x, y, 100); 9 | } 10 | }; 11 | this.pressCenter = function (o) { 12 | return this.press(o.bounds().centerX(), o.bounds().centerY()); 13 | } 14 | }; -------------------------------------------------------------------------------- /201804/Secure.js: -------------------------------------------------------------------------------- 1 | /** 2 | * 安全相关 3 | * @param {Robot} robot 机器人对象 4 | * @param {int} max_retry_times 最大尝试次数 5 | * @author ridersam 6 | */ 7 | const WIDTH = Math.min(device.width, device.height); 8 | const HEIGHT = Math.max(device.width, device.height); 9 | 10 | function Secure(robot, max_retry_times) { 11 | this.robot = robot; 12 | this.max_retry_times = max_retry_times || 10; 13 | this.km = context.getSystemService(context.KEYGUARD_SERVICE); 14 | this.secure = (function() { 15 | var secure; 16 | 17 | switch (true) { 18 | case !isNaN(parseInt(shell("getprop ro.miui.ui.version.code").result)): 19 | secure = new MIUISecure(this); 20 | break; 21 | default: 22 | secure = new NativeSecure(this); 23 | break; 24 | } 25 | 26 | return secure; 27 | }.bind(this))(); 28 | 29 | this.openLock = function(password, pattern_size) { 30 | var isLocked = this.km.inKeyguardRestrictedInputMode(); // 是否已经上锁 31 | var isSecure = this.km.isKeyguardSecure(); // 是否设置了密码 32 | pattern_size = pattern_size || 3; 33 | log({ 34 | isLocked: isLocked, 35 | isSecure: isSecure 36 | }); 37 | 38 | var i = 0; 39 | while (this.secure.hasLayer()) { 40 | if (i >= this.max_retry_times) { 41 | toastLog("打开上滑图层失败"); 42 | return this.failed(); 43 | } 44 | log("向上滑动"); 45 | this.openLayer(); 46 | i++; 47 | } 48 | 49 | if (!(isLocked && isSecure)) return true; 50 | log("解锁"); 51 | for (var i = 0; i < this.max_retry_times; i++) { 52 | if (this.unlock(password, pattern_size)) { 53 | return true; 54 | } else { 55 | toastLog("解锁失败,重试"); 56 | } 57 | } 58 | 59 | toastLog("解锁失败,不再重试"); 60 | return this.failed(); 61 | }; 62 | 63 | this.failed = function() { 64 | KeyCode("KEYCODE_POWER"); 65 | engines.stopAll(); 66 | exit(); 67 | return false; 68 | }; 69 | 70 | this.openLayer = function() { 71 | var x = WIDTH / 2; 72 | var y = HEIGHT - 100; 73 | this.robot.swipe(x, y, x, 100, 750); 74 | sleep(1500); // 等待动画 75 | }; 76 | 77 | this.unlock = function(password, pattern_size) { 78 | var len = password.length; 79 | 80 | if (len < 4) { 81 | throw new Error("密码至少4位"); 82 | } 83 | 84 | return this.secure.unlock(password, pattern_size); 85 | }; 86 | 87 | this.gestureUnlock = function(pattern, password, len, pattern_size) { 88 | var rect = pattern.bounds(); 89 | // 使用坐标查找按键 90 | var oX = rect.left, 91 | oY = rect.top; // 第一个点位置 92 | var w = (rect.right - rect.left) / pattern_size, 93 | h = (rect.bottom - rect.top) / pattern_size; // 2点之单间隔为边框的1/3 94 | var points = []; 95 | 96 | points[0] = { 97 | x: 0, 98 | y: 0 99 | }; 100 | // 初始化每个点的坐标 101 | for (var i = 1; i <= pattern_size; i++) { 102 | for (var j = 1; j <= pattern_size; j++) { 103 | var row = i - 1; 104 | var col = j - 1; 105 | var index = pattern_size * (i - 1) + j; // 序号,从1开始 106 | points[index] = { 107 | x: oX + col * w + w / 2, 108 | y: oY + row * h + h / 2 109 | }; 110 | } 111 | } 112 | 113 | // 使用手势解锁 114 | var gestureParam = [100 * len]; 115 | for (var i = 0; i < len; i++) { 116 | var point = points[password[i]]; 117 | 118 | gestureParam.push([point.x, point.y]); 119 | } 120 | gestures(gestureParam); 121 | 122 | return this.checkUnlock(); 123 | }; 124 | 125 | this.unlockPassword = function(password) { 126 | if (typeof password !== "string") { 127 | password = password.join(""); 128 | } 129 | Text(password); // 输入密码 130 | KeyCode("KEYCODE_ENTER"); // 按Enter 131 | 132 | sleep(1500); 133 | return this.checkUnlock(); 134 | }; 135 | } 136 | 137 | function NativeSecure(secure) { 138 | this.__proto__ = secure; 139 | 140 | this.hasLayer = function() { 141 | return id("com.android.systemui:id/preview_container").visibleToUser(true).exists(); // 是否有上滑图层 142 | }; 143 | 144 | this.unlock = function(password, pattern_size) { 145 | var len = password.length; 146 | 147 | if (id("com.android.systemui:id/lockPatternView").exists()) { 148 | return this.unlockPattern(password, len, pattern_size); 149 | } else if (id("com.android.systemui:id/passwordEntry").exists()) { 150 | return this.unlockPassword(password); 151 | } else if (id("com.android.systemui:id/pinEntry").exists()) { 152 | return this.unlockKey(password, len); 153 | } else { 154 | /*toastLog("识别锁定方式失败,型号:" + device.brand + " " + device.product + " " + device.release); 155 | return this.failed();*/ 156 | toastLog("尝试PIN解锁"); 157 | this.openLayer(); 158 | return this.unlockKey(password, len); 159 | } 160 | }; 161 | 162 | this.unlockKey = function(password, len) { 163 | for (var j = 0; j < len; j++) { 164 | var key_id = "com.android.systemui:id/key" + password[j]; 165 | if (!id(key_id).exists()) { 166 | return false; 167 | } 168 | id(key_id).findOne(1000).click(); 169 | } 170 | if (id("com.android.systemui:id/key_enter").exists()) { 171 | id("com.android.systemui:id/key_enter").findOne(1000).click(); 172 | } 173 | 174 | return this.checkUnlock(); 175 | }; 176 | 177 | this.unlockPattern = function(password, len, pattern_size) { 178 | var pattern = id("com.android.systemui:id/lockPatternView").findOne(1000); 179 | return this.gestureUnlock(pattern, password, len, pattern_size); 180 | }; 181 | 182 | this.checkUnlock = function() { 183 | sleep(1500); // 等待动画 184 | if (id("android:id/message").textContains("重试").exists()) { 185 | toastLog("密码错误"); 186 | return this.failed(); 187 | } 188 | 189 | return !this.km.inKeyguardRestrictedInputMode(); 190 | }; 191 | } 192 | 193 | function MIUISecure(secure) { 194 | this.__proto__ = secure; 195 | 196 | this.hasLayer = function() { 197 | return id("com.android.keyguard:id/miui_porch_notification_and_music_control_container").visibleToUser(true).exists(); 198 | }; 199 | 200 | this.unlock = function(password, pattern_size) { 201 | var len = password.length; 202 | 203 | if (id("com.android.keyguard:id/lockPattern").exists()) { 204 | return this.unlockPattern(password, len, pattern_size); 205 | } else if (id("com.android.keyguard:id/miui_mixed_password_input_field").exists()) { 206 | return this.unlockPassword(password); 207 | } else if (id("com.android.keyguard:id/numeric_inputview").exists()) { 208 | return this.unlockKey(password, len); 209 | } else { 210 | toastLog("识别锁定方式失败,型号:" + device.brand + " " + device.product + " " + device.release); 211 | return this.failed(); 212 | } 213 | }; 214 | 215 | this.unlockKey = function(password, len) { 216 | for (var j = 0; j < len; j++) { 217 | var btn = id("com.android.keyguard:id/numeric_inputview").findOne(1000).findOne(text(password[j])); 218 | if (btn) { 219 | this.robot.clickCenter(btn); 220 | } else { 221 | return false; 222 | } 223 | } 224 | 225 | return this.checkUnlock(); 226 | }; 227 | 228 | this.unlockPattern = function(password, len, pattern_size) { 229 | var pattern = id("com.android.keyguard:id/lockPattern").findOne(1000); 230 | return this.gestureUnlock(pattern, password, len, pattern_size); 231 | }; 232 | 233 | this.checkUnlock = function() { 234 | sleep(1500); // 等待动画 235 | if (id("com.android.keyguard:id/phone_locked_textview").exists()) { 236 | toastLog("密码错误"); 237 | return this.failed(); 238 | } 239 | 240 | return !this.km.inKeyguardRestrictedInputMode(); 241 | }; 242 | } 243 | 244 | module.exports = Secure; -------------------------------------------------------------------------------- /201804/SingleScript.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/start201711/autojs/880563261cd250c4d61ec97fe16fe53d28fd477e/201804/SingleScript.jar -------------------------------------------------------------------------------- /201804/SingleScript.js: -------------------------------------------------------------------------------- 1 | /* 2 | * 说明:模块用于确保多个脚本同时执行时,能 3 | * 够确保这些脚本按照先后顺序、一个个排队执行, 4 | * 类似单一线程池功能 5 | * 6 | * 方法:确保jar文件和此模块在同一个目录, 7 | * 在自己的需要确保单任务的脚本开头, 8 | * 调用加载此模块,并且调用enqueue方法即可 9 | * var single=quire("SingleScript"); 10 | * single.enqueue(); 11 | * 12 | * By 酷安@群主让我注册 13 | * 使用时请保留此注释 14 | */ 15 | importClass(java.io.File); 16 | importClass(java.lang.ClassLoader); 17 | importClass(java.lang.Class); 18 | importClass(com.stardust.autojs.rhino.AndroidClassLoader); 19 | let parent = context.getClassLoader(); 20 | let engine = engines.myEngine(); 21 | let clz = Class.forName("com.stardust.autojs.engine.ScriptEngine", true, parent); 22 | let cls; 23 | try { 24 | cls = Class.forName("com.stardust.TaskQueue", true, parent); 25 | } catch (e) { 26 | let loader = new AndroidClassLoader(parent, new File(context.getCacheDir(), "jar")); 27 | let path = files.path("./SingleScript.jar"); 28 | log(path); 29 | loader.loadJar(new File(path)); 30 | cls = loader.loadClass("com.stardust.TaskQueue"); 31 | } 32 | 33 | let _register = cls.getMethod("register", clz); 34 | let _unregister = cls.getMethod("unregister", clz); 35 | let _taskCount = cls.getMethod("getTaskCount"); 36 | let str = engine + ""; 37 | str = str.substring(str.lastIndexOf("@")); 38 | let SingleScript = {}; 39 | 40 | SingleScript.enqueue = function (b) { 41 | let n = this.size(); 42 | if (n != 0) { 43 | log(str + "前面还有" + n + "个任务,排队中"); 44 | } 45 | _register.invoke(null, engine); 46 | log(str + "\t任务执行中"); 47 | if (b !== true) { 48 | events.on("exit", function () { 49 | SingleScript.dequeue(); 50 | }); 51 | } 52 | }; 53 | SingleScript.dequeue = function () { 54 | _unregister.invoke(null, engine); 55 | log(str + "\t出队"); 56 | }; 57 | SingleScript.size = function () { 58 | return _taskCount.invoke(null); 59 | }; 60 | 61 | module.exports = SingleScript; -------------------------------------------------------------------------------- /201804/config.js: -------------------------------------------------------------------------------- 1 | let config = { 2 | password: "1234", // 锁屏密码 3 | takeImg: "take.png", // 收取好友能量用到的图片 4 | pattern_size: 3, // 图案解锁每行点数 5 | max_retry_times: 10, // 最大失败重试次数 6 | timeout: 15000, // 超时时间:毫秒 7 | check_self_timeout: 60 // 检测自己能量时间:秒 8 | }; 9 | 10 | module.exports = config; -------------------------------------------------------------------------------- /201804/enable.js: -------------------------------------------------------------------------------- 1 | module.exports = function() { 2 | try { 3 | let enabled = shell("settings get secure enabled_accessibility_services", true).result.replace(/\n/, ""); 4 | if (enabled.indexOf("stardust") < 0) { 5 | let stardust = "com.stardust.scriptdroid/com.stardust.scriptdroid.accessibility.AccessibilityService"; 6 | let ret = shell("settings put secure enabled_accessibility_services " + enabled + ":" + stardust, true); 7 | if (ret.code) { 8 | throw new java.lang.Exception(); 9 | } else { 10 | log("检测到无障碍服务被关闭,\n现在已使用脚本强行开启"); 11 | } 12 | } 13 | shell("settings put secure accessibility_enabled 1", true); 14 | } catch (e) { 15 | toastLog("尝试开启无障碍服务异常"); 16 | } 17 | }; -------------------------------------------------------------------------------- /201804/readme.md: -------------------------------------------------------------------------------- 1 | # 使用说明 2 | ### 脚本内容 3 | > * 蚂蚁森林自动收能量脚本 4 | > * 蚂蚁庄园自动投食、驱赶脚本 5 | #### 设备要求: 6 | android 7.0+或者已root的5.0+, 7 | 由于使用需要exposed edge定时任务,实际要求相当于已root 5.0+ 8 | ### 支付宝版本10.1.15.463(就是图标带有福到-年到那个)10.1.18版本之后应该是不支持的 9 | ### 目前应该是没卵用了,就当参考吧 10 | ### 自动收能量脚本 11 | 1. 下载全部文件 12 | 2. 安装[autojs](https://www.coolapk.com/apk/com.stardust.scriptdroid)、[exposed edge](https://play.google.com/store/apps/details?id=com.jozein.xedgepro)等软件 13 | 2. 自己截收取好友能量的小手的图片,重命名为take.png放入当前目录下 14 | ![小手图片](https://github.com/start201711/autojs/blob/master/201804/take.png) 15 | 3. 在config.js文件里面配置解锁密码 16 | 4. 在exposed edge里面使用shell执行命令,设置多个定时任务 17 | ``` 18 | fp="你的`蚂蚁森林.js`全路径" 19 | am start -n com.stardust.scriptdroid/.external.open.RunIntentActivity -d file://${fp} -t application/x-javascript 20 | ``` 21 | **注意有的exposed edge版本不支持中文路径那就改成英文路径 22 | 或者像我那样,再新写一个start.js(非中文路径下),里面写上下面的代码, 23 | edge shell命令执行start.js,实现伪支持中文路径** 24 | ```ecmascript 6 25 | engines.execScriptFile("/sdcard/脚本/蚂蚁森林/蚂蚁森林.js"); 26 | ``` 27 | 28 | 5. 如果会使用tasker,把next函数里面的shell发送广播命令取消注释, 29 | 然后在tasker里面添加收到广播事件,循环执行脚本 30 | ![image](https://github.com/start201711/autojs/blob/master/201804/ScreenShot/Screenshot_2018-04-03-19-55-21.jpg) 31 | 32 | ### 蚂蚁庄园脚本 33 | 1. 配置几个固定的点击坐标 34 | 2. 定时执行。。。 35 | 3. 使用tasker最好,exposed edge 不太适合 36 | 37 | ## 非常感谢`龙泽一郎`大佬做的解锁模块!解决了繁琐的解锁问题 38 | 39 | 40 | ##### 更新日志 41 | 42 | - [x] 添加重试功能 43 | - [x] 去掉不必要的root权限检测,自动开启无障碍服务 44 | - [x] 增加SingleScript模块,限制同一时间只能运行一个脚本 45 | - [x] 优化查找能量球的方法,添加能量统计功能 46 | - [x] 如果自己的能量球还剩下1-2分钟,脚本会停留在当前界面,不断点击能量球,直到能量球消失为止 47 | - [ ] 目前captureScreen有可能返回为null,导致异常,期待autojs开发者的修复。 48 | #### 一切都在慢慢完善中…… 49 | -------------------------------------------------------------------------------- /201804/start.js: -------------------------------------------------------------------------------- 1 | engines.execScriptFile("/sdcard/脚本/蚂蚁森林/蚂蚁森林.js"); -------------------------------------------------------------------------------- /201804/take.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/start201711/autojs/880563261cd250c4d61ec97fe16fe53d28fd477e/201804/take.png -------------------------------------------------------------------------------- /201804/unlock.js: -------------------------------------------------------------------------------- 1 | /** 2 | * 欢迎使用和提交bug反馈 3 | * 设备要求: 4 | * 1.需要root(脚本用到唤醒、截图、点击等权限) 5 | * 2.安卓5.0以上 6 | * 3.Auto.js软件版本3.0以上 7 | * 8 | * 使用方法: 9 | * 1.将take.png(找图所需,仅适用于1920*1080屏幕。其它机型请自己制作截图,图片应略小于小手范围,10KB以下)、 10 | * config.js(配置文件)、Robot.js(机器人模块)、Secure.js(解锁模块,可选)、蚂蚁森林设置向导.js 与脚本放置于同目录下,一般为/storage/emulated/0/脚本/ 11 | * 2.将“蚂蚁森林”按钮设置在支付宝首页,方便查找控件 12 | * 3.运行蚂蚁森林设置向导.js,修改个性化配置。支持的解锁方式(仅限类原生系统,如LineageOS、Mokee):滑动(5.0+)、PIN码(5.0+)、密码(5.0+)、 13 | * 图案(7.0+,将点转换为数字即可,布局参考9宫格数字键盘) 14 | * 4.直接在软件里面运行脚本即可,不用手动打开支付宝。建议先手动运行一次,成功之后再配置定时任务 15 | * 5.申请截图的权限时,不需要手动点击"立即开始",脚本会自行点击"立即开始" 16 | * 6.脚本运行时,可以按音量上键停止运行 17 | * 18 | * 定时任务(建议)步骤: 19 | * 1.安装edge pro软件 20 | * 2.添加多重动作,假设命名为蚂蚁森林。假设脚本路径是/storage/emulated/0/脚本/蚂蚁森林.js 21 | * 动作的第一步是唤醒,第二步是shell命令,参考 22 | * am start -n com.stardust.scriptdroid/.external.open.RunIntentActivity -d file:///storage/emulated/0/脚本/蚂蚁森林.js -t application/x-javascript 23 | * 3.添加定时计划,动作是保存的多重动作 24 | * 4.若该机型不能正常解锁,可以使用edge录制手势解决,建议步骤:1.唤醒 2.延时 3.注入手势 4.延时 5.shell命令 25 | * 5.定时收自己的能量可以适当提前,有剩余能量球的时候,脚本会持续检测(默认1分钟) 26 | * 27 | * 软件测试结果: 28 | * 1.魔趣7.1系统正常,偶尔出现崩溃情况,依赖于Auto.js.apk稳定性 29 | * @author ridersam 30 | */ 31 | 32 | //sleep(3000); 33 | auto(); // 自动打开无障碍服务 34 | 35 | let options = require("./config.js"); 36 | 37 | // 所有操作都是竖屏 38 | 39 | //start(options); 40 | 41 | /** 42 | * 开始运行 43 | * @param options 44 | */ 45 | function start(options) { 46 | let isScreenOn = device.isScreenOn(); // 屏幕是否点亮 47 | if (!isScreenOn) { 48 | log("唤醒"); 49 | device.wakeUp(); 50 | sleep(500); 51 | } 52 | this.checkModule(); 53 | 54 | let Robot = require("./Robot.js"); 55 | let robot = new Robot(options.max_retry_times); 56 | 57 | 58 | let Secure = require("./Secure.js"); 59 | let secure = new Secure(robot, options.max_retry_times); 60 | secure.openLock(options.password, options.pattern_size); 61 | } 62 | 63 | /** 64 | * 检查必要模块 65 | */ 66 | function checkModule() { 67 | if (!files.exists("Robot.js")) { 68 | throw new Error("缺少Robot.js文件,请核对第一条"); 69 | } 70 | 71 | if (!files.exists("Secure.js") && context.getSystemService(context.KEYGUARD_SERVICE).inKeyguardRestrictedInputMode()) { 72 | throw new Error("缺少Secure.js文件,请核对第一条"); 73 | } 74 | } 75 | 76 | module.exports = function() { 77 | 78 | sleep(3000); 79 | start(options); 80 | }; -------------------------------------------------------------------------------- /201804/投食.js: -------------------------------------------------------------------------------- 1 | const pkg = "com.eg.android.AlipayGphone"; 2 | const max_try_count = 5; //最大尝试次数 3 | const max_run_time = 100 * 1000; //脚本运行最长时间 4 | let single = require("SingleScript"); 5 | single.enqueue(); 6 | let enable = require("enable"); 7 | let unlock = require("unlock"); 8 | enable(); 9 | unlock(); 10 | 11 | let Script = require("Script"); 12 | let script = new Script(); 13 | 14 | main(); 15 | exit(); 16 | 17 | 18 | function main() { 19 | prepare(); 20 | doSth(); 21 | } 22 | 23 | function prepare() { 24 | events.observeKey(); 25 | events.onceKeyDown("volume_up", function () { 26 | toastLog("脚本停止运行"); 27 | exit(); 28 | }); 29 | toastLog("即将收进行投食任务,请勿操作\n按音量上键键停止脚本"); 30 | shell("pm enable " + pkg, true); 31 | threads.start(function () { 32 | if (max_run_time <= 0) { 33 | return; 34 | } 35 | let run_time = 0; 36 | while (run_time++ < max_run_time) { 37 | sleep(1000); 38 | } 39 | exit(); 40 | }); 41 | 42 | let tryCount = 0; 43 | while (tryCount++ < max_try_count) { 44 | launch(pkg); 45 | if (into()) { 46 | break; 47 | } else { 48 | shell("am force-stop " + pkg, true); 49 | sleep(2000); 50 | } 51 | } 52 | 53 | if (tryCount >= max_try_count) { 54 | log("已尝试" + tryCount + "次,不再重试"); 55 | exit(); 56 | } 57 | } 58 | 59 | function doSth() { 60 | for (let i = 0; i < 2; i++) { 61 | //这里需要设置投食按钮的位置 62 | script.press(595, 1150, 20); 63 | sleep(50); 64 | } 65 | log("投食完毕"); 66 | sleep(3000); 67 | shell("am force-stop " + pkg, true); 68 | toastLog("本轮完毕!"); 69 | sleep(3000); 70 | } 71 | 72 | 73 | function into() { 74 | let w = id("com.alipay.android.phone.openplatform:id/app_text").text("蚂蚁庄园").findOne(8000); 75 | return w && w.parent() && w.parent().click() && desc("星星球").findOne(20 * 1000); 76 | } -------------------------------------------------------------------------------- /201804/蚂蚁森林.js: -------------------------------------------------------------------------------- 1 | const pkg = "com.eg.android.AlipayGphone"; 2 | const max_try_count = 5; //最大尝试次数 3 | const max_run_time = 200 * 1000; //脚本运行最长时间 4 | let single = require("SingleScript"); 5 | single.enqueue(); 6 | sleep(1000); 7 | let enable = require("enable"); 8 | let unlock = require("unlock"); 9 | enable(); 10 | unlock(); 11 | 12 | 13 | const _path = "take.png"; 14 | if (!files.exists(_path)) { 15 | throw new java.lang.Exception("小手图片不存在"); 16 | } 17 | const temp = images.read(_path); 18 | let Script = require("Script"); 19 | let script = new Script(); 20 | let save = require("SaveXml"); 21 | main(); 22 | exit(); 23 | 24 | function main() { 25 | events.observeKey(); 26 | events.onceKeyDown("volume_up", function () { 27 | toastLog("脚本停止运行"); 28 | exit(); 29 | }); 30 | events.on("exit", function () { 31 | // KeyCode(26);//脚本退出时息屏,如果有此需要,请取消注释 32 | }); 33 | toastLog("即将收取蚂蚁森林能量,请勿操作\n按音量上键停止脚本"); 34 | shell("pm enable " + pkg, true); 35 | threads.start(function () { 36 | if (max_run_time <= 0) { 37 | return; 38 | } 39 | let run_time = 0; 40 | while (run_time++ < max_run_time) { 41 | sleep(1000); 42 | } 43 | exit(); 44 | }); 45 | 46 | let tryCount = 0; 47 | while (tryCount++ < max_try_count) { 48 | launch(pkg); 49 | if (into()) { 50 | break; 51 | } else { 52 | shell("am force-stop " + pkg, true); 53 | sleep(2000); 54 | } 55 | } 56 | 57 | if (tryCount >= max_try_count) { 58 | log("已尝试" + tryCount + "次,不再重试"); 59 | exit(); 60 | } 61 | 62 | toastLog("成功进入蚂蚁森林"); 63 | takeMyself(); 64 | toastLog("开始收取好友能量"); 65 | threads.start(function () { 66 | let btn = classNameContains("Button").textMatches("立即开始|START NOW").findOne(10 * 1000); 67 | btn ? btn.click() : false; 68 | }); 69 | if (!requestScreenCapture()) { 70 | exit(); 71 | } 72 | takeOthers(); 73 | while (!idContains("J_rank_list_more").click()) ; 74 | if (idContains("J_rank_list_self").findOne(10 * 1000)) { 75 | toastLog("开始收取更多好友的能量"); 76 | takeOthers(); 77 | next(); 78 | } else { 79 | log("进入更多好友失败"); 80 | } 81 | desc("返回").click(); 82 | sleep(500); 83 | desc("返回").click(); 84 | toastLog("收取能量结束"); 85 | } 86 | 87 | function takeOthers() { 88 | while (1) { 89 | let p; 90 | while (p = findImage(captureScreen(), temp)) { 91 | script.press(device.width / 2, p.y + 0.8 * temp.getHeight()); 92 | try { 93 | takeOther(); 94 | } catch (e) { 95 | log(e); 96 | } 97 | idContains("h5_tv_nav_back").click(); 98 | sleep(1000); 99 | } 100 | let end = idContains("J_rank_list_more").find(); 101 | if (!end.empty() && end.get(0).bounds().top < device.height) { 102 | break; 103 | } 104 | scrollable(true).className("android.webkit.WebView").scrollForward(); 105 | sleep(2000); 106 | } 107 | } 108 | 109 | 110 | function takeOther() { 111 | desc("浇水").findOne(5000); 112 | let cover = descMatches(/\d{2}:\d{2}:\d{2}/).find(); 113 | if (!cover.empty()) { 114 | log("保护罩还剩" + cover.get(0).desc() + ",忽略"); 115 | return; 116 | } 117 | let start = getEnergy(); 118 | take(); 119 | sleep(1200); 120 | let end = getEnergy(); 121 | let title = idContains("h5_tv_title").findOne(2000); 122 | title = title ? title.text() : null; 123 | log("收取了" + title + (end - start) + "g能量") 124 | } 125 | 126 | function takeMyself() { 127 | desc("攻略").findOne(5000); 128 | let start = idContains("tree_energy").findOne(2000); 129 | take(); 130 | let selector = descMatches("还剩\n?00:0[12]"); 131 | let wait; 132 | let m; 133 | while (m = selector.findOne(500)) { 134 | log(m.bounds()); 135 | script.pressCenter(m); 136 | wait = true; 137 | } 138 | if (wait) { 139 | take(); 140 | } 141 | sleep(500); 142 | let end = idContains("tree_energy").findOne(2000); 143 | try { 144 | let ei = parseInt(end.desc().match(/\d+/)[0]); 145 | let si = parseInt(start.desc().match(/\d+/)[0]); 146 | log("收取了自己" + (ei - si) + "g能量"); 147 | } catch (e) { 148 | log(e); 149 | } 150 | } 151 | 152 | function getEnergy() { 153 | try { 154 | let sl = descMatches(/\d+g/) 155 | .filter(function (o) { 156 | return o.bounds().centerX() > device.width / 2; 157 | }); 158 | let a = idContains("J_friend_pk_wrap") 159 | .findOne(5000) 160 | .findOne(sl); 161 | return parseInt(a.desc().match(/\d+/)[0]); 162 | } catch (e) { 163 | log(e); 164 | return NaN; 165 | } 166 | } 167 | 168 | function take() { 169 | let c = idContains("J_bubbles_wrap") 170 | .findOne(5000) 171 | .find(descMatches("绿色\n?能量|\\d+g")); 172 | toastLog("找到" + c.size() + "个能量球"); 173 | c.each(function (o) { 174 | script.pressCenter(o); 175 | sleep(500); 176 | }); 177 | } 178 | 179 | function into() { 180 | let w = id("com.alipay.android.phone.openplatform:id/app_text").text("蚂蚁森林").findOne(8000); 181 | return w && w.parent() && w.parent().click() && desc("攻略").findOne(20 * 1000); 182 | } 183 | 184 | function next() { 185 | let time = new Date().getHours(); 186 | let min = 60; 187 | if (time > 6) { 188 | let d = descMatches(/\d+’/).find(); 189 | d.each(function (o) { 190 | let value = parseInt(o.desc().match(/\d+/)[0]); 191 | min = Math.min(min, value); 192 | }); 193 | log("距离下一次收取还有" + min + "分钟"); 194 | //shell("am broadcast -function.js autojs.next.time --es next " + min, true); 195 | } 196 | return min; 197 | } -------------------------------------------------------------------------------- /201804/驱赶.js: -------------------------------------------------------------------------------- 1 | const pkg = "com.eg.android.AlipayGphone"; 2 | const max_try_count = 5; //最大尝试次数 3 | const max_run_time = 100 * 1000; //脚本运行最长时间 4 | let single = require("SingleScript"); 5 | single.enqueue(); 6 | let enable = require("enable"); 7 | let unlock = require("unlock"); 8 | enable(); 9 | unlock(); 10 | 11 | let Script = require("Script"); 12 | let script = new Script(); 13 | 14 | main(); 15 | exit(); 16 | 17 | 18 | function main() { 19 | prepare(); 20 | doSth(); 21 | } 22 | 23 | function prepare() { 24 | events.observeKey(); 25 | events.onceKeyDown("volume_up", function () { 26 | toastLog("脚本停止运行"); 27 | exit(); 28 | }); 29 | toastLog("即将进行驱赶任务,请勿操作\n按音量上键键停止脚本"); 30 | shell("pm enable " + pkg, true); 31 | threads.start(function () { 32 | if (max_run_time <= 0) { 33 | return; 34 | } 35 | let run_time = 0; 36 | while (run_time++ < max_run_time) { 37 | sleep(1000); 38 | } 39 | exit(); 40 | }); 41 | 42 | let tryCount = 0; 43 | while (tryCount++ < max_try_count) { 44 | launch(pkg); 45 | if (into()) { 46 | break; 47 | } else { 48 | shell("am force-stop " + pkg, true); 49 | sleep(2000); 50 | } 51 | } 52 | 53 | if (tryCount >= max_try_count) { 54 | log("已尝试" + tryCount + "次,不再重试"); 55 | exit(); 56 | } 57 | } 58 | 59 | function doSth() { 60 | //这里需要设置偷吃东西的两只鸡的位置 61 | for (let i = 0; i < 10; i++) { 62 | script.press(218, 851, 100); 63 | sleep(500); 64 | script.press(518, 851, 100); 65 | sleep(500); 66 | } 67 | sleep(3000); 68 | shell("am force-stop " + pkg, true); 69 | toastLog("本轮完毕!"); 70 | sleep(3000); 71 | exit(); 72 | 73 | } 74 | 75 | 76 | function into() { 77 | let w = id("com.alipay.android.phone.openplatform:id/app_text").text("蚂蚁庄园").findOne(8000); 78 | return w && w.parent() && w.parent().click() && desc("星星球").findOne(20 * 1000); 79 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # autojs 2 | ![效果图](https://github.com/start201711/autojs/blob/master/201804/ScreenShot/Screenshot_2018-04-03-20-01-34.jpg) 3 | -------------------------------------------------------------------------------- /take.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/start201711/autojs/880563261cd250c4d61ec97fe16fe53d28fd477e/take.png -------------------------------------------------------------------------------- /take720p.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/start201711/autojs/880563261cd250c4d61ec97fe16fe53d28fd477e/take720p.png -------------------------------------------------------------------------------- /update.js: -------------------------------------------------------------------------------- 1 | //简单说明:这个是用于检查更新的,直接使用即可。 2 | 3 | var url = "https://raw.githubusercontent.com/start201711/autojs/master/%E8%84%9A%E6%9C%AC.js"; 4 | 5 | var js = http.get(url).body.string(); 6 | 7 | js.match(/最后修改于:(.*?)\n/g); 8 | var ret = RegExp.$1; 9 | log(ret); 10 | 11 | if (confirm("蚂蚁森林自动收能量脚本最后更新于\n" + ret + "\n你需要更新吗?")) { 12 | setClip(js); 13 | alert("最新脚本已复制到剪贴板,粘贴即可使用"); 14 | } 15 | -------------------------------------------------------------------------------- /收取更多好友的能量.js: -------------------------------------------------------------------------------- 1 | //转载请注明来自酷安用户@群主让我注册 2 | //根据此代码修改,请注明根据酷安@群主让我注册 修改 3 | //注意,脚本随时更新,记得经常来看看脚本是不是又更新了 4 | //脚本下载地址:https://github.com/start201711/autojs?files=1 5 | //软件下载地址:https://github.com/hyb1996/Auto.js/releases 6 | //设备要求:需要root或者安卓7.0以上,以及autojs软件版本3.0版本以上才能使用 7 | //使用方法: 8 | //1.准备工作:只需要一张小图片 9 | //即:可以收取好友能量的时候,好友右上角那个绿色的小手图像,只要能包括绿色小手的图像就行, 10 | //不能使用大的图像,命名为take.png,放在sdcard根目录下 11 | //2.直接运行脚本即可,不用点自己打开支付宝。(一般的话,设置为定时脚本,每天定时执行,无需看护!!) 12 | //3.如果手机没有解锁屏幕,是运行不了的。所以需要自己想办法解锁屏幕。 13 | // 如果会写解锁屏幕代码,请自行编写解锁模块的代码(本文最后有示例);如果不会写解锁屏幕代码,请勿设置手机锁屏密码; 14 | //4.申请截图的权限时,不需要手动点击"立即开始",脚本会自行点击"立即开始"。 15 | //5.这里内置两种抓取能量球的方式,可以互换使用。 16 | //6.由于我只有5.1系统的手机,我也不知道在不同版本的手机的press和swipe函数效果如何,这个碰上了再解决吧。 17 | //7.建议第一次使用本脚本的时候,打开开发者模式的显示指针位置和触摸操作,可以直观的看到整个收取能量过程 18 | //8.本脚本可以配合tasker或者exposed edge的定时任务使用。 19 | // 可能在7.0上面滑动没有那么"自然" 20 | // 21 | //最后修改于:2018-4-12 22 | //修改说明: 23 | // 2018-01-11 12:28:29 24 | // 1.添加一个例外情况(绿色能量) 25 | // 2.修改流程使之更完善,现在基本上没有问题了 26 | // 2018-01-11 23:16:25 27 | // 1.不再需要结束图片 28 | // 2018-01-13 12:45:21 29 | // 1.将click换成press 30 | // 2.如果没有take.png将尝试下载远程的图像 31 | // 3.添加root权限检查 32 | // 4.对于已root设备,将会使用shell命令强制开启autojs的无障碍服务 33 | // 2018-01-13 20:38:14 34 | // 1.添加两种分辨率 35 | // 2.增加默认的按压时间,由50改为100 36 | // 2018-01-14 11:28:32 37 | // 1.添加进森林的兼容方案 38 | // 2.新发现部分人的swipe、press没用,这个我也无能为力了 39 | // 2018-01-23 01:40:57 40 | // 1.添加进入更多好友的代码 41 | // 2.发现更多的问题。。。。 42 | // 2018-02-02 00:00:16 43 | // 1.尝试修复部分手机不点击、不滑动的bug。 44 | // 2.关闭调试 45 | // 3.修复路径问题。 46 | // 2018-4-12 47 | // 适应支付宝的改动 48 | var isAuthor = false; //如果你不是作者,这里务必为false,不然各种报错。 49 | var debug = false; //开启调试,会截图保存到本地 50 | var useShell = false; //使用shell命令执行模拟输入tap、swipe动作。如果你的滑动不了或者点能量球点不了,测试把它改为true 51 | var debug_dir = "/sdcard/debug/take/"; 52 | if (debug) { 53 | files.ensureDir(debug_dir); 54 | } 55 | 56 | //检测手机是否已root,如果root,下面的代码会自动开启autojs的无障碍服务!!! 57 | if (isRoot()) { 58 | var s = shell("settings get secure enabled_accessibility_services", true).result.replace(/\n/, ""); 59 | log(s); 60 | if (s.indexOf("stardust") == "-1") { 61 | var stardust = "com.stardust.scriptdroid/com.stardust.scriptdroid.accessibility.AccessibilityService"; 62 | var code = shell("settings put secure enabled_accessibility_services " + s + ":" + stardust, true).code; 63 | if (code) { 64 | toastLog("尝试开启无障碍服务异常"); 65 | } 66 | } 67 | shell("settings put secure accessibility_enabled 1", true); 68 | } 69 | 70 | if (isAuthor) { 71 | var unlock = require("unlock"); //解锁模块 72 | unlock(); 73 | shell("pm enable com.eg.android.AlipayGphone", true); 74 | } else { 75 | //请自己想办法让手机屏幕解锁可以进行操作 76 | device.wakeUp(); 77 | } 78 | 79 | sleep(3000); 80 | var temp = images.read("/sdcard/take.png"); 81 | 82 | if (!temp) { 83 | toastLog("缺少图片文件,请仔细查看\n使用方法的第一条!!!"); 84 | switch (device.width) { 85 | case 1080: 86 | temp = images.load("https://raw.githubusercontent.com/start201711/autojs/master/take.png"); 87 | break; 88 | case 720: 89 | temp = images.load("https://raw.githubusercontent.com/start201711/autojs/master/take720p.png"); 90 | break; 91 | default: 92 | temp = null; 93 | break; 94 | } 95 | 96 | if (!temp) { 97 | toastLog("尝试下载take.png失败,脚本停止运行"); 98 | exit(); 99 | } 100 | toastLog("现在将尝试使用别人的图片,分辨率可能不匹配,脚本可能无法正常执行"); 101 | } 102 | var r = new Robot(); 103 | var dh = 40 * device.height / 720; 104 | 105 | 106 | //向系统申请截图时,自动确认 107 | new java.lang.Thread(function() { 108 | classNameContains("Button").textContains("立即开始").click(); 109 | }).start(); 110 | 111 | 112 | if (!requestScreenCapture()) { 113 | toast("请求截图失败,脚本退出"); 114 | exit(); 115 | } 116 | toastLog("即将收取蚂蚁森林能量,请勿操作!"); 117 | 118 | launch("com.eg.android.AlipayGphone"); 119 | waitForPackage("com.eg.android.AlipayGphone"); 120 | 121 | //有人说进不去森林,但是查看布局分析是没问题的 122 | //这里使用一个兼容的办法clickSenlin(); 123 | //如果你的进不去,你可以把下面的这句换成while (!click("蚂蚁森林")); 124 | //如果还不行,你换成r.press(x,y);//x,y是需要点击的森林的位置。 125 | //如果再不行,那你换成Tap(x,y);//x,y是需要点击的森林的位置。 126 | //如果再再不行,那就shell("input tap x y");//x,y是需要点击的森林的位置。 127 | //如果再再再不行,去支付宝充把火麒麟就好了(#滑稽) 128 | clickSenlin(); //兼容方法 129 | 130 | 131 | className("android.widget.Button").desc("攻略").waitFor(); 132 | toastLog("成功进入蚂蚁森林"); 133 | sleep(3000); 134 | 135 | 136 | takeMyself(); 137 | toastLog("收取自己的能量完毕"); 138 | sleep(2000); 139 | 140 | takeInRank(); 141 | toastLog("收取更多好友的能量"); 142 | sleep(2000); 143 | 144 | 145 | //通知tasker下一次运行脚本的时间,全天候自动挂机 146 | if (isAuthor) { 147 | var loop = require("loop"); 148 | loop(); //将等待下一次时间写入文件中给tasker 149 | sleep(2000); 150 | } 151 | 152 | var more = descContains("查看更多好友").findOne(); 153 | 154 | r.pressCenter(more); 155 | 156 | sleep(5000); 157 | takeMore(); 158 | toastLog("收取能量完毕"); 159 | idContains("h5_tv_nav_back").click(); 160 | sleep(2000); 161 | idContains("h5_tv_nav_back").click(); 162 | 163 | 164 | if (isAuthor) { 165 | shell("pm disable com.eg.android.AlipayGphone", true); 166 | } 167 | exit(); 168 | 169 | /******************收取能量函数********************/ 170 | 171 | 172 | function takeInRank() { 173 | takeOthers("爱心捐赠"); 174 | } 175 | 176 | 177 | function takeMore() { 178 | takeOthers("没有更多了") 179 | } 180 | 181 | function takeOthers(end) { 182 | while (1) { 183 | for (var p = findImage(captureScreen(), temp); p; p = findImage(captureScreen(), temp)) { 184 | if (debug) { 185 | toastLog("进入好友的森林"); 186 | } 187 | r.press(device.width / 2, p.y + dh, 100); 188 | takeOther(); 189 | sleep(1000); 190 | idContains("h5_tv_nav_back").click(); 191 | sleep(2000); 192 | } 193 | if (debug) { 194 | images.captureScreen(debug_dir + new Date().getTime() + ".png"); 195 | } 196 | 197 | if (descContains(end).find().size() > 0) { 198 | if (descContains(end).findOne().bounds().top < device.height) { 199 | break; 200 | } 201 | 202 | } 203 | r.swipe(device.width / 2, device.height * 2 / 3, device.width / 2, device.height * 1 / 3); 204 | 205 | sleep(2000); 206 | } 207 | 208 | } 209 | 210 | function takeMyself() { 211 | 212 | take("攻略"); 213 | } 214 | 215 | function takeOther() { 216 | 217 | take("浇水"); 218 | } 219 | 220 | function take(desc) { 221 | var right_bottom = className("android.widget.Button").desc(desc).findOne(); 222 | log(right_bottom); 223 | var left_top = descContains("返回").findOne(); 224 | log(left_top); 225 | 226 | var filtes = []; 227 | var left = 0; 228 | var right = device.width; 229 | var top = left_top.bounds().bottom; 230 | var bottom = right_bottom.bounds().top; 231 | 232 | log(left + "-" + top + "-" + right + "-" + bottom); 233 | sleep(2000); 234 | var all = descMatches("^((绿色|收集)能量|\\d+g)$").boundsInside(left, top, right, bottom).untilFind(); 235 | toastLog("找到" + (all.size() - 1) + "个能量球"); 236 | all.each(function(x) { 237 | filtes.push(x); 238 | }); 239 | 240 | filtes.sort(function(o1, o2) { 241 | return distance(o1) - distance(o2); 242 | }); 243 | 244 | if (filtes.length > 0) { 245 | filtes.splice(0, 1); 246 | } 247 | if (debug) { 248 | images.captureScreen(debug_dir + new Date().getTime() + ".png"); 249 | } 250 | for (var i = 0; i < filtes.length; i++) { 251 | r.pressCenter(filtes[i], 100); 252 | sleep(1000); 253 | log("点击->" + filtes[i]); 254 | } 255 | 256 | 257 | function distance(o) { 258 | return Math.pow((o.bounds().top - top), 2) + Math.pow((o.bounds().right - right), 2); 259 | } 260 | } 261 | 262 | function clickSenlin() { 263 | var b = text("蚂蚁森林").findOne().bounds(); 264 | var a = idContains("home_app_view").untilFind().filter(o => { 265 | return o.bounds().contains(b); 266 | }); 267 | while (!a[0].click()); 268 | } 269 | 270 | function Robot() { 271 | var r = null; 272 | if (device.sdkInt < 24) { 273 | if (isRoot()) { 274 | r = new RootAutomator(); 275 | } else { 276 | toastLog("本脚本需要android7.0以上或者已root才能使用"); 277 | exit(); 278 | } 279 | } 280 | var _useShellCmd = useShell; 281 | 282 | this.press = function(x, y, duration) { 283 | if (duration == undefined) { 284 | duration = 100; 285 | } 286 | if (r == null) { 287 | press(x, y, duration); 288 | } else if (_useShellCmd) { 289 | Swipe(x, y, x, y, duration); 290 | } else { 291 | r.press(x, y, duration); 292 | } 293 | } 294 | 295 | this.pressCenter = function(obj, duration) { 296 | this.press(obj.bounds().centerX(), obj.bounds().centerY(), duration); 297 | } 298 | this.swipe = function(x1, y1, x2, y2, duration) { 299 | if (duration == undefined) { 300 | duration = 200; 301 | } 302 | if (r == null) { 303 | swipe(x1, y1, x2, y2, duration); 304 | } else if (_useShellCmd) { 305 | Swipe(x1, y1, x2, y2, duration); 306 | } else { 307 | r.swipe(x1, y1, x2, y2, duration); 308 | } 309 | } 310 | } 311 | 312 | 313 | 314 | function isRoot() { 315 | var bool = false; 316 | try { 317 | bool = new java.io.File("/system/bin/su").exists() || new java.io.File("/system/xbin/su").exists(); 318 | } catch (e) { 319 | print(e); 320 | } 321 | return bool; 322 | } 323 | 324 | 325 | 326 | /*******************解锁模块代码实例,我把自己的代码乱改***********************/ 327 | //下面的代码放另一个文件里面 328 | // function unlock() { 329 | // var pm = context.getSystemService(context.POWER_SERVICE); 330 | // var b = pm.isScreenOn(); 331 | // if (!b) { 332 | // unlock0(); 333 | // } 334 | // } 335 | 336 | // function unlock0() { 337 | // "root"; 338 | // device.wakeUp(); 339 | // sleep(3000); 340 | // var ra = new Robot(); 341 | // ra.swipe(760, 1000, 360, 750); 342 | // sleep(1000); 343 | // ra.press(650, 450); 344 | // sleep(1000); 345 | // ra.press(650, 350); 346 | // sleep(1000); 347 | // ra.press(160, 750); 348 | // sleep(1000) 349 | // ra.press(760, 360); 350 | // sleep(2000); 351 | // } 352 | 353 | 354 | // module.exports = unlock; 355 | -------------------------------------------------------------------------------- /脚本.js: -------------------------------------------------------------------------------- 1 | //转载请注明来自酷安用户@群主让我注册 2 | //根据此代码修改,请注明根据酷安@群主让我注册 修改 3 | //注意,脚本随时更新,记得经常来看看脚本是不是又更新了 4 | //下载地址:https://github.com/start201711/autojs?files=1 5 | //设备要求:需要root或者安卓7.0以上,以及autojs软件版本3.0版本以上才能使用 6 | //使用方法: 7 | //1.准备工作:只需要一张小图片 8 | //即:好友的列表右上角的绿色的小图标,命名为take.png,放在sdcard根目录下 9 | //2.直接启动脚本即可,不用点自己打开支付宝。(一般的话,设置为定时脚本,每天定时执行,无需看护!!) 10 | //3.如果手机没有解锁屏幕,是运行不了的。所以需要自己想办法解锁屏幕。 11 | // 如果会写解锁屏幕代码,请自行编写解锁模块的代码(本文最后有示例);如果不会写解锁屏幕代码,请勿设置手机锁屏密码; 12 | //4.申请截图的权限时,不需要手动点击"立即开始",脚本会自行点击"立即开始"。 13 | //5.这里内置两种抓取能量球的方式,可以互换使用。 14 | //6.由于我只有5.1系统的手机,我也不知道在不同版本的手机的click和swipe函数效果如何,这个碰上了再解决吧。 15 | // 可能在7.0上面的没有那么"自然" 16 | //最后修改于:2018-4-12 17 | //修改说明: 18 | // 2018-01-11 12:28:29 19 | // 添加一个例外情况(绿色能量) 20 | // 修改流程使之更完善,现在基本上没有问题了 21 | // 2018-01-11 23:16:25 22 | // 不再需要结束图片 23 | // 2018-02-02 23:54:44 24 | // 1.关闭调试,避开软件新版本的错误 25 | // 2.修复路径问题 26 | // 2018-4-12 27 | // 适应支付宝的改动 28 | var isMyself = false; 29 | var debug = false; 30 | 31 | var debug_dir = "/sdcard/debug/take/"; 32 | if (debug) { 33 | files.ensureDir(debug_dir); 34 | } 35 | if (isMyself) { 36 | var unlock = require("unlock"); //解锁模块 37 | unlock(); 38 | shell("pm enable com.eg.android.AlipayGphone", true); 39 | } else { 40 | device.wakeUp(); //这种方式请勿设置锁屏密码 41 | } 42 | 43 | sleep(3000); 44 | var temp = images.read("/sdcard/take.png"); 45 | 46 | if (temp == null) { 47 | toastLog("缺少图片文件,请仔细查看使用方法的第一条!!!"); 48 | exit(); 49 | } 50 | var r = new Robot(); 51 | var dh = 40 * device.height / 720; 52 | 53 | 54 | new java.lang.Thread(function() { 55 | 56 | classNameContains("Button").textContains("立即开始").click(); 57 | }).start(); 58 | 59 | 60 | if (!requestScreenCapture()) { 61 | toast("请求截图失败"); 62 | exit(); 63 | } 64 | toastLog("即将收取蚂蚁森林能量,请勿操作!"); 65 | 66 | launch("com.eg.android.AlipayGphone"); 67 | waitForPackage("com.eg.android.AlipayGphone"); 68 | while (!click("蚂蚁森林")); 69 | className("android.widget.Button").desc("攻略").waitFor(); 70 | toastLog("成功进入蚂蚁森林"); 71 | sleep(3000); 72 | 73 | 74 | takeMyself2(); 75 | toastLog("收取自己的能量完毕"); 76 | sleep(3000); 77 | 78 | 79 | while (1) { 80 | for (var p = findImage(captureScreen(), temp); p; p = findImage(captureScreen(), temp)) { 81 | r.click(p.x, p.y + dh); 82 | takeOther2(); 83 | sleep(2000); 84 | idContains("h5_tv_nav_back").click(); 85 | sleep(3000); 86 | } 87 | 88 | if (descContains("爱心捐赠").classNameContains("android.widget.Image").findOne().bounds().top < device.height) { 89 | break; 90 | } 91 | r.swipe(device.width / 2, device.height * 2 / 3, device.width / 2, device.height * 1 / 3); 92 | sleep(3000); 93 | } 94 | 95 | 96 | toastLog("收取能量完毕"); 97 | idContains("h5_tv_nav_back").click(); 98 | if (isMyself) { 99 | shell("pm disable com.eg.android.AlipayGphone", true); 100 | } 101 | exit(); 102 | 103 | /******************收取能量函数********************/ 104 | 105 | 106 | function takeMyself2() { 107 | 108 | take("攻略"); 109 | } 110 | 111 | function takeOther2() { 112 | 113 | take("浇水"); 114 | } 115 | 116 | function take(desc) { 117 | var right_bottom = className("android.widget.Button").desc(desc).findOne(); 118 | log(right_bottom); 119 | var left_top = descContains("返回").findOne(); 120 | log(left_top); 121 | 122 | var filtes = []; 123 | var left = 0; 124 | var right = device.width; 125 | var top = left_top.bounds().bottom; 126 | var bottom = right_bottom.bounds().top; 127 | 128 | log(left + "-" + top + "-" + right + "-" + bottom); 129 | sleep(2000); 130 | var all = descMatches("^((绿色|收集)能量|\\d+g)$").boundsInside(left, top, right, bottom).untilFind(); 131 | toastLog("找到" + (all.size() - 1) + "个能量球"); 132 | all.each(function(x) { 133 | filtes.push(x); 134 | }); 135 | 136 | filtes.sort(function(o1, o2) { 137 | return distance(o1) - distance(o2); 138 | }); 139 | 140 | if (filtes.length > 0) { 141 | filtes.splice(0, 1); 142 | } 143 | if (debug) { 144 | images.captureScreen(debug_dir + new Date().getTime() + ".png"); 145 | } 146 | for (var i = 0; i < filtes.length; i++) { 147 | //原有的click无效 148 | r.clickCenter(filtes[i], 100); 149 | sleep(2000); 150 | log("点击->" + filtes[i]); 151 | } 152 | 153 | 154 | function distance(o) { 155 | return Math.pow((o.bounds().top - top), 2) + Math.pow((o.bounds().right - right), 2); 156 | } 157 | } 158 | 159 | 160 | 161 | function Robot() { 162 | var r = null; 163 | if (device.sdkInt < 24) { 164 | r = new RootAutomator(); 165 | } 166 | 167 | this.click = function(x, y, duration) { 168 | if (duration == undefined) { 169 | duration = 50; 170 | } 171 | if (r == null) { 172 | press(x, y, duration); 173 | } else { 174 | r.touchDown(x, y); 175 | sleep(duration); 176 | r.touchUp(); 177 | } 178 | } 179 | this.clickCenter = function(b, duration) { 180 | this.click(b.bounds().centerX(), b.bounds().centerY(), duration); 181 | } 182 | this.swipe = function(x1, y1, x2, y2, duration) { 183 | if (duration == undefined) { 184 | duration = 200; 185 | } 186 | if (r == null) { 187 | swipe(x1, y1, x2, y2, duration); 188 | } else { 189 | var n = 30; 190 | var dx = (x2 - x1) / n; 191 | var dy = (y2 - y1) / n; 192 | var xc = 0; 193 | var yc = 0; 194 | r.touchDown(x1, y1); 195 | for (var i = 0; i < n; i++) { 196 | r.touchMove(x1 + xc, y1 + yc); 197 | xc += 6 * dx * i * (n - i) / Math.pow(n, 2); 198 | yc += 6 * dy * i * (n - i) / Math.pow(n, 2); 199 | sleep(duration / n); 200 | } 201 | r.touchUp(); 202 | } 203 | } 204 | } 205 | 206 | 207 | /**********************应该会废弃下面的方法**************************/ 208 | 209 | // var a = descContains("线下支付").find(); 210 | // if (a) { 211 | // toastLog("能量球个数1:" + a.size()); 212 | // a.each(function(x) { 213 | // log(x.bounds()); 214 | // r.click(x.bounds().centerX(), x.bounds().centerY() - dh); 215 | // }); 216 | // } 217 | // var b = descContains("行走").find(); 218 | // if (b) { 219 | // log("能量球个数2:" + b.size()); 220 | // b.each(function(x) { 221 | // toastLog(x.bounds()); 222 | // r.click(x.bounds().centerX(), x.bounds().centerY() - dh); 223 | // }); 224 | // } 225 | 226 | // //todo 需要添加更多的情况 227 | // } 228 | 229 | // function takeOther() { 230 | // className("android.widget.Button").desc("浇水").waitFor(); 231 | // sleep(3000); 232 | // var a = descContains("  可收取").find(); 233 | // if (a) { 234 | // toastLog("能量球个数:" + a.size()); 235 | // a.each(function(x) { 236 | // toastLog(x.bounds()); 237 | // r.click(x.bounds().centerX(), x.bounds().centerY() - dh); 238 | // sleep(1000); 239 | // }); 240 | // } 241 | // } 242 | 243 | 244 | 245 | /*******************解锁模块代码实例,我把自己的代码乱改***********************/ 246 | //下面的代码放另一个文件里面 247 | // function unlock() { 248 | // var pm = context.getSystemService(context.POWER_SERVICE); 249 | // var b = pm.isScreenOn(); 250 | // if (!b) { 251 | // unlock0(); 252 | // } 253 | // } 254 | 255 | // function unlock0() { 256 | // "root"; 257 | // device.wakeUp(); 258 | // sleep(3000); 259 | // var ra = new Robot(); 260 | // ra.swipe(760, 1000, 360, 750); 261 | // sleep(1000); 262 | // ra.click(650, 450); 263 | // sleep(1000); 264 | // ra.click(650, 350); 265 | // sleep(1000); 266 | // ra.click(160, 750); 267 | // sleep(1000) 268 | // ra.click(760, 360); 269 | // sleep(2000); 270 | // }  271 | 272 | // module.exports = unlock; 273 | -------------------------------------------------------------------------------- /蚂蚁森林收能量exposed edge 版本.js: -------------------------------------------------------------------------------- 1 | //转载请注明来自酷安用户@群主让我注册 2 | //根据此代码修改,请注明根据酷安@群主让我注册 修改 3 | //注意,脚本随时更新,记得经常来看看脚本是不是又更新了 4 | //脚本下载地址:https://github.com/start201711/autojs?files=1 5 | //设备要求:需要root或者安卓7.0以上,以及autojs软件版本3.0版本以上才能使用 6 | //使用方法: 7 | //1.准备工作:只需要一张小图片 8 | //即:可以收取好友能量的时候,好友右上角那个绿色的小手图像,只要能包括绿色小手的图像就行, 9 | //不能使用大的图像,命名为take.png,放在sdcard根目录下 10 | //2.直接运行脚本即可,不用点自己打开支付宝。(一般的话,设置为定时脚本,每天定时执行,无需看护!!) 11 | //3.如果手机没有解锁屏幕,是运行不了的。所以需要自己想办法解锁屏幕。 12 | // 如果会写解锁屏幕代码,请自行编写解锁模块的代码(本文最后有示例);如果不会写解锁屏幕代码,请勿设置手机锁屏密码; 13 | //4.申请截图的权限时,不需要手动点击"立即开始",脚本会自行点击"立即开始"。 14 | //5.这里内置两种抓取能量球的方式,可以互换使用。 15 | //6.由于我只有5.1系统的手机,我也不知道在不同版本的手机的press和swipe函数效果如何,这个碰上了再解决吧。 16 | //7.建议第一次使用本脚本的时候,打开开发者模式的显示指针位置和触摸操作,可以直观的看到整个收取能量过程 17 | //8.本脚本可以配合tasker或者exposed edge的定时任务使用。 18 | // 可能在7.0上面滑动没有那么"自然" 19 | // 20 | //最后修改于:2018-4-12 21 | //修改说明: 22 | // 2018-01-11 12:28:29 23 | // 1.添加一个例外情况(绿色能量) 24 | // 2.修改流程使之更完善,现在基本上没有问题了 25 | // 2018-01-11 23:16:25 26 | // 1.不再需要结束图片 27 | // 2018-01-13 12:45:21 28 | // 1.将click换成press 29 | // 2.如果没有take.png将尝试下载远程的图像 30 | // 3.添加root权限检查 31 | // 4.对于已root设备,将会使用shell命令强制开启autojs的无障碍服务 32 | // 2018-01-13 20:38:14 33 | // 1.添加两种分辨率 34 | // 2.增加默认的按压时间,由50改为100 35 | // 2018-01-14 11:28:32 36 | // 1.添加进森林的兼容方案 37 | // 2.新发现部分人的swipe、press没用,这个我也无能为力了 38 | // 2018-02-02 23:54:44 39 | // 1.关闭调试,避开软件新版本出现的错误 40 | // 2.修复路径问题 41 | // 2018-4-12 42 | // 适应支付宝的改动 43 | var isAuthor = false;//如果你不是作者,这里务必为false,不然各种报错。 44 | var debug = false; 45 | 46 | var debug_dir = "/sdcard/debug/take/"; 47 | if (debug) { 48 | files.ensureDir(debug_dir); 49 | } 50 | 51 | //检测手机是否已root,如果root,下面的代码会自动开启autojs的无障碍服务!!! 52 | if (isRoot()) { 53 | var s = shell("settings get secure enabled_accessibility_services", true).result.replace(/\n/, ""); 54 | log(s); 55 | var stardust = "com.stardust.scriptdroid/com.stardust.scriptdroid.accessibility.AccessibilityService"; 56 | if (s.indexOf("stardust") == "-1") { 57 | var code = shell("settings put secure enabled_accessibility_services " + s + ":" + stardust, true).code; 58 | if (code) { 59 | toastLog("开启无障碍服务异常"); 60 | } 61 | } 62 | shell("settings put secure accessibility_enabled 1", true); 63 | } 64 | 65 | if (isAuthor) { 66 | var unlock = require("unlock"); //解锁模块 67 | unlock(); 68 | shell("pm enable com.eg.android.AlipayGphone", true); 69 | } else { 70 | //请自己想办法让手机屏幕解锁可以进行操作 71 | device.wakeUp(); 72 | } 73 | 74 | sleep(3000); 75 | var temp = images.read("/sdcard/take.png"); 76 | 77 | if (!temp) { 78 | toastLog("缺少图片文件,请仔细查看\n使用方法的第一条!!!"); 79 | switch (device.width) { 80 | case 1080: 81 | temp = images.load("https://raw.githubusercontent.com/start201711/autojs/master/take.png"); 82 | break; 83 | case 720: 84 | temp = images.load("https://raw.githubusercontent.com/start201711/autojs/master/take720p.png"); 85 | break; 86 | default: 87 | temp = null; 88 | break; 89 | } 90 | 91 | if (!temp) { 92 | toastLog("尝试下载take.png失败,脚本停止运行"); 93 | exit(); 94 | } 95 | toastLog("现在将尝试使用别人的图片,分辨率可能不匹配,脚本可能无法正常执行"); 96 | } 97 | var r = new Robot(); 98 | var dh = 40 * device.height / 720; 99 | 100 | 101 | //向系统申请截图时,自动确认 102 | new java.lang.Thread(function() { 103 | classNameContains("Button").textContains("立即开始").click(); 104 | }).start(); 105 | 106 | 107 | if (!requestScreenCapture()) { 108 | toast("请求截图失败"); 109 | exit(); 110 | } 111 | toastLog("即将收取蚂蚁森林能量,请勿操作!"); 112 | 113 | launch("com.eg.android.AlipayGphone"); 114 | waitForPackage("com.eg.android.AlipayGphone"); 115 | 116 | //有人说进不去森林,但是查看布局分析是没问题的 117 | //这里使用一个兼容的办法clickSenlin(); 118 | //如果你的进不去,你可以把下面的这句换成while (!click("蚂蚁森林")); 119 | //如果还不行,你换成r.press(x,y);//x,y是需要点击的森林的位置。 120 | //如果再不行,那你换成Tap(x,y);//x,y是需要点击的森林的位置。 121 | //如果再再不行,那就shell("input tap x y");//x,y是需要点击的森林的位置。 122 | //如果再再再不行,去支付宝充把火麒麟就好了(#滑稽) 123 | clickSenlin(); //兼容方法 124 | 125 | 126 | className("android.widget.Button").desc("攻略").waitFor(); 127 | toastLog("成功进入蚂蚁森林"); 128 | sleep(3000); 129 | 130 | 131 | takeMyself2(); 132 | toastLog("收取自己的能量完毕"); 133 | sleep(2000); 134 | 135 | 136 | while (1) { 137 | for (var p = findImage(captureScreen(), temp); p; p = findImage(captureScreen(), temp)) { 138 | if (debug) { 139 | toastLog("进入好友的森林"); 140 | } 141 | r.press(p.x, p.y + dh, 100); 142 | takeOther2(); 143 | sleep(1000); 144 | idContains("h5_tv_nav_back").click(); 145 | sleep(2000); 146 | } 147 | if (debug) { 148 | images.captureScreen(debug_dir + new Date().getTime() + ".png"); 149 | } 150 | if (descContains("爱心捐赠").classNameContains("android.widget.Image").findOne().bounds().top < device.height) { 151 | break; 152 | } 153 | r.swipe(device.width / 2, device.height * 2 / 3, device.width / 2, device.height * 1 / 3); 154 | sleep(2000); 155 | } 156 | 157 | //通知tasker下一次运行脚本的时间,全天候自动挂机 158 | if (isAuthor) { 159 | var loop = require("loop"); 160 | loop(); //将等待下一次时间写入文件中给tasker 161 | } 162 | 163 | toastLog("收取能量完毕"); 164 | idContains("h5_tv_nav_back").click(); 165 | if (isAuthor) { 166 | shell("pm disable com.eg.android.AlipayGphone", true); 167 | } 168 | exit(); 169 | 170 | /******************收取能量函数********************/ 171 | 172 | 173 | function takeMyself2() { 174 | 175 | take("攻略"); 176 | } 177 | 178 | function takeOther2() { 179 | 180 | take("浇水"); 181 | } 182 | 183 | function take(desc) { 184 | var right_bottom = className("android.widget.Button").desc(desc).findOne(); 185 | log(right_bottom); 186 | var left_top = descContains("返回").findOne(); 187 | log(left_top); 188 | 189 | var filtes = []; 190 | var left = 0; 191 | var right = device.width; 192 | var top = left_top.bounds().bottom; 193 | var bottom = right_bottom.bounds().top; 194 | 195 | log(left + "-" + top + "-" + right + "-" + bottom); 196 | sleep(2000); 197 | var all = descMatches("^((绿色|收集)能量|\\d+g)$").boundsInside(left, top, right, bottom).untilFind(); 198 | toastLog("找到" + (all.size() - 1) + "个能量球"); 199 | all.each(function(x) { 200 | filtes.push(x); 201 | }); 202 | 203 | filtes.sort(function(o1, o2) { 204 | return distance(o1) - distance(o2); 205 | }); 206 | 207 | if (filtes.length > 0) { 208 | filtes.splice(0, 1); 209 | } 210 | if (debug) { 211 | images.captureScreen(debug_dir + new Date().getTime() + ".png"); 212 | } 213 | for (var i = 0; i < filtes.length; i++) { 214 | r.pressCenter(filtes[i], 100); 215 | sleep(1000); 216 | log("点击->" + filtes[i]); 217 | } 218 | 219 | 220 | function distance(o) { 221 | return Math.pow((o.bounds().top - top), 2) + Math.pow((o.bounds().right - right), 2); 222 | } 223 | } 224 | 225 | function clickSenlin() { 226 | var b = text("蚂蚁森林").findOne().bounds(); 227 | var a = idContains("home_app_view").untilFind().filter(o => { 228 | return o.bounds().contains(b); 229 | }); 230 | while (!a[0].click()); 231 | } 232 | 233 | function Robot() { 234 | var r = null; 235 | if (device.sdkInt < 24) { 236 | if (isRoot()) { 237 | r = new RootAutomator(); 238 | } else { 239 | toastLog("本脚本需要android7.0以上或者已root才能使用"); 240 | exit(); 241 | } 242 | } 243 | 244 | this.press = function(x, y, duration) { 245 | if (duration == undefined) { 246 | duration = 100; 247 | } 248 | if (r == null) { 249 | press(x, y, duration); 250 | } else { 251 | r.press(x, y, duration); 252 | } 253 | } 254 | this.pressCenter = function(b, duration) { 255 | this.press(b.bounds().centerX(), b.bounds().centerY(), duration); 256 | } 257 | this.swipe = function(x1, y1, x2, y2, duration) { 258 | if (duration == undefined) { 259 | duration = 200; 260 | } 261 | if (r == null) { 262 | swipe(x1, y1, x2, y2, duration); 263 | } else { 264 | var n = 30; 265 | var dx = (x2 - x1) / n; 266 | var dy = (y2 - y1) / n; 267 | r.touchDown(x1, y1); 268 | for (var i = 0; i < n; i++) { 269 | r.touchMove(x1, y1); 270 | x1 += 6 * dx * i * (n - i) / Math.pow(n, 2); 271 | y1 += 6 * dy * i * (n - i) / Math.pow(n, 2); 272 | sleep(duration / n); 273 | } 274 | r.touchUp(); 275 | } 276 | } 277 | } 278 | 279 | 280 | 281 | function isRoot() { 282 | var bool = false; 283 | try { 284 | bool = new java.io.File("/system/bin/su").exists() || new java.io.File("/system/xbin/su").exists(); 285 | } catch (e) { 286 | print(e); 287 | } 288 | return bool; 289 | } 290 | 291 | /**********************应该会废弃下面的方法**************************/ 292 | 293 | // var a = descContains("线下支付").find(); 294 | // if (a) { 295 | // toastLog("能量球个数1:" + a.size()); 296 | // a.each(function(x) { 297 | // log(x.bounds()); 298 | // r.press(x.bounds().centerX(), x.bounds().centerY() - dh); 299 | // }); 300 | // } 301 | // var b = descContains("行走").find(); 302 | // if (b) { 303 | // log("能量球个数2:" + b.size()); 304 | // b.each(function(x) { 305 | // toastLog(x.bounds()); 306 | // r.press(x.bounds().centerX(), x.bounds().centerY() - dh); 307 | // }); 308 | // } 309 | 310 | // //todo 需要添加更多的情况 311 | // } 312 | 313 | // function takeOther() { 314 | // className("android.widget.Button").desc("浇水").waitFor(); 315 | // sleep(3000); 316 | // var a = descContains("  可收取").find(); 317 | // if (a) { 318 | // toastLog("能量球个数:" + a.size()); 319 | // a.each(function(x) { 320 | // toastLog(x.bounds()); 321 | // r.press(x.bounds().centerX(), x.bounds().centerY() - dh); 322 | // sleep(1000); 323 | // }); 324 | // } 325 | // } 326 | 327 | 328 | 329 | /*******************解锁模块代码实例,我把自己的代码乱改***********************/ 330 | //下面的代码放另一个文件里面 331 | // function unlock() { 332 | // var pm = context.getSystemService(context.POWER_SERVICE); 333 | // var b = pm.isScreenOn(); 334 | // if (!b) { 335 | // unlock0(); 336 | // } 337 | // } 338 | 339 | // function unlock0() { 340 | // "root"; 341 | // device.wakeUp(); 342 | // sleep(3000); 343 | // var ra = new Robot(); 344 | // ra.swipe(760, 1000, 360, 750); 345 | // sleep(1000); 346 | // ra.press(650, 450); 347 | // sleep(1000); 348 | // ra.press(650, 350); 349 | // sleep(1000); 350 | // ra.press(160, 750); 351 | // sleep(1000) 352 | // ra.press(760, 360); 353 | // sleep(2000); 354 | // }  355 | 356 | // module.exports = unlock; 357 | --------------------------------------------------------------------------------