自动化的抖音

文件命名 main.js

javascript 复制代码
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 也是试图 文件

javascript 复制代码
// 创建UI
function createUI() {
    var window = floaty.window(
        <frame>
            <vertical>
                <button id="stop" text="停止" w="120" h="40" bg="#ff0000" />
                <text id="timer" text="等待: 0s" textSize="14sp" textColor="#ffffff" />
                <text id="targetSwipeCountText" text="目标滑动次数: 0" textSize="14sp" textColor="#ffffff"/>
                <text id="swipeCountText" text="当前滑动次数: 0" textSize="14sp" textColor="#ffffff"/>
                <text id="randomWaitText" text="随机等待时间: 0s" textSize="14sp" textColor="#ffffff"/>
            </vertical>
        </frame>
    );
    window.setPosition(100, 100);  // 设置浮动窗口位置
    return window;
}

// 更新目标滑动次数
function setTargetSwipeCount(window, targetSwipeCount) {
    ui.run(() => {
        window.targetSwipeCountText.setText("滑动: " + targetSwipeCount+ '次开始点赞');
    });
}

// 更新当前滑动次数
function setSwipeCount(window, swipeCount) {
    ui.run(() => {
        window.swipeCountText.setText("当前滑动次数: " + swipeCount + '次');
    });
}

// 更新随机等待时间
function setRandomWait(window, randomWait) {
    ui.run(() => {
        window.randomWaitText.setText("随机等待时间: " + randomWait + "秒");
    });
}

// 更新倒计时
function updateTimer(window, seconds) {
    ui.run(() => {
        window.timer.setText("等待: " + seconds + "s");
    });
}

// 导出模块函数
module.exports = {
    createUI: createUI,
    setTargetSwipeCount: setTargetSwipeCount,
    setSwipeCount: setSwipeCount,
    setRandomWait: setRandomWait,
    updateTimer: updateTimer
};
相关推荐
右子1 分钟前
HTML Canvas API 技术简述与关系性指南
前端·javascript·canvas
Lotzinfly2 分钟前
10个JavaScript浏览器API奇淫技巧你需要掌握😏😏😏
前端·javascript·面试
xxxxxxllllllshi4 分钟前
Java 集合框架全解析:从数据结构到源码实战
java·开发语言·数据结构·面试
爱编程的鱼20 分钟前
Python 与 C++、C 语言的区别及选择指南
c语言·开发语言·c++
liangshanbo121530 分钟前
React 19 新特性:原生支持在组件中渲染 <meta> 与 <link>
前端·javascript·react.js
运维闲章印时光37 分钟前
网络断网、环路、IP 冲突?VRRP+MSTP+DHCP 联动方案一次性解决
运维·服务器·开发语言·网络·php
lly2024061 小时前
TypeScript 循环
开发语言
liulilittle1 小时前
OPENPPP2 静态隧道链路迁移平滑(UDP/IP)
开发语言·网络·c++·网络协议·tcp/ip·udp·通信
前端 贾公子1 小时前
《Vuejs设计与实现》第 18 章(同构渲染)(下)
前端·javascript·html
qq_402605651 小时前
python爬虫(二) ---- JS动态渲染数据抓取
javascript·爬虫·python