Git Product home page Git Product logo

robveg's Introduction

身处上海,抢菜很难。更难的是,每天 5:50 起床还抢不到菜,搞得人身心俱疲。今天发现了一个可以在安卓机上运行脚本的工具——Auto.js,简单的写了个脚本用来抢菜。

开发步骤:

  1. 下载 Auto.js 安装包,目前官网提供的是 Auto.js Pro,是收费的,45 块钱买断制,还是良心的,建议大家购买。不过这里也分享一下免费版本(非破解版,是开始收费前的免费版,网上听说很多版本是有毒的,这个是我以身试毒后确认无毒的,大家可放心使用)—— 链接: https://pan.baidu.com/s/1zBTij7imoLCKf1bm7HtY6Q 提取码: n9jc --来自百度网盘超级会员v3的分享

  2. 安装软件后,开启应用的无障碍悬浮窗功能。

image-20220406221255685

  1. 可以使用悬浮窗的工具来检查 app的元素。

    image-20220406225906556

    image-20220406225941640

  2. 打开 VS Code,安装Auto.js-VSCodeExt插件。

image-20220406222424648

  1. Command+shift+P快捷键打开 Command Palette,运行 Auto.js:New Project命令创建一个新项目。

image-20220406222958526

  1. 在 main.js 文件中编写脚本:
function robVeg() {
  launchApp("美团买菜");
  waitForPackage("com.meituan.retail.v.android", 200);
  auto.waitFor();
  const btn_skip = id("btn_skip").findOne();
  if (btn_skip) {
    btn_skip.click();
    toast("已跳过首屏广告");
  }
  sleep(1000);
  gotoBuyCar();
  sleep(1000);
  checkAll();
}

robVeg();

//打开购物车页面
function gotoBuyCar() {
  const buyCarBtn = id("cartredDotTextView").findOne();
  if (buyCarBtn) {
    buyCarBtn.parent().click();
    toast("已进入购物车");
  } else {
    toast("没找到购物车");
    exit;
  }
}

//勾选全部商品
function checkAll() {
  const isCheckedAll = textStartsWith("结算(").exists();
  const checkAllBtn = text("全选").findOne();
  if (!!checkAllBtn) {
    !isCheckedAll && checkAllBtn.parent().click();
    sleep(1000);
  } else {
    toast("没找到全选按钮");
    exit;
  }
}

6.运行 Auto.js:Start Server 命令启动服务,手机和电脑在同一局域网的情况下打开”连接电脑“选项,连接成功后,VS Code 会弹出提示。然后就可以愉快地改代码调试了。

项目中容易踩到的坑,给大家提个醒:

  1. 一定要打开无障碍功能!如果发现无法选取元素了或者什么其他异常,大概率是无障碍功能关闭了,是的,无障碍功能有时候会自动关闭。
  2. 手机的GPS 打开。

项目地址:

现在的代码是一个半成品,因为白天点击结算按钮后面的场景只有”我知道了“这个场景,正常购买场景走不进去了,我打算明天早上 5:30起床调试脚本,把场景都记下来。但结算之前的脚本在我的手机上测试都是可用的,不过也可能会因为机型的不同会有不同,就需要大家自己调试了。

robveg's People

Contributors

qulingyuan avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.