自动化的抖音

文件命名 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
};
相关推荐
_OP_CHEN14 小时前
C++进阶:(七)红黑树深度解析与 C++ 实现
开发语言·数据结构·c++·stl·红黑树·红黑树的旋转·红黑树的平衡调整
阳懿14 小时前
meta-llama-3-8B下载失败解决。
前端·javascript·html
史林枫14 小时前
JavaScript 中call和apply的详细讲解 —— 连10岁的小朋友都能看懂!
javascript·apply·call
硅农深芯14 小时前
如何使用ptqt5实现进度条的动态显示
开发语言·python·qt
紫小米14 小时前
Vue 2 和 Vue 3 的区别
前端·javascript·vue.js
Lhan.zzZ14 小时前
Qt数据可视化实战:饼图、线图与表格的完整指南
开发语言·qt·信息可视化
Acrelhuang14 小时前
筑牢用电防线:Acrel-1000 自动化系统赋能 35kV 园区高效供电-安科瑞黄安南
java·大数据·开发语言·人工智能·物联网
小龙报15 小时前
《算法通关指南数据结构和算法篇(4)--- 队列和queue》
c语言·开发语言·数据结构·c++·创业创新·学习方法·visual studio
民乐团扒谱机15 小时前
深入浅出理解克尔效应(Kerr Effect)及 MATLAB 仿真实现
开发语言·matlab·光学·非线性光学·克尔效应·kerr effect
用户66006766853915 小时前
从变量提升到调用栈:V8 引擎如何 “读懂” JS 代码
前端·javascript