《飞向未来》脚本

感谢 @tiancai9 佬让我时隔很久终于又逮到机会可以发帖子了,
《飞向未来》游猴脚本
我是个前端小白不太会前端,在gpt和克劳德的帮助下终于实现了个小脚本贴在下面,也是改了好几过版本,现在应该勉强能用,“一只大树”的持续点击按钮还有问题,感觉是在那个div持续点击导致没法停止也不知道为什么,就加了个全局停止的按钮
佬的帖子是

写的不是很好,来大佬帮忙更新一下tieba28


更新了一个版本,下面大佬说div里的data-hash是动态构建的,加上之前按钮的位置有一些问题,鼠标放到按钮上会有一个提示框出现,按钮会展示在框的上面很丑,我就又让克劳德优化了一下把按钮改到左边,但是问题又来了,我找不到之前的那串代码了tieba9 在我想修改document.querySelectorAll(‘div[data-v-87d557cd][class*=“building”]’);的时候我发现这串代码不见了,也不知道修改哪里了,
如果有大佬发现有问题可以把修改后的脚本贴到下面,我会复制过来直接更新掉现在的tieba9前端不太懂,你们说怎么修改之后我可能不知道改哪里tieba9


刚刚突然发现每个按钮后面都可以快速建造,之前没有注意,都是手点的,所以其实只有大树的点击有一点点用, 所以下面再放一份之前的脚本,悬浮框的点击

总结
// ==UserScript==
// @name         飞向未来悬浮窗
// @namespace    http://tampermonkey.net/
// @version      2024-11-22
// @description  自动点击游戏按钮(支持拖动和收起,按钮切换开关)
// @author       You
// @match        http://182.43.19.5:9999/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=19.5
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    const buttonMappings = [
        { label: "一只大树🌳" },
        { label: "打猎小屋" },
        { label: "简陋居所" },
        { label: "伐木小屋" },
        { label: "采集小屋" },
        { label: "玻璃工坊" },
        { label: "砖窑" },
        { label: "农田" },
        { label: "皮革工坊" },
        { label: "草药园" },
    ];

    // 用于保存每个按钮的定时器
    const clickIntervals = new Map();

    // 创建浮动控制面板
    const panel = document.createElement("div");
    Object.assign(panel.style, {
        position: "fixed",
        top: "20px",
        left: "20px",
        width: "200px",
        backgroundColor: "rgba(0, 0, 0, 0.8)",
        color: "white",
        padding: "10px",
        borderRadius: "8px",
        boxShadow: "0px 4px 6px rgba(0, 0, 0, 0.3)",
        zIndex: "9999",
        cursor: "move",
        userSelect: "none"
    });

    document.body.appendChild(panel);

    // 创建面板头部
    const header = document.createElement("div");
    Object.assign(header.style, {
        fontSize: "16px",
        fontWeight: "bold",
        marginBottom: "10px",
        display: "flex",
        justifyContent: "space-between",
        alignItems: "center"
    });
    header.innerText = "自动点击控制面板";
    panel.appendChild(header);

    // 添加收起按钮
    const toggleButton = document.createElement("button");
    toggleButton.innerText = "收起";
    Object.assign(toggleButton.style, {
        backgroundColor: "#f44336",
        color: "white",
        border: "none",
        padding: "5px 10px",
        borderRadius: "4px",
        cursor: "pointer"
    });
    header.appendChild(toggleButton);

    // 添加按钮组
    const buttonContainer = document.createElement("div");
    panel.appendChild(buttonContainer);

    // 设置收起和展开功能
    let isCollapsed = false;
    toggleButton.addEventListener("click", () => {
        isCollapsed = !isCollapsed;
        buttonContainer.style.display = isCollapsed ? "none" : "block";
        toggleButton.innerText = isCollapsed ? "展开" : "收起";
    });

    // 查找建筑的函数
    function findBuildingByName(name) {
        const buildings = document.querySelectorAll('.building-box > .building');
        for (const building of buildings) {
            const nameElement = building.querySelector('.name');
            if (nameElement && nameElement.innerText.trim() === name) {
                return nameElement;
            }
        }
        return null;
    }

    // 为每个目标创建切换按钮
    buttonMappings.forEach((button) => {
        const toggleButton = document.createElement("button");
        toggleButton.innerText = button.label;
        Object.assign(toggleButton.style, {
            width: "100%",
            marginBottom: "5px",
            backgroundColor: "#4CAF50",
            color: "white",
            border: "none",
            padding: "5px 10px",
            borderRadius: "4px",
            cursor: "pointer",
            transition: "background-color 0.3s"
        });

        buttonContainer.appendChild(toggleButton);

        // 按钮点击事件 - 切换开始/停止
        toggleButton.addEventListener("click", function() {
            const isRunning = clickIntervals.has(button.label);

            if (isRunning) {
                // 停止点击
                clearInterval(clickIntervals.get(button.label));
                clickIntervals.delete(button.label);
                toggleButton.style.backgroundColor = "#4CAF50";
                console.log(`停止点击: ${button.label}`);
            } else {
                // 开始点击
                const interval = setInterval(() => {
                    const targetElement = findBuildingByName(button.label);
                    if (targetElement) {
                        targetElement.click();
                    }
                }, 10);

                clickIntervals.set(button.label, interval);
                toggleButton.style.backgroundColor = "#f44336";
                console.log(`开始点击: ${button.label}`);
            }
        });
    });

    // 添加拖动功能
    let isDragging = false;
    let offsetX = 0;
    let offsetY = 0;

    header.addEventListener("mousedown", (e) => {
        isDragging = true;
        offsetX = e.clientX - panel.offsetLeft;
        offsetY = e.clientY - panel.offsetTop;
        panel.style.cursor = "grabbing";
    });

    document.addEventListener("mousemove", (e) => {
        if (isDragging) {
            panel.style.left = `${e.clientX - offsetX}px`;
            panel.style.top = `${e.clientY - offsetY}px`;
        }
    });

    document.addEventListener("mouseup", () => {
        isDragging = false;
        panel.style.cursor = "move";
    });

    // ESC 键停止所有点击
    document.addEventListener('keydown', (e) => {
        if (e.key === 'Escape') {
            // 停止所有点击
            clickIntervals.forEach((interval, label) => {
                clearInterval(interval);
                // 找到对应的按钮并重置样式
                const button = Array.from(buttonContainer.children).find(
                    btn => btn.innerText === label
                );
                if (button) {
                    button.style.backgroundColor = "#4CAF50";
                }
            });
            clickIntervals.clear();
            console.log('已停止所有点击');
        }
    });
})();

脚本如下:

总结
// ==UserScript==
// @name         飞向未来游戏改进版
// @namespace    http://tampermonkey.net/
// @version      2024-11-22
// @description  修复按钮位置问题,避免重复添加
// @author       You
// @match        http://182.43.19.5:9999/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=19.5
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    const clickIntervals = new Map();
    const clickingStatus = new Map();

    // 创建全局停止按钮
    function createGlobalStopButton() {
        const buttonContainer = document.createElement('div');
        Object.assign(buttonContainer.style, {
            position: 'fixed',
            top: '10px',
            right: '10px',
            zIndex: '10000',
            display: 'flex',
            gap: '10px'
        });

        // 创建停止所有按钮
        const stopAllButton = document.createElement('button');
        Object.assign(stopAllButton.style, {
            padding: '8px 16px',
            backgroundColor: '#f44336',
            color: 'white',
            border: 'none',
            borderRadius: '4px',
            cursor: 'pointer',
            fontSize: '14px',
            fontWeight: 'bold',
            boxShadow: '0 2px 4px rgba(0,0,0,0.2)'
        });
        stopAllButton.innerText = '停止所有点击';

        // 创建状态指示器
        const statusIndicator = document.createElement('div');
        Object.assign(statusIndicator.style, {
            padding: '8px 16px',
            backgroundColor: '#4CAF50',
            color: 'white',
            borderRadius: '4px',
            fontSize: '14px',
            display: 'flex',
            alignItems: 'center'
        });
        statusIndicator.innerText = '自动点击状态:空闲';

        // 停止所有点击的函数
        function stopAllClicking() {
            try {
                clickingStatus.clear();
                for (let [label, interval] of clickIntervals) {
                    clearInterval(interval);
                    console.log(`Stopped clicking for: ${label}`);
                }
                clickIntervals.clear();

                document.querySelectorAll('.persistent-click-btn').forEach(btn => {
                    btn.innerText = "持续";
                    btn.style.backgroundColor = "#4CAF50";
                });

                statusIndicator.innerText = '自动点击状态:已停止';
                statusIndicator.style.backgroundColor = '#f44336';

                console.log('已停止所有点击');
            } catch (error) {
                console.error('停止点击时发生错误:', error);
            }
        }

        stopAllButton.addEventListener('click', stopAllClicking);

        document.addEventListener('keydown', (e) => {
            if (e.key === 'Escape') {
                stopAllClicking();
            }
        });

        buttonContainer.appendChild(stopAllButton);
        buttonContainer.appendChild(statusIndicator);
        document.body.appendChild(buttonContainer);

        return { stopAllClicking, statusIndicator };
    }

    // 创建并添加建筑点击按钮
    function addPersistentClickButtons() {
        // 使用更精确的选择器,只选择内部的 building div
        const buildings = document.querySelectorAll('.building-box > .building');

        buildings.forEach((building) => {
            // 跳过不可见或已添加按钮的建筑
            if (building.style.opacity === "0" ||
                building.querySelector('.persistent-click-btn')) return;

            const nameElement = building.querySelector('.name');
            if (!nameElement) return;

            const label = nameElement.innerText.trim();

            const button = document.createElement('button');
            Object.assign(button.style, {
                position: "absolute",
                top: "5px",
                left: "5px",
                padding: "5px",
                fontSize: "12px",
                backgroundColor: "#4CAF50",
                color: "white",
                border: "none",
                borderRadius: "4px",
                cursor: "pointer",
                zIndex: "1000",
                opacity: "0.9"
            });

            button.className = "persistent-click-btn";
            button.innerText = "持续";
            building.style.position = "relative";

            // 点击处理逻辑
            button.addEventListener("click", () => {
                const globalStatus = document.querySelector('#globalStatusIndicator');

                if (clickIntervals.has(label)) {
                    // 停止点击
                    clearInterval(clickIntervals.get(label));
                    clickIntervals.delete(label);
                    clickingStatus.set(label, false);
                    button.innerText = "持续";
                    button.style.backgroundColor = "#4CAF50";
                    console.log(`停止点击: ${label}`);
                } else {
                    // 开始点击
                    clickingStatus.set(label, true);
                    const interval = setInterval(() => {
                        if (!clickingStatus.get(label)) {
                            clearInterval(interval);
                            return;
                        }
                        nameElement.click();
                    }, 10);

                    clickIntervals.set(label, interval);
                    button.innerText = "停止";
                    button.style.backgroundColor = "#f44336";
                    console.log(`开始点击: ${label}`);
                }

                // 更新全局状态显示
                const activeClicks = clickIntervals.size;
                const statusIndicator = document.querySelector('div[style*="border-radius: 4px"]');
                if (statusIndicator) {
                    statusIndicator.innerText = `自动点击状态:${activeClicks > 0 ? `点击中(${activeClicks})` : '空闲'}`;
                    statusIndicator.style.backgroundColor = activeClicks > 0 ? '#FFA500' : '#4CAF50';
                }
            });

            building.appendChild(button);
        });
    }

    // 初始化
    const { stopAllClicking } = createGlobalStopButton();

    // 定时检查新建筑
    const checkInterval = setInterval(addPersistentClickButtons, 1000);

    // 清理函数
    function cleanup() {
        clearInterval(checkInterval);
        stopAllClicking();
    }

    // 注册清理事件
    window.addEventListener('unload', cleanup);
    window.addEventListener('beforeunload', cleanup);
})();
5 个赞

感谢大佬分享

感谢大佬写的脚本,维护了大家的鼠标左键, :sob: :sob: :sob:

2 个赞

佬 佬,我不是,我不是tieba9 你是你是

你们都是大佬 :bili_040:

:sneezing_face: :sneezing_face: :sneezing_face:我是码农

1 个赞

我自己点的太累了,都是问GPT和克劳德的tieba9

膜拜大佬tieba28

这里的data-hash是每次构建动态生成的,你确定这样不会有问题?

1 个赞

我一点也看不懂tieba9我不知道这个代码是干嘛的 佬可以帮忙改改 tieba28

    const buildings = document.querySelectorAll('div[class*="building"]');

应该这样就对了

1 个赞

我好像有一点懂了,我说怎么之前的脚本在你更新之后就不能用了,我又重新生成了一个,原来是那个data-v会随机生成我靠 我懂了,我改一下

好好好,正说着手都快点出腱鞘炎了 ,脚本就来了

1 个赞

之前就想写脚本,f12一看是画板画的按钮,手都给爷点麻了 :clown_face:

1 个赞

现在不是了,害,我彻底优化了 :sneezing_face: :sneezing_face:

哈哈哈哈哈哈哈哈哈哈哈哈哈哈我笑死