抖音自动养号脚本app,智能化可随机时间,autojs开发学习案例

当然,这里分享的是框架部分代码,并非完整代码哈,仅供大家学习哈

AutoJS脚本代码实现

1. 初始化配置

// 配置参数
let config = {
    watchDuration: [5000, 15000], // 观看视频时长范围(毫秒)
    likeProbability: 0.6, // 点赞概率(0-1)
    commentProbability: 0.3, // 评论概率(0-1)
    followProbability: 0.2, // 关注概率(0-1)
    comments: [ // 自定义评论话术
        "真不错!",
        "支持一下!",
        "666!",
        "学到了!",
        "哈哈哈!"
    ],
    swipeInterval: [3000, 8000], // 滑动间隔时间范围(毫秒)
    loopCount: 20, // 循环操作次数(0表示无限循环)
};

// 启动脚本
main();

function main() {
    // 检查抖音是否已打开
    if (!launchApp("抖音")) {
        toast("请先打开抖音");
        exit();
    }
    sleep(5000);

    // 开始养号操作
    let count = 0;
    while (config.loopCount === 0 || count < config.loopCount) {
        watchVideo();
        randomSleep(config.swipeInterval[0], config.swipeInterval[1]); // 随机滑动间隔
        count++;
    }
    toast("养号操作完成");
}

2. 观看视频

function watchVideo() {
    // 随机观看时长
    let duration = random(config.watchDuration[0], config.watchDuration[1]);
    sleep(duration);

    // 随机点赞
    if (Math.random() < config.likeProbability) {
        likeVideo();
    }

    // 随机评论
    if (Math.random() < config.commentProbability) {
        commentVideo();
    }

    // 随机关注作者
    if (Math.random() < config.followProbability) {
        followAuthor();
    }

    // 滑动到下一个视频
    swipeToNextVideo();
}

3. 点赞视频

function likeVideo() {
    let likeButton = desc("点赞").findOne();
    if (likeButton) {
        likeButton.click();
        toast("已点赞视频");
    } else {
        toast("未找到点赞按钮");
    }
}

4. 评论视频

function commentVideo() {
    // 点击评论按钮
    let commentButton = desc("评论").findOne();
    if (commentButton) {
        commentButton.click();
        sleep(2000);
    } else {
        toast("未找到评论按钮");
        return;
    }

    // 输入评论内容
    let commentInput = id("com.ss.android.ugc.aweme:id/et_input").findOne();
    if (commentInput) {
        let comment = getRandomComment();
        commentInput.setText(comment);
        sleep(1000);

        // 点击发送按钮
        let sendButton = id("com.ss.android.ugc.aweme:id/aoh").findOne();
        if (sendButton) {
            sendButton.click();
            toast("已发送评论:" + comment);
        } else {
            toast("未找到发送按钮");
        }
    } else {
        toast("未找到评论输入框");
    }

    // 返回视频页面
    back();
    sleep(1000);
}

5. 随机选择评论

function getRandomComment() {
    let index = Math.floor(Math.random() * config.comments.length);
    return config.comments[index];
}

6. 关注作者

function followAuthor() {
    // 点击作者头像进入主页
    let authorAvatar = id("com.ss.android.ugc.aweme:id/avatar").findOne();
    if (authorAvatar) {
        authorAvatar.click();
        sleep(3000);
    } else {
        toast("未找到作者头像");
        return;
    }

    // 点击关注按钮
    let followButton = text("关注").findOne();
    if (followButton) {
        followButton.click();
        toast("已关注作者");
    } else {
        toast("未找到关注按钮");
    }

    // 返回视频页面
    back();
    sleep(1000);
}

7. 滑动到下一个视频

function swipeToNextVideo() {
    // 模拟向上滑动
    let screenWidth = device.width;
    let screenHeight = device.height;
    let startX = screenWidth / 2;
    let startY = screenHeight * 0.8;
    let endY = screenHeight * 0.2;
    swipe(startX, startY, startX, endY, 500);
    toast("已滑动到下一个视频");
}

8. 随机休息(避免频繁操作)

function randomSleep(min, max) {
    let sleepTime = random(min, max);
    sleep(sleepTime);
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值