图寻眨眼模式

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

目前為 2023-07-19 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 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.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);
})();