1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449
|
auto.waitFor();
setScreenMetrics(1080, 2340);
var g_help_friend = true;
var g_energy_postion = [ [250, 750], [350, 700], [450, 650], [600, 650], [750, 700], [850, 750] ]; var hour = 7; var min = 10; var sec = 0;
const DEBUG = false;
main();
function addSteps() { launchApp("小米步数管理"); sleep(500); id("edtAddSteps").findOne().setText(20000); sleep(100); id("btnAddSteps").findOne().click(); console.log("增加步数"); }
function unlock() { if (!device.isScreenOn()) { device.wakeUp(); sleep(1000); swipe(500, 30, 500, 1000, 300); sleep(400); click(100, 120); sleep(500); click(555, 1379); sleep(100); click(244, 1381); sleep(100); click(224, 1200); sleep(100); click(541, 1596); sleep(100); click(541, 1596); sleep(100); click(224, 1200); sleep(100); click(244, 1381); sleep(100); click(555, 1379); sleep(100); click(544, 1196); sleep(1000); console.log("自动解锁屏幕"); } }
function lock() { KeyCode(26); console.log("锁屏"); }
function getScreenCapturePermission() { if (!requestScreenCapture()) { toast("获取截图权限失败,脚本退出"); console.error("获取截图权限失败,脚本退出"); exit(); } toastLog("获取截图权限成功,等待支付宝启动"); sleep(500); }
function registerExitEvent() { var thread = threads.start(function() { events.observeKey(); events.onKeyDown("volume_down", function(event) { toast("音量下键被按下,脚本退出"); console.warn("音量下键被按下,脚本退出"); exit(); }); }); return thread; }
function findHomePage() { let i = 0; while (i++ < 5) { if (text("首页").exists() && text("我的").exists()) break; back(); sleep(500); } if (i < 5) return true; else return false; }
function openAlipay() { launchApp("支付宝"); sleep(1000); if (!findHomePage()) { toast("寻找支付宝首页失败,脚本退出"); console.error("寻找支付宝首页失败,脚本退出"); exit(); } else { let item = text("首页").findOnce(); if (!item.selected()) { let pos = item.bounds(); if (!click(pos.centerX(), pos.centerY())) { console.error("打开支付宝首页失败,脚本退出"); exit(); } } console.log("成功找到支付宝首页"); } }
function entranceAntForest() { var item = null, i = 0; while (i++ < 5) { item = className("android.widget.TextView").text("蚂蚁森林").findOnce(); if (item != null) break; swipe(520, 500, 520, 1500, 500); sleep(500); } if (item == null) { toast("首页上没有蚂蚁森林,退出脚本"); console.error("首页上没有蚂蚁森林,退出脚本"); exit(); } else { let pos = item.bounds(); click(pos.centerX(), pos.centerY()); } i = 0; while (i++ < 10) { if (text("背包").exists() && text("任务").exists()) break; sleep(1000); } if (i >= 10) { toast("进入蚂蚁森林主页失败,退出脚本"); exit(); } else { if (DEBUG) console.log("成功进入蚂蚁森林主页", "用时" + i * 1.0 + "秒"); else console.log("成功进入蚂蚁森林主页"); } collectionEnergyByPosition(400);
item = null; i = 0; while (i++ < 10) { item = text("查看更多好友").findOnce(); if (item != null && item.bounds().height() > 100) break; swipe(520, 1800, 520, 300, 500); sleep(500); } if (item == null) { toast("没有找到查看更多好友,退出脚本"); exit(); } else { let pos = item.bounds(); if (!click(pos.centerX(), pos.centerY())) { toast("进入好友排行榜失败,退出脚本"); exit(); } else { if (DEBUG) console.log("成功进入好友排行榜", "用时" + i * 0.5 + "秒"); else console.log("成功进入好友排行榜"); sleep(2000);
entranceFriendsRank(); } } }
function searchAndClickByName(serach_name, match_pos, text_or_desc, timeout) { var result = null; if (match_pos == "prefix") { if (text_or_desc == "text") result = textStartsWith(serach_name).findOne(timeout); else result = descStartsWith(serach_name).findOne(timeout); } else { if (text_or_desc == "text") result = textEndsWith(serach_name).findOne(timeout); else result = descEndsWith(serach_name).findOne(timeout); } if (!result) { let pos = result.bounds(); if (pos.centerX() < 0 || pos.centerY() < 0) return false; else return click(pos.centerX(), pos.centerY()); } return null; }
function collectionEnergyByPosition(delay) { if (typeof(delay) == "undefined") delay = 0; for (let i = 0; i < g_energy_postion.length; ++i) { click(g_energy_postion[i][0], g_energy_postion[i][1]); sleep(200); } }
function getCaptureImg() { var img = captureScreen(); sleep(100); if (img == null || typeof(img) == "undefined") { toast("截图失败,脚本退出"); console.error("截图失败,脚本退出"); exit(); } else { return img; } }
function getHasEnergyFriends() { var img = getCaptureImg(); var hand = null, heart = null;
hand = images.findMultiColors(img, "#1da06d", [ [0, -7, "#ffffff"], [0, 10, "#ffffff"] ], { region: [1010, 400, 1, 1800], threshold: 4 }); if (hand != null) { console.info("找到**可收取**好友"); return [hand, "hand"]; }
if (g_help_friend == true) { heart = images.findColor(img, "#f99236", { region: [1000, 400, 10, 1800], threshold: 4 }); if (heart != null) { console.info("找到**可帮收**好友"); return [heart, "heart"]; } } return null; }
function arriveRankBottom() { var img = getCaptureImg(); var result = null; result = images.findMultiColors(img, "#F5F5F5", [ [0, -40, "#FFFFFF"], [0, 20, "#999999"] ], { region: [600, 2000], threshold: 1 }); if (result != null) return true; else return false; }
function entranceFriendsRank() { var i = 0; sleep(500); var epoint = getHasEnergyFriends();
while (epoint == null) { swipe(520, 1800, 520, 800, 500); sleep(500); epoint = getHasEnergyFriends(); if (epoint == null && arriveRankBottom()) { toastLog("没有更多好友了"); return true; } if (i++ >= 32) { console.error("程序可能出错, 连续" + i + "次未检测到可收集好友"); return false; } } if (click(epoint[0].x, epoint[0].y + 20)) { let i = 0; while (i++ < 10) { if (text("TA收取你").exists() && text("你收取TA").exists()) break; sleep(500); } if (i < 10) { if (DEBUG) console.log("成功进入好友森林主页", "用时" + i * 0.5 + "秒"); collectionEnergyByPosition(400); } back(); } entranceFriendsRank(); }
function main() { while (true) { let date = new Date(); let sleepHour, sleepMin, sleepSec; if (date.getSeconds() > sec) { sleepSec = 60 - date.getSeconds() + sec; } else { sleepSec = sec - date.getSeconds(); } if (date.getMinutes() > min) { sleepMin = 60 - date.getMinutes() + min; } else if (date.getMinutes() == min) { if (date.getSeconds() < sec) { sleepMin = 0; } else { sleepMin = 60; } } else { sleepMin = min - date.getMinutes(); } if (date.getHours() > hour) { sleepHour = 24 - date.getHours() + hour; } else if (date.getHours() == hour) { if (date.getMinutes() < min) { sleepHour = 0; } else { sleepHour = 24; } } else { sleepHour = hour - date.getHours(); } if (sleepHour > 0) { sleepHour--; } if (sleepMin > 0) { sleepMin--; } let message = "休眠" + sleepHour + "小时" + sleepMin + "分钟" + sleepSec + "秒后运行"; toast(message); console.log(message);
sleep(sleepHour * 60 * 60 * 1000 + sleepMin * 60 * 1000 + sleepSec * 1000);
unlock(); addSteps(); getScreenCapturePermission(); openAlipay(); entranceAntForest(); lock(); } }
|