Automatically hides the panorama image 1 second after entering a game, refresh page and turn page on spacebar press
当前为
// ==UserScript==
// @name 图寻眨眼模式
// @namespace http://tampermonkey.net/
// @version 1.32
// @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;
// Initialize the blink mode state from localStorage
var blinkMode = localStorage.getItem('blinkMode') !== 'false';
// Part 1: Automatically hides the panorama image 1 second after entering a game
let observer = new MutationObserver((mutations) => {
if (blinkMode) {
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;
}
}
}
// Create the blink mode switch button
var blinkSwitch = document.createElement('button');
blinkSwitch.innerText = "眨眼" + (blinkMode ? "开启" : "关闭");
blinkSwitch.style.position = "fixed";
blinkSwitch.style.top = "5px";
blinkSwitch.style.left = "99%";
blinkSwitch.style.transform = "translateX(-50%)";
blinkSwitch.style.zIndex = "9999";
blinkSwitch.style.background = "#fff";
blinkSwitch.style.border = "none";
blinkSwitch.style.borderRadius = "25px";
blinkSwitch.style.padding = "5px 5px";
blinkSwitch.onclick = function() {
blinkMode = !blinkMode;
blinkSwitch.innerText = "眨眼" + (blinkMode ? "开启" : "关闭");
// Save the state to localStorage
localStorage.setItem('blinkMode', blinkMode);
};
document.body.appendChild(blinkSwitch);
// etc.
// 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);
// Other parts of your script...
})();