Auto.js 是个基于 JavaScript 语言运行在Android平台上的脚本框架。Auto.js主要工作原理是基于辅助服务AccessibilityService。今天主要和大家分享一下刷刷刷过程中提示直播的窗体关闭问题,我的手机判断一下android.widget.RelativeLayout控件的数量。9个是正常的超过了就是有直播提醒。当然不同的手机可能不一样,大家自己修改一下吧!
let liveVideo=className ("android.widget.RelativeLayout").find();
if(liveVideo.length>9){

clickScreen();
}
let liveVideo=className ("android.widget.RelativeLayout").find();
if(liveVideo.length>9){

clickScreen();
}其实还有一个思路:就是每一次都点击一下屏幕。总体代码:
auto.waitFor();
let see_count = 1000;// rawInput('请输入滑动次数',"3000");
app.launchApp('刷宝短视频');
sleep(4000);
console.show(); //开启日志(悬浮窗权限)
authorityCancleTip();//点击权限取消按钮
for (var i = 1; i < see_count; i++) {
toast("刷宝短视频滑动" + i + '次');
console.log("刷宝短视频滑动" + i + '次' + "总计:" + see_count + "次");
shuabaoCloseAD();
randomDownSildeScreen();
randomHeart();
randomFollow();
slideScreenDown(device.width / 2, device.height * 0.8, device.width / 2, device.height * 0.1, 400);
}
//退到主页面
home();
/**
* 刷宝关闭广告
*/
function shuabaoCloseAD() {
let liveVideo=className ("android.widget.RelativeLayout").find();
if(liveVideo.length>9){

clickScreen();
}
if (id("hotspot_imgdismiss").exists()) {

id("hotspot_imgdismiss").findOnce().click();
}
}
/**
* 屏幕向下滑动并延迟8至12秒
*/
function slideScreenDown(startX, startY, endX, endY, pressTime) {
swipe(startX, startY, endX, endY, pressTime);
delayTime = random(8000, 10000);
sleep(delayTime);//模仿人类随机时间
}
/**
*点击一下屏幕
*/
function clickScreen() {
var x = device.width - device.width * 0.2;
var y = device.height - device.height * 0.2;
toastLog("点击屏幕" + x + ":" + y);
let clickResult = click(x, y);
toastLog(clickResult);
}
function authorityCancleTip() {
if(text("取消").exists()){

text("取消").findOnce().click();
}
if (id("cancel").exists()) {

id("cancel").findOnce().click();
}
}
/**
* 随机上滑(防止被判定是机器)上滑后停留时间至少是10S,造成假象表示是对内容感兴趣
* 点赞和关注先不搞。
*/
function randomUpSildeScreen() {
let randomIndex = random(1, 40);
if (randomIndex == 1) {

console.log("随机上滑被执行了");

pressTime = random(200, 500);

swipe(device.width / 2, 500, device.width / 2, device.height - 200, 700);

delayTime = random(8000, 10000);

sleep(delayTime);
}
}
/**
* 连续下滑对上一个无兴趣
* 其实得和上滑做个排他,既然无兴趣不要在上滑
*/
function randomDownSildeScreen() {
let randomIndex = random(1, 20);
if (randomIndex == 1) {

console.log("连续下滑被执行了");

swipe(device.width / 2, device.height * 0.8, device.width / 2, device.height * 0.1, 400);

sleep(2000);

swipe(device.width / 2, device.height * 0.8, device.width / 2, device.height * 0.1, 400);

delayTime = random(8000, 10000);

sleep(delayTime);
}
}
/**随机点赞并休息一秒 */
function randomHeart() {
index = random(1, 10);
if (index == 6) {

if(id("praise").exists()){

id("praise").findOnce().click();

}
}
}
function randomFollow() {
index = random(1, 10);
if (index == 6) {

if(id('tv_ad_attention').exists()){

id("tv_ad_attention").findOnce().click();

}else{

if(text("关注").exists()){

text("关注").findOnce().click();

}

}
}
}
auto.waitFor();
let see_count = 1000;// rawInput('请输入滑动次数',"3000");
app.launchApp('刷宝短视频');
sleep(4000);
console.show(); //开启日志(悬浮窗权限)
authorityCancleTip();//点击权限取消按钮
for (var i = 1; i < see_count; i++) {
toast("刷宝短视频滑动" + i + '次');
console.log("刷宝短视频滑动" + i + '次' + "总计:" + see_count + "次");
shuabaoCloseAD();
randomDownSildeScreen();
randomHeart();
randomFollow();
slideScreenDown(device.width / 2, device.height * 0.8, device.width / 2, device.height * 0.1, 400);
}
//退到主页面
home();
/**
* 刷宝关闭广告
*/
function shuabaoCloseAD() {
let liveVideo=className ("android.widget.RelativeLayout").find();
if(liveVideo.length>9){

clickScreen();
}
if (id("hotspot_imgdismiss").exists()) {

id("hotspot_imgdismiss").findOnce().click();
}
}
/**
* 屏幕向下滑动并延迟8至12秒
*/
function slideScreenDown(startX, startY, endX, endY, pressTime) {
swipe(startX, startY, endX, endY, pressTime);
delayTime = random(8000, 10000);
sleep(delayTime);//模仿人类随机时间
}
/**
*点击一下屏幕
*/
function clickScreen() {
var x = device.width - device.width * 0.2;
var y = device.height - device.height * 0.2;
toastLog("点击屏幕" + x + ":" + y);
let clickResult = click(x, y);
toastLog(clickResult);
}
function authorityCancleTip() {
if(text("取消").exists()){

text("取消").findOnce().click();
}
if (id("cancel").exists()) {

id("cancel").findOnce().click();
}
}
/**
* 随机上滑(防止被判定是机器)上滑后停留时间至少是10S,造成假象表示是对内容感兴趣
* 点赞和关注先不搞。
*/
function randomUpSildeScreen() {
let randomIndex = random(1, 40);
if (randomIndex == 1) {

console.log("随机上滑被执行了");

pressTime = random(200, 500);

swipe(device.width / 2, 500, device.width / 2, device.height - 200, 700);

delayTime = random(8000, 10000);

sleep(delayTime);
}
}
/**
* 连续下滑对上一个无兴趣
* 其实得和上滑做个排他,既然无兴趣不要在上滑
*/
function randomDownSildeScreen() {
let randomIndex = random(1, 20);
if (randomIndex == 1) {

console.log("连续下滑被执行了");

swipe(device.width / 2, device.height * 0.8, device.width / 2, device.height * 0.1, 400);

sleep(2000);

swipe(device.width / 2, device.height * 0.8, device.width / 2, device.height * 0.1, 400);

delayTime = random(8000, 10000);

sleep(delayTime);
}
}
/**随机点赞并休息一秒 */
function randomHeart() {
index = random(1, 10);
if (index == 6) {

if(id("praise").exists()){

id("praise").findOnce().click();

}
}
}
function randomFollow() {
index = random(1, 10);
if (index == 6) {

if(id('tv_ad_attention').exists()){

id("tv_ad_attention").findOnce().click();

}else{

if(text("关注").exists()){

text("关注").findOnce().click();

}

}
}
}总结总结总结