0


自动化的抖音

文件命名 main.js

  1. var uiModule = require("ui_module.js");
  2. if (!auto.service) {toast("请开启无障碍服务");auto.waitFor();}
  3. var isRunning = true;
  4. var swipeCount = 0;
  5. var targetSwipeCount = random(1, 10);
  6. var window = uiModule.createUI();
  7. uiModule.setTargetSwipeCount(window, targetSwipeCount);
  8. window.stop.click(() => (isRunning = false));
  9. function updateTimer(seconds) {
  10. uiModule.updateTimer(window, seconds);
  11. }
  12. function checkForText() {
  13. return textContains("点击进入直播间").findOne(1000) != null;
  14. }
  15. threads.start(function () {
  16. var width = device.width;
  17. var height = device.height;
  18. toast("3秒后启动应用");
  19. sleep(3000);
  20. launchApp("测试");
  21. sleep(2000);
  22. while (isRunning) {
  23. swipeCount = 0;
  24. targetSwipeCount = random(1, 10);
  25. uiModule.setTargetSwipeCount(window, targetSwipeCount);
  26. for (var i = 0; i < targetSwipeCount && isRunning; i++) {
  27. if (!isRunning) break;
  28. swipe(width / 2, height * 0.8, width / 2, height * 0.2, 500);
  29. swipeCount++;
  30. uiModule.setSwipeCount(window, swipeCount);
  31. var randomWait = random(1, 10);
  32. toast("等待: " + randomWait + "秒后继续滑动");
  33. uiModule.setRandomWait(window, randomWait);
  34. for (var j = randomWait; j > 0 && isRunning; j--) {
  35. updateTimer(j);
  36. sleep(1000);
  37. }
  38. if (!isRunning) break;
  39. }
  40. if (!isRunning) break;
  41. if (checkForText()) {
  42. toast("发现'点击进入直播间',执行滑动");
  43. swipe(width / 2, height * 0.8, width / 2, height * 0.2, 500);
  44. } else {
  45. var randomWait = random(1, 10);
  46. toast("未发现特定文字,等待: " + randomWait + "秒后执行双击");
  47. uiModule.setRandomWait(window, randomWait);
  48. for (var j = randomWait; j > 0 && isRunning; j--) {
  49. updateTimer(j);
  50. sleep(1000);
  51. }
  52. click(width / 2, height / 2);
  53. sleep(100);
  54. click(width / 2, height / 2);
  55. }
  56. updateTimer(0);
  57. sleep(2000);
  58. }
  59. window.close();
  60. toast("脚本已停止");
  61. });

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

  1. // 创建UI
  2. function createUI() {
  3. var window = floaty.window(
  4. <frame>
  5. <vertical>
  6. <button id="stop" text="停止" w="120" h="40" bg="#ff0000" />
  7. <text id="timer" text="等待: 0s" textSize="14sp" textColor="#ffffff" />
  8. <text id="targetSwipeCountText" text="目标滑动次数: 0" textSize="14sp" textColor="#ffffff"/>
  9. <text id="swipeCountText" text="当前滑动次数: 0" textSize="14sp" textColor="#ffffff"/>
  10. <text id="randomWaitText" text="随机等待时间: 0s" textSize="14sp" textColor="#ffffff"/>
  11. </vertical>
  12. </frame>
  13. );
  14. window.setPosition(100, 100); // 设置浮动窗口位置
  15. return window;
  16. }
  17. // 更新目标滑动次数
  18. function setTargetSwipeCount(window, targetSwipeCount) {
  19. ui.run(() => {
  20. window.targetSwipeCountText.setText("滑动: " + targetSwipeCount+ '次开始点赞');
  21. });
  22. }
  23. // 更新当前滑动次数
  24. function setSwipeCount(window, swipeCount) {
  25. ui.run(() => {
  26. window.swipeCountText.setText("当前滑动次数: " + swipeCount + '次');
  27. });
  28. }
  29. // 更新随机等待时间
  30. function setRandomWait(window, randomWait) {
  31. ui.run(() => {
  32. window.randomWaitText.setText("随机等待时间: " + randomWait + "秒");
  33. });
  34. }
  35. // 更新倒计时
  36. function updateTimer(window, seconds) {
  37. ui.run(() => {
  38. window.timer.setText("等待: " + seconds + "s");
  39. });
  40. }
  41. // 导出模块函数
  42. module.exports = {
  43. createUI: createUI,
  44. setTargetSwipeCount: setTargetSwipeCount,
  45. setSwipeCount: setSwipeCount,
  46. setRandomWait: setRandomWait,
  47. updateTimer: updateTimer
  48. };

本文转载自: https://blog.csdn.net/qq_44759522/article/details/142785108
版权归原作者 luckycoke 所有, 如有侵权,请联系我们删除。

“自动化的抖音”的评论:

还没有评论