帮我使用Floaty模块,绘制一个好看的控制台,包含:启动、暂停、结束开关。

已存档
shαdow · 1 个月前

回答

Hamibot AI
1
· 1 个月前
// 文档地址 https://docs.hamibot.com/
auto.waitFor();
var handlers = {
    running: false,
    paused: false,
    
    start: function() {
        if (this.running) return;
        this.running = true;
        this.paused = false;
        toast("任务开始");
        // 这里添加启动逻辑
    },
    
    pause: function() {
        if (!this.running) return;
        this.paused = !this.paused;
        toast(this.paused ? "任务暂停" : "继续执行");
        // 这里添加暂停/继续逻辑
    },
    
    stop: function() {
        if (!this.running) return;
        this.running = false;
        this.paused = false;
        toast("任务结束");
        // 这里添加停止逻辑
    }
};

var floatyWin = floaty.window(
    <vertical padding="16" bg="#222222">
        <button id="startBtn" text="启动" 
                w="160" h="48" 
                textSize="16" 
                bg="#4CAF50" 
                textColor="#FFFFFF" 
                margin="0 8 0 0"/>
        <button id="pauseBtn" text="暂停" 
                w="160" h="48" 
                textSize="16" 
                bg="#FFA726" 
                textColor="#FFFFFF" 
                margin="0 8 0 0" 
                enabled="false"/>
        <button id="stopBtn" text="结束" 
                w="160" h="48" 
                textSize="16" 
                bg="#F44336" 
                textColor="#FFFFFF" 
                margin="0 8 0 0" 
                enabled="false"/>
    </vertical>
);

// 按钮事件处理
floatyWin.startBtn.click(function() {
    handlers.start();
    ui.run(function() {
        floatyWin.startBtn.enabled = false;
        floatyWin.pauseBtn.enabled = true;
        floatyWin.stopBtn.enabled = true;
    });
});

floatyWin.pauseBtn.click(function() {
    handlers.pause();
    ui.run(function() {
        floatyWin.pauseBtn.text = handlers.paused ? "继续" : "暂停";
    });
});

floatyWin.stopBtn.click(function() {
    handlers.stop();
    ui.run(function() {
        floatyWin.startBtn.enabled = true;
        floatyWin.pauseBtn.enabled = false;
        floatyWin.stopBtn.enabled = false;
    });
});

// 保持悬浮窗显示
setInterval(function() {}, 1000);
ℹ️ 本回答由 AI 生成,内容仅供参考