【Autox.js】 微信机器人-顶部浮窗

var stop_storage = storages.create("stop");

//  执行前先清除上一次的记录
stop_storage.remove("stop")     // 暂停状态
stop_storage.remove("time")     // 执行倒计时
stop_storage.remove("cmd")        // cmd命令状态

cmd_map = {
    "INIT": "初始化",
    "undefined": "空闲中",
    "IDLE": "空闲中",
    "REQUEST_ADD_FRIEND": "加好友",
    "REPORT_FRIENDS_SUMMARY": "上报粉丝",
    "CHECK_FRIENDS_REQUEST": "被动接粉",
    "REPLY_NEW_USERS": "回复新用户",
    "SEND_CIRCLE_FRIEND": "发朋友圈",
    "BROWSER_CIRCLE_FRIEND": "浏览朋友圈",
    "BROWSE_ARTICLES": "浏览公众号",
    "UPDATE": "更新脚本",
    "ROLLBACK": "回退脚本",
    "EMPTY_THE_ALBUM":"清空相册"
}

function get_version() {
    // 获取当前项目版本
    var root_path = files.cwd()
    version_file = files.join(root_path, "/project.json")
    if (files.exists(version_file)) {
        infos = files.read(version_file)
        json_info = JSON.parse(infos)
        return json_info.versionName
    }
    return "0.0.0"
}
function countdown(second) {
    //  倒计时
    var s = Math.floor(second % 60);
    var m = Math.floor(second / 60);
    return `${`00${m}`.slice(-2)} : ${`00${s}`.slice(-2)}`;
}

cmd_text = "初始化"
info_text = "执行中,勿操作。如需操作,点击色块暂停"

function notice_win() {
    // 顶部信息弹窗
    screen_width = device.width
    aqu_widht = device.width / 1.6 / 3
    var notice_bar = floaty.rawWindow(
        <card cardCornerRadius="10" gravity="center">
            <vertical bg="#CCFF0000" id="notice" >
                <horizontal >
                    <vertical w="{{aqu_widht/4.5}}" h="20">
                        <text
                            textSize='8ps'
                            paddingLeft="5" gravity="left" textColor="#A0F5F5F5">
                            Wx助手
                        </text>
                        <text></text>
                    </vertical>

                    <text
                        paddingTop="10px"
                        id="cmd" gravity="center" textStyle="bold" w="{{aqu_widht/1.8}}" textSize='18ps' textColor="#F5F5F5">{cmd_text}
                    </text>

                    <vertical w="{{aqu_widht/4.5}}">
                        <text
                            textSize='8ps' paddingRight="5" gravity="right" textColor="#A0F5F5F5">V{get_version()}
                        </text>
                        <text></text>
                    </vertical>
                </horizontal>
                <text
                    textSize='9ps' id="info" gravity="center" textColor="#F5F5F5">
                    {info_text}
                </text>
            </vertical>
        </card>
    );
    notice_bar.setSize(screen_width / 1.6, 135)
    notice_bar.setTouchable(true);
    notice_bar.setPosition(screen_width / 5.5, 0)

    notice_bar.notice.click(function () {
        // 点击事件
        stop_storage.put("stop", !stop_storage.get("stop") ? 1 : 0)
    })

    setInterval(() => {
        ui.run(function () {
            stop_status = stop_storage.get("stop")
            if (!stop_status) {
                cmd_text =  cmd_map[stop_storage.get("cmd")] 
                if (cmd_text != "空闲中") {
                    info_text = "执行中,勿操作。如需操作,点击色块暂停"
                    notice_bar.notice.attr("bg", "#CCFF0000")
                } else {
                    info_text = "脚本空闲中,可操作手机"
                    notice_bar.notice.attr("bg", "#CC62D962")
                }
            } else {
                if (stop_status == 1) {
                    cmd_text = "准备暂停"
                    info_text = "正在暂停脚本,勿操作,请稍后..."
                    notice_bar.notice.attr("bg", "#CCFF0000")
                } else {
                    time = stop_storage.get('time')
                    cmd_text = '暂停中..'
                    info_text = `脚本暂停中,可操作手机,${countdown(time)}后可恢复`
                    time--;
                    stop_storage.put('time', time)
                    notice_bar.notice.attr("bg", "#CC62D962")
                }
            }
            notice_bar.cmd.setText(cmd_text)
            notice_bar.info.setText(info_text)
        })
    }, 1000)
}


if (!floaty.checkPermission()) {
    // 没有悬浮窗权限,提示用户并跳转请求
    toast("本脚本需要悬浮窗权限来显示悬浮窗,请在随后的界面中允许并重新运行本脚本。");
    floaty.requestPermission();
    exit();
} else {
    notice_win()
}
//启用按键监听
events.observeKey();
//监听音量上键按下
events.onKeyDown("volume_up", function(event){
    stop_storage.put("stop", !stop_storage.get("stop") ? 1 : 0)
    // device.setBrightness(stop_storage.get("stop")?35:5)
});

  效果图:

    

         

        

 

              

 

 

 

             

 

posted @ 2023-01-13 14:43  情调丶  阅读(243)  评论(0编辑  收藏  举报