图寻眨眼模式

Automatically hides the panorama image 1 second after entering a game, refresh page and turn page on spacebar press

当前为 2023-07-19 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

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

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         图寻眨眼模式
// @namespace    http://tampermonkey.net/
// @version      1.2
// @description  Automatically hides the panorama image 1 second after entering a game, refresh page and turn page on spacebar press
// @author       某人
// @match        https://tuxun.fun/*
// @run-at       document-start
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // Initialize the refresh state
    let refreshEnabled = false;

    // Part 1: Automatically hides the panorama image 1 second after entering a game
    let observer = new MutationObserver((mutations) => {
        let mapRoot = document.querySelector('.widget-scene-canvas');
        if (mapRoot && getComputedStyle(mapRoot).display !== 'none') {
            setTimeout(() => {
                mapRoot.style.opacity = '0';
            }, 400);  
        }
    });

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

    // Part 2: Refresh page on spacebar press
    async function handleKeyPressForRefresh(e) {
        // Check if the pressed key was the spacebar (key code 32)
        if (e.keyCode === 32) {
            // Add a delay of 0.5 seconds before refreshing the page
            await new Promise(resolve => setTimeout(resolve, 500));
            // Check if the specific DOM element exists
            var specificDomElement = document.querySelector('.round_result_center');
            if (!specificDomElement && refreshEnabled) {
                // If the specific DOM element does not exist and refresh is enabled, refresh the page
                location.reload();
            } else if (specificDomElement) {
                // If the specific DOM element exists, enable the refresh
                refreshEnabled = true;
            }
        }
    }

    // Part 3: Turn page on spacebar press
    function handleKeyPressForNextPage(e) {
        // Check if the pressed key was the spacebar (key code 32)
        if (e.keyCode === 32) {
            // Find the "next page" button and click it
            var nextPageButton = document.querySelector('.confirm .el-button.el-button--default.el-button--medium.is-round');
            if (nextPageButton) {
                nextPageButton.click();
            }
        }
    }

    // Part 4: Trigger another selector on spacebar press
function handleKeyPressForAnotherSelector(e) {
    // Check if the pressed key was the spacebar (key code 32)
    if (e.keyCode === 32) {
        // Find the another selector and do something
        var buttons = document.querySelectorAll('button');
        var startButton;
        var replayButton;
        for (var i = 0; i < buttons.length; i++) {
            if (buttons[i].textContent == '开始') {
                startButton = buttons[i];
            }
            if (buttons[i].textContent == '再来一局') {
                replayButton = buttons[i];
            }
        }
        if (startButton) {
            // Do something with startButton
            startButton.click();
        }
        if (replayButton) {
            // Do something with replayButton
            replayButton.click();
        }
    }
}

    // 每隔500毫秒检查一下"下一题"按钮是否已经出现
    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);

    // Listen for key press events
    document.addEventListener('keydown', handleKeyPressForRefresh);
    document.addEventListener('keydown', handleKeyPressForAnotherSelector);
})();