图寻眨眼模式

进入游戏后0.1秒后自动隐藏全景图像,按空格键刷新页面并翻页

目前為 2023-09-14 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         图寻眨眼模式
// @namespace    http://tampermonkey.net/
// @version      1.52
// @description  进入游戏后0.1秒后自动隐藏全景图像,按空格键刷新页面并翻页
// @author       宇宙百科君
// @match        https://tuxun.fun/*
// @run-at       document-start
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // 从localStorage初始化眨眼模式状态
    var blinkMode = localStorage.getItem('blinkMode') !== 'false';

    // 初始化刷新状态
    let refreshEnabled = false;

// 第1部分:进入游戏后1秒自动隐藏全景图像
let isObserverActive = true;  // 添加一个标志来跟踪观察者的状态

let observer = new MutationObserver((mutations) => {
    if (blinkMode && isObserverActive) {
        let mapRoot = document.querySelector('.widget-scene-canvas');
        if (mapRoot && getComputedStyle(mapRoot).display !== 'none' && getComputedStyle(mapRoot).opacity !== '0') {
            mapRoot.style.opacity = '0';
            isObserverActive = false;  // 设置观察者标志为false
            setTimeout(() => {
                mapRoot.style.opacity = '1';  // 3秒后显示全景图
                setTimeout(() => {
                    mapRoot.style.opacity = '0';  // 再经过3秒隐藏全景图
                }, 200);
            }, 2000);
        }
    }
});

observer.observe(document.body, {
    attributes: true,
    attributeFilter: ['style', 'width', 'height'],
    subtree: true
});


    // 第2部分:按空格键刷新页面
    async function handleKeyPressForRefresh(e) {
        // 检查是否按下的是空格键(键码32)
        if (e.keyCode === 32 && blinkMode) {
            // 刷新页面前等待0.5秒
            await new Promise(resolve => setTimeout(resolve, 500));
            // 检查特定DOM元素是否存在
            var specificDomElement = document.querySelector('.round_result_center');
            if (!specificDomElement && refreshEnabled) {
                // 如果特定DOM元素不存在且已启用刷新,则刷新页面
                location.reload();
            } else if (specificDomElement) {
                // 如果特定DOM元素存在,启用刷新
                refreshEnabled = true;
            }
        }
    }
// 更改父级容器的高度

let urlPattern = /^https:\/\/tuxun\.fun\/maps-start\?mapsId=\d+$/;

if (urlPattern.test(window.location.href)) {

    // 创建眨眼模式切换按钮
document.addEventListener("DOMContentLoaded", function() {
// 创建开关容器元素
var switchContainer = document.createElement('div');
switchContainer.style.position = "relative"; // 设置绝对定位
switchContainer.style.top = "39.5%"; // 设置顶部距离
switchContainer.style.left = "50%"; // 设置左侧距离
switchContainer.style.transform = "translate(-50%, -50%)"; // 将元素居中
switchContainer.style.zIndex = "9999"; // 设置 z-index 层级
switchContainer.style.width = "40px"; // 设置宽度
switchContainer.style.height = "20px"; // 设置高度
switchContainer.style.border = "0px solid rgb(19, 206, 102)"; // 设置边框
switchContainer.style.borderRadius = "25px"; // 设置圆角
switchContainer.style.overflow = ""; // 隐藏溢出内容
switchContainer.style.cursor = "pointer"; // 添加点击指针样式


    // 创建一个包含“眨眼模式”文字的元素
var switchLabel = document.createElement('div');
switchLabel.innerText = "眨眼模式";  // 设置文本内容
switchLabel.style.color = "#fff";  // 设置字体颜色为白色
switchLabel.style.backgroundColor = "rgba(0, 0, 0, 0)";  // 添加半透明的黑色背景
switchLabel.style.padding = "0";  // 添加一些内边距
switchLabel.style.borderRadius = "4px";  // 圆角
switchLabel.style.position = "absolute";  // 定位
switchLabel.style.bottom = "100%";  // 放置在开关容器的上方
switchLabel.style.left = "50%";  // 水平居中
switchLabel.style.transform = "translateX(-50%)";  // 调整为从中心点向左偏移,使其完全居中
switchLabel.style.fontFamily = "Arial, sans-serif";  // 字体样式
switchLabel.style.fontSize = "18px";  // 字体大小
switchLabel.style.writingMode = "horizontal-tb";
switchLabel.style.width = "120px";  // 显式设置宽度
switchLabel.style.whiteSpace = "nowrap";  // 防止文本换行
switchLabel.style.textAlign = "center";  // 添加文本居中属性
switchLabel.style.marginBottom = "0";  // 与开关之间的距离
switchContainer.appendChild(switchLabel);  // 将标签添加到开关容器中
switchLabel.style.cursor = "text";


// 创建开关背景元素
var switchBackground = document.createElement('div');
switchBackground.style.width = "100%"; // 设置宽度为 100%
switchBackground.style.height = "100%"; // 设置高度为 100%
switchBackground.style.backgroundColor = blinkMode ? "rgb(19, 206, 102)" : "red";  // 初始状态为反转颜色
switchBackground.style.transition = "background-color 0.2s"; // 减小背景颜色过渡时间
switchContainer.appendChild(switchBackground);
switchBackground.style.borderRadius = "25px"; // 设置圆角

// 创建白色按钮元素
var switchButton = document.createElement('div');
switchButton.style.width = "16px"; // 设置宽度
switchButton.style.height = "16px"; // 设置高度
switchButton.style.top = "12%"; // 设置垂直居中
switchButton.style.backgroundColor = "#fff"; // 设置背景颜色为白色
switchButton.style.borderRadius = "50%"; // 设置圆角
switchButton.style.position = "absolute"; // 设置绝对定位
switchButton.style.transition = "left 0.3s"; // 减小按钮平滑移动的过渡时间
switchButton.style.left = blinkMode ? "20px" : "0"; // 初始位置为反转按钮位置
switchBackground.appendChild(switchButton);
switchButton.style.borderRadius = "50%"; // 设置圆角

let targetLeft = blinkMode ? 0 : 20; // 初始位置目标值为反转位置
let isAnimating = false;



// 添加点击事件监听器
switchContainer.addEventListener("click", function() {
    if (!isAnimating) {

        isAnimating = true;
        blinkMode = !blinkMode;
        // 保存新的blinkMode状态到localStorage
        localStorage.setItem('blinkMode', blinkMode);
        switchBackground.style.backgroundColor = blinkMode ?  "rgb(19, 206, 102)" : "red"; // 反转颜色
        targetLeft = blinkMode ? 20 : 0;

        animateButton();
    }
});

// 创建按钮动画函数
function animateButton() {
    const currentLeft = parseFloat(getComputedStyle(switchButton).left);
    const step = (targetLeft - currentLeft);

    if (Math.abs(targetLeft - currentLeft) > 0.5) {
        switchButton.style.left = currentLeft + step + "px";
        requestAnimationFrame(animateButton);
    } else {
        switchButton.style.left = targetLeft + "px";
        isAnimating = false;
    }
}
    switchLabel.addEventListener("click", function(event) {
    event.stopPropagation();  // 阻止事件冒泡
});
 // 将状态保存到loclStorage
        localStorage.setItem('blinkMode', blinkMode);
     // 尝试将按钮插入到指定位置
setTimeout(function() {
    let targetElement = document.querySelector('div[data-v-515b103e][style="padding-top: 2rem;"]');
    if(targetElement) {
        targetElement.appendChild(switchContainer);
        targetElement.style.height = "80px";  // 这里更改目标元素的高度
    } else {
        document.body.appendChild(switchContainer);
    }
}, 500); // 延迟2秒


let elementToChange = document.querySelector('div[data-v-515b103e][style="padding-top: 2rem;"]');
if (elementToChange) {
    elementToChange.style.height = "500px";
}
});
}

    // 第3部分:按空格键翻页
    function handleKeyPressForNextPage(e) {
        // 检查是否按下的是空格键(键码32)
        if (e.keyCode === 32) {
            // 查找“下一页”按钮并点击它
            var nextPageButton = document.querySelector('.confirm .el-button.el-button--default.el-button--medium.is-round');
            if (nextPageButton) {
                nextPageButton.click();
            }
        }
    }

    // 第4部分:按空格键触发另一个选择器
    function handleKeyPressForAnotherSelector(e) {
        // 检查是否按下的是空格键(键码32)
        if (e.keyCode === 32) {
            // 查找另一个选择器并执行相应操作
            var buttons = document.querySelectorAll('button');
            var startButton;
            var replayButton;
            var preserveButton;
            for (var i = 0; i < buttons.length; i++) {
                if (buttons[i].textContent == '开始') {
                    startButton = buttons[i];
                }
                if (buttons[i].textContent == '再来一局') {
                    replayButton = buttons[i];
                }
                if (buttons[i].textContent == '保留') {
                    preserveButton = buttons[i];
                }
            }
            if (startButton) {
                startButton.click();
            }
            if (replayButton) {
                replayButton.click();
            }
            if (preserveButton) {
                preserveButton.click();
            }
        }
    }

    // 每隔500ms检查"下一题"按钮是否已经出现
    var checkExist = setInterval(function() {
        var nextPageButton = document.querySelector('.confirm .el-button.el-button--default.el-button--medium.is-round');
        if (nextPageButton) {
            // 如果"下一题"按钮已经出现,添加键盘按键事件监听器,并停止定时器
            document.addEventListener('keydown', handleKeyPressForNextPage);
            clearInterval(checkExist);
        }
    }, 500);

    // 监听DOM变化的函数看是否或出现比赛
function observeDOMChanges() {
    // 配置observer的选项: 添加或删除的子节点
    var config = { childList: true, subtree: true };

    // 当DOM发生变化时调用的回调函数
    var callback = function(mutationsList, observer) {
        for(var mutation of mutationsList) {
            // 如果有子节点被添加
            if(mutation.addedNodes.length) {
                mutation.addedNodes.forEach(function(node) {
                    // 检查该节点是否是你想要的元素
                    if(node.nodeType === Node.ELEMENT_NODE && node.classList.contains("van-toast") && node.classList.contains("van-toast--middle") && node.classList.contains("van-toast--text")) {
                        var innerDiv = node.querySelector('.van-toast__text');
                        if(innerDiv && innerDiv.textContent === "比赛已经开始或者这一轮游戏还未结束") {
                            node.style.transition = 'none';
                            node.style.animation = 'none';
                            node.style.opacity = '0';
                        }
                    }
                });
            }
        }
    };

    // 创建一个observer实例与回调函数关联
    var observer = new MutationObserver(callback);

    // 在整个document上开始观察DOM的变化
    observer.observe(document, config);
}

// 调用上面的函数以开始监听DOM变化
observeDOMChanges();
let elementToChange = document.querySelector('div[data-v-515b103e][style="padding-top: 2rem;"]');
if (elementToChange) {
    elementToChange.style.height = "500px";
}

    // 监听按键事件
    document.addEventListener('keydown', handleKeyPressForRefresh);
    document.addEventListener('keydown', handleKeyPressForAnotherSelector);
})();