Greasy Fork

Greasy Fork is available in English.

图寻眨眼模式

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

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

// ==UserScript==
// @name         图寻眨眼模式
// @namespace    http://tampermonkey.net/
// @version      1.31
// @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';
            }, 600);  // 这里的单位是毫秒,可以自行修改,由于图片加载动画比较慢,如果时间越短,可能就不会出现图片了,这里的时间包含了图片加载时间和眨眼时间。
        }
    });

    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);
})();