Write a food grab script based on Auto.js

In Shanghai, it is difficult to grab food. What's more difficult is that I get up at 5:50 every day and still can't get the food, which makes people physically and mentally exhausted. Today I found a tool that can run scripts on Android machines - Auto.js , I simply wrote a script to grab food.

Development steps:

  1. Download the Auto.jsinstallation package, currently available on the official website Auto.js Pro, is a fee, 45 yuan buyout system, or conscience, it is recommended that you buy it. However, I will also share the free version here (the non-cracked version is the free version before starting to charge. I heard that many versions are poisonous on the Internet. This is the one that I confirmed to be non-toxic after testing the drug, so you can use it with confidence) - link : pan.baidu.com/s/1zBTij7im...Extraction code: n9jc -- sharing from Baidu Netdisk Super Member v3

  2. After installing the software, enable the accessibility and floating window functions of the application.

image-20220406221255685

  1. You can use the floating window tool to inspect the elements of the app.

    image-20220406225906556

WechatIMG55.jpeg

  1. Open VS Code and install the Auto.js-VSCodeExtplugin.

image-20220406222424648

  1. Command+shift+PThe shortcut key opens Command Palette, run Auto.js:New Projectthe command to create a new project.

image-20220406222958526

  1. Write the script in the main.js file:
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. Run Auto.js:Start Serverthe command to start the service. When the phone and the computer are on the same local area network, turn on the "connect computer" option. After the connection is successful, VS Code will pop up a prompt. Then you can happily change the code and debug it.

The pits that are easy to step on in the project, remind everyone:

  1. Be sure to turn on accessibility features! If it is found that the element cannot be selected or any other abnormality, the high probability is that the accessibility function is turned off. Yes, the accessibility function will sometimes be automatically turned off.
  2. The phone's GPS is turned on.

Project address: github.com/qulingyuan/…

The current code is a semi-finished product, because the scene after clicking the checkout button during the day is only "I know". The normal purchase scene cannot be entered. I plan to get up at 5:30 tomorrow morning to debug the script and write down all the scenes. However, the scripts before settlement are available for testing on my mobile phone, but it may be different due to different models, so you need to debug it yourself.

Guess you like

Origin juejin.im/post/7083512899200614430