Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android Automation: Auto.js #350

Open
2 tasks done
hhstore opened this issue Apr 17, 2022 · 6 comments
Open
2 tasks done

Android Automation: Auto.js #350

hhstore opened this issue Apr 17, 2022 · 6 comments

Comments

@hhstore
Copy link
Owner

hhstore commented Apr 17, 2022

related:

@hhstore
Copy link
Owner Author

hhstore commented Apr 17, 2022

@hhstore
Copy link
Owner Author

hhstore commented Apr 17, 2022

抢菜助手:

这个脚本, 有个小 bug: 修复版本如下:

// 解锁手机屏幕
function unLock() {
  if (!device.isScreenOn()) {
    device.wakeUp();
    sleep(500);
    swipe(500, 2000, 500, 1000, 200);
    sleep(500);
    const password = "123456"; //这里换成自己的手机解锁密码
    for (let i = 0; i < password.length; i++) {
      let position = text(password[i]).findOne().bounds();
      click(position.centerX(), position.centerY());
      sleep(100);
    }
  }

  sleep(1000);
}

//抢菜流程
function robVeg() {
  // 解锁手机屏幕:
  unLock();

  // 打开买菜 app:
  launchApp("美团买菜");
  waitForPackage("com.meituan.retail.v.android", 200);

  // 检查无障碍权限:
  auto.waitFor();

  //
  // app 跳过广告:
  //
  const btn_skip = id("btn_skip").findOne();
  if (btn_skip) {
    btn_skip.click();
    toast("已跳过首屏广告");
  }
  sleep(2000);

  // 购物车:
  gotoBuyCar();
  sleep(2000);

  // 检查:
  checkAll();
  sleep(2000);

  // 提交订单:
  submitOrder(0);
}

robVeg();

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

//勾选全部商品
function checkAll() {
  const isCheckedAll = textStartsWith("结算(").exists();

  // todo x: button:
  const checkAllBtn = text("全选").findOne();
  if (!!checkAllBtn) {
    !isCheckedAll && checkAllBtn.parent().click();
    sleep(1000);
  } else {
    toast("没找到全选按钮");
    exit;
  }
}

function submitOrder(count) {
  //
  // 结算按钮:
  //
  if (textStartsWith("结算(").exists()) {
    //
    //
    //
    textStartsWith("结算(").findOne().parent().click();
  } else if (text("我知道了").exists()) {
    //
    //
    //
    toast("关闭 >>  我知道了");

    //
    //  todo x: key button
    //
    text("我知道了").findOne().parent().click();
  } else if (text("返回购物车").exists()) {
    text("返回购物车").findOne().parent().click();
    toast(">> 返回购物车");
  } else if (text("重新加载").exists()) {
    toast("重新加载");
    text("重新加载").findOne().parent().click();
  } else if (text("立即支付").exists()) {
    text("立即支付").findOne().parent().click();
  } else if (text("确认支付").exists()) {
    const music =
      "/storage/emulated/0/netease/cloudmusic/Music/Joel Hanson Sara Groves - Traveling Light.mp3";
    media.playMusic(music);
    sleep(media.getMusicDuration());
  } else {
    //
    //
    //
    toast(">> 抢个屁!");
    exit;
  }

  //
  //
  //
  sleep(800);
  if (count > 10000) {
    toast("没抢到");
    exit;
  }

  submitOrder(count++);
}

@hhstore
Copy link
Owner Author

hhstore commented Apr 17, 2022

@hhstore
Copy link
Owner Author

hhstore commented Apr 17, 2022

@hhstore
Copy link
Owner Author

hhstore commented Apr 17, 2022

1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant