1. Operating environment
1.1 Vscode Version: 1.78.2 (user setup)
1.2 Autojs 7.0.4-1
1.3 Android Simulation Thunderbolt 7
1.4 Chopsticks v9.2.21.18848
Two, the actual code
Probability Js, after randomization, carry out probability distribution straight line or curve
/** * Probability 0-9, when it is greater than 3, the probability of the curve is used, and when it is less than 3, the probability of the line is used */ function randomFunction(){ return Math. floor(Math. random() * 10); }
slide screen function
/** * The curve sliding screen slides down and delays for n seconds */ function swipeCurveDown(qx, qy, zx, zy, time, timesInterval){ toastLog("curve sliding"); var xxy = [time]; var point = []; var dx0 = { "x": qx, "y": qy }; var dx1 = { "x": random(qx - 100, qx + 100), "y": random(qy, qy + 50) }; var dx2 = { "x": random(zx - 100, zx + 100), "y": random(zy, zy + 50), }; var dx3 = { "x": zx, "y": zy }; for (var i = 0; i < 4; i ++ ) { eval("point. push(dx" + i + ")"); }; for (let i = 0; i < 1; i + = 0.08) { let newPoint=bezier_curves(point, i); xxyy = [parseInt(newPoint.x), parseInt(newPoint.y)] xxy.push(xxyy); } gesture.apply(null, xxy); let randomMin = timesInterval * 1000; let randomMax = (parseInt(timesInterval) + 2) * 1000; let delayTime = random(randomMin, randomMax); sleep(delayTime); } /** * Slide the screen down in a straight line and delay n seconds */ function swipeLineDown(startX, startY, endX, endY, pressTime, timesInterval) { toastLog("Swipe straight"); swipe(startX, startY, endX, endY, pressTime); let randomMin = timesInterval * 1000; let randomMax = (parseInt(timesInterval) + 3) * 1000; let delayTime = random(randomMin, randomMax); sleep(delayTime); } /** * Bezier curve * @param {coordinate point} ScreenPoint * @param {offset} Offset */ function bezier_curves(ScreenPoint, Offset) { cx = 3.0 * (ScreenPoint[1].x - ScreenPoint[0].x); bx = 3.0 * (ScreenPoint[2].x - ScreenPoint[1].x) - cx; ax = ScreenPoint[3].x - ScreenPoint[0].x - cx - bx; cy = 3.0 * (ScreenPoint[1].y - ScreenPoint[0].y); by = 3.0 * (ScreenPoint[2].y - ScreenPoint[1].y) - cy; ay = ScreenPoint[3].y - ScreenPoint[0].y - cy - by; tSquared = Offset * Offset; tCubed = tSquared * Offset; result = { "x": 0, "y": 0 }; result.x = (ax * tCubed) + (bx * tSquared) + (cx * Offset) + ScreenPoint[0].x; result.y = (ay * tCubed) + (by * tSquared) + (cy * Offset) + ScreenPoint[0].y; return result; }
3. Truth (running log)
16:17:03.637/I: 4 seconds left…
16:17:04.640/I: 3 seconds left…
16:17:05.640/I: 2 seconds left…
16:17:06.641/I: 1 second left…
16:17:10.320/D: Linear slide
16:17:31.690/D: Curved sliding
16:17:53.247/D: Linear slide
16:18:15.925/D: Linear slide
16:18:37.583/D: Linear slide
16:18:58.384/D: Curved sliding
16:19:19.248/D: Linear slide
16:19:42.211/D: Linear slide
16:20:03.051/D: Curve sliding
16:20:25.343/D: Linear slide
16:20:47.903/D: Linear slide
16:21:09.548/D: Curved sliding
16:21:31.922/D: Curved sliding
4. Complete code (execute the code of chopsticks)
auto.waitFor();//judging and waiting to enable accessibility console.show(); //Open log (floating window permission) app.launchApp('Kuaishou');//There is only one Kuaishou to launch directly, no need for package name cutDownBySleep(8);//Waiting for splash time countdown timesInterval=20 let x1 = random(device. width * 0.8, device. width * 0.9); let y1 = device. height - (device. height * 0.15) let x2 = random(device. width * 0.8, device. width * 0.9); let y2 = device. height * 0.2 let pressTime = random(700, 800); adolescentWindows() closeUpgrageTip() clickVideo() while(true){ swipeScreenDown(x1, y1, x2, y2, pressTime, timesInterval) } function clickVideo() { if (text("Featured").exists()) { clickControlBounds(text("Selected")) } } /** * Teen window */ function adolescentWindows() { if (text("I know").exists()) { text("I know").findOnce().click(); } if (text("Got it").exists()) { text("Got it").findOnce().click(); } } /** * directly ignore */ function closeUpgrageTip() { if (text("Ignore").exists()) { text("Directly ignore").findOnce().click(); } if (text("Refresh and try again").exists()) { text("Refresh and try again").findOnce().click(); } } /** * Click the coordinates on the screen * @param {coordinates} b */ function clickControlBounds(element) { let clickResult = false; if (element == null) { return false; } try { if (element. exists()) { let b = element.findOnce().bounds(); clickResult = click(b. centerX(), b. centerY()); sleep(random(2000, 3200)); } else { } return clickResult; } catch (error) { toastLog("clickControlBounds method error:" + error) return false; } } /** * The countdown method is available for scripts * @param {countdown time} lasterTime */ function cutDownBySleep(lasterTime, message) { message=message || "" for (let i = lastTime; i => 0; i--) { console.info(message + "remaining" + i + "seconds...") sleep(1000) if (i == 1) { return } } } /** * Probability 0-9, when it is greater than 3, the probability of the curve is used, and when it is less than 3, the probability of the line is used */ function randomFunction(){ return Math. floor(Math. random() * 10); } /** * Swipe (default probability is 30%) * @param {*}qx * @param {*}qy * @param {*} zx * @param {*} zy * @param {*} time * @param {*} timesInterval */ function swipeScreenDown(qx, qy, zx, zy, time, timesInterval) { let probability = randomFunction() if (probability>=7) { swipeCurveDown(qx, qy, zx, zy, time, timesInterval); //curve probability } else { swipeLineDown(qx, qy, zx, zy, time, timesInterval); //line probability } } /** * The curve sliding screen slides down and delays for n seconds */ function swipeCurveDown(qx, qy, zx, zy, time, timesInterval){ toastLog("curve sliding"); var xxy = [time]; var point = []; var dx0 = { "x": qx, "y": qy }; var dx1 = { "x": random(qx - 100, qx + 100), "y": random(qy, qy + 50) }; var dx2 = { "x": random(zx - 100, zx + 100), "y": random(zy, zy + 50), }; var dx3 = { "x": zx, "y": zy }; for (var i = 0; i < 4; i ++ ) { eval("point. push(dx" + i + ")"); }; for (let i = 0; i < 1; i + = 0.08) { let newPoint=bezier_curves(point, i); xxyy = [parseInt(newPoint.x), parseInt(newPoint.y)] xxy.push(xxyy); } gesture.apply(null, xxy); let randomMin = timesInterval * 1000; let randomMax = (parseInt(timesInterval) + 2) * 1000; let delayTime = random(randomMin, randomMax); sleep(delayTime); } /** * Slide the screen down in a straight line and delay n seconds */ function swipeLineDown(startX, startY, endX, endY, pressTime, timesInterval) { toastLog("Swipe straight"); swipe(startX, startY, endX, endY, pressTime); let randomMin = timesInterval * 1000; let randomMax = (parseInt(timesInterval) + 3) * 1000; let delayTime = random(randomMin, randomMax); sleep(delayTime); } /** * Bezier curve * @param {coordinate point} ScreenPoint * @param {offset} Offset */ function bezier_curves(ScreenPoint, Offset) { cx = 3.0 * (ScreenPoint[1].x - ScreenPoint[0].x); bx = 3.0 * (ScreenPoint[2].x - ScreenPoint[1].x) - cx; ax = ScreenPoint[3].x - ScreenPoint[0].x - cx - bx; cy = 3.0 * (ScreenPoint[1].y - ScreenPoint[0].y); by = 3.0 * (ScreenPoint[2].y - ScreenPoint[1].y) - cy; ay = ScreenPoint[3].y - ScreenPoint[0].y - cy - by; tSquared = Offset * Offset; tCubed = tSquared * Offset; result = { "x": 0, "y": 0 }; result.x = (ax * tCubed) + (bx * tSquared) + (cx * Offset) + ScreenPoint[0].x; result.y = (ay * tCubed) + (by * tSquared) + (cy * Offset) + ScreenPoint[0].y; return result; }