自动化的抖音

文件命名 main.js
 

var uiModule = require("ui_module.js");
if (!auto.service) {toast("请开启无障碍服务");auto.waitFor();}
var isRunning = true;
var swipeCount = 0;
var targetSwipeCount = random(1, 10);
var window = uiModule.createUI();
uiModule.setTargetSwipeCount(window, targetSwipeCount);
window.stop.click(() => (isRunning = false));
function updateTimer(seconds) {
  uiModule.updateTimer(window, seconds);
}
function checkForText() {
  return textContains("点击进入直播间").findOne(1000) != null;
}
threads.start(function () {
  var width = device.width;
  var height = device.height;
  toast("3秒后启动应用");
  sleep(3000);
  launchApp("测试");
  sleep(2000);
  while (isRunning) {
    swipeCount = 0;
    targetSwipeCount = random(1, 10);
    uiModule.setTargetSwipeCount(window, targetSwipeCount);
    for (var i = 0; i < targetSwipeCount && isRunning; i++) {
      if (!isRunning) break;
      swipe(width / 2, height * 0.8, width / 2, height * 0.2, 500);
      swipeCount++;
      uiModule.setSwipeCount(window, swipeCount);
      var randomWait = random(1, 10);
      toast("等待: " + randomWait + "秒后继续滑动");
      uiModule.setRandomWait(window, randomWait);
      for (var j = randomWait; j > 0 && isRunning; j--) {
        updateTimer(j);
        sleep(1000);
      }
      if (!isRunning) break;
    }
    if (!isRunning) break;
    if (checkForText()) {
      toast("发现'点击进入直播间',执行滑动");
      swipe(width / 2, height * 0.8, width / 2, height * 0.2, 500);
    } else {
      var randomWait = random(1, 10);
      toast("未发现特定文字,等待: " + randomWait + "秒后执行双击");
      uiModule.setRandomWait(window, randomWait);
      for (var j = randomWait; j > 0 && isRunning; j--) {
        updateTimer(j);
        sleep(1000);
      }
      click(width / 2, height / 2);
      sleep(100);
      click(width / 2, height / 2);
    }
    updateTimer(0);
    sleep(2000);
  }
  window.close();
  toast("脚本已停止");
});

第二个文件ui_module.js   也是试图 文件 

// 创建UI
function createUI() {
    var window = floaty.window(
        
            
                

你可能感兴趣的:(javascript,开发语言,ecmascript)