侧边栏壁纸
博主头像
DeQ

江流宛转绕芳甸,月照花林皆似霰

  • 累计撰写 23 篇文章
  • 累计创建 12 个标签
  • 累计收到 5 条评论

目 录CONTENT

文章目录

Auto.js开发安卓自动化脚本

DeQ
DeQ
2020-11-03 / 0 评论 / 0 点赞 / 838 阅读 / 2,932 字

双十一又来了,看着淘宝双十一的领喵币,我不经陷入了沉思...

领喵币可以,但浪费时间领喵币,不行!

Auto.js

介绍

一个不需要Root权限的类似按键精灵的自动操作软件,可以实现自动点击、滑动、输入文字、打开应用等。用于编写软件和游戏脚本,解放双手,轻松完成日常自动化工作流任务。

Auto.js使用JavaScript作为脚本语言。

GitHub:
https://github.com/hyb1996/Auto.js

文档:
https://hyb1996.github.io/AutoJs-Docs/#/

pro版文档:
https://pro.autojs.org/docs/#/

APP下载地址:

官网写的在<酷安>下载,但只能下载到Auto.js Pro,为收费版本。

这里找到一个Auto.js 4.1.0
https://www.lanzous.com/b0dpip61e

编写脚本案例/demo

# 官方demo
https://github.com/hyb1996/Auto.js/tree/master/app/src/main/assets/sample

# 其它
https://github.com/bayson/autojs
https://github.com/bjc5233/autojs

淘宝双十一自动领喵币脚本

/**
* @fileOverview 脚本 - 淘宝双十一领喵币
* @description 本脚本在Auto.Js 4.1.1版及pro版本中,淘宝9.5.7,测试通过!
* @author <a href="https://www.deq.plus">deq</a>
* @date 2020-10-30
*/

// 带时间输出日志
function printLog(logText) {
    if(!logText){
        return false;
    }

    let date = new Date();
    
    let year = date.getFullYear();
    let month = date.getMonth();
    let day = date.getDate();

    let hours = date.getHours();
    hours = hours < 10 ? "0"+hours.toString() : hours;
    let minutes = date.getMinutes();
    minutes = minutes < 10 ? "0"+minutes.toString() : minutes;
    let seconds = date.getSeconds();

    let nowDate = year + "/" + month + "/"  + day + " " + hours + ":"  + minutes + ":"  + seconds;

    console.log(nowDate + " " + logText.toString());
}

taobaoShuangshiyi = {
    init: function() {
        //显示控制台
        console.show();
        // 等待无障碍启动后继续
        try {
            auto.waitFor();
        } catch (error) {
            toast("请手动开启无障碍并授权给Auto.js");
            sleep(2000);
            exit();
        }
        
        // mi8 全面屏 1080 * 2248
        setScreenMetrics(1080, 2248);
    },
    run: function(){
        this.init();
        this.startApp();
    },
    startApp: function(){
        printLog("启动淘宝");
        launch("com.taobao.taobao");

        printLog("6秒后进入活动");
        sleep(6000);

        this.doTask();
    },
    doTask: function(){
        // 淘宝是否启动(随便拿个检测)
        let searchBtn = desc("搜索").findOne();
        if(searchBtn){
            /* 一、打开养喵活动页面 */

            // 淘宝9.5.7
            let ui_act = desc("主互动").findOnce();
            if(ui_act){
                ui_act.click();
            }else{
                log("未能找到活动入口,请手动打开");   // 输出日志
            }

            /* 二、打开赚喵币面板,查看任务 */
            let zmbBtn = text("赚喵币").findOne();
            // click(920.5, 2059);

            if(zmbBtn){
                zmbBtn.click();
                sleep(5000);    // 给5秒加载任务列表(够了吧...)
            
                if (text("去浏览").exists()) {
                    this.taskGoBrowse();
                };
                
                // over
                if(typeof nowTaskThreads_isOver !== "undefined"){
                    // console.log("nowTaskThreads_isOver存在, 发出通知");
                    //发送事件result通知主线程接收结果
                    printLog("任务完成");
                    nowTaskThreads_isOver.emit('result', true);   // 该脚本已运行完成
                }
                
            }else{
                printLog("加载过慢, 请重试");   // 输出日志
                return false;
            }


        }
    },
    taskGoBrowse: function(){
        let nowBrowse;

        while (text("去浏览").exists()) {
            nowBrowse = text("去浏览").findOne();
    
            let nowBrowsePar = nowBrowse.parent();
            let detailText = nowBrowsePar.child(0);
            printLog(detailText.child(0).text());   // 输出日志-当前任务内容
    
            nowBrowse.click();
    
            sleep(25000);   // 15秒的任务,这里多出的10秒给其它情况(比如加载等)
    
            if(textContains("完成").exists()){
                printLog("返回");
                back();
            } else {
                sleep(300);    // 再等3秒
                printLog("返回");
                back();
            }
            sleep(3000);
        }
    },
    // &
}

taobaoShuangshiyi.run();

ps: 淘宝已经在新版本加入了 检测<无障碍权限应用列表>,一旦发现奇奇怪怪的程序,喵币获取只能得到100~300之间。实测低版本淘宝(9.5.7)不受影响。

0

评论区