进入游戏后1秒自动隐藏全景图像,按空格键刷新页面并翻页
当前为
// ==UserScript==
// @name 图寻眨眼模式
// @namespace http://tampermonkey.net/
// @version 1.44
// @description 进入游戏后1秒自动隐藏全景图像,按空格键刷新页面并翻页
// @author 宇宙百科君
// @match https://tuxun.fun/*
// @run-at document-start
// @grant none
// ==/UserScript==
(function() {
'use strict';
// 初始化刷新状态
let refreshEnabled = false;
// 从localStorage初始化眨眼模式状态
var blinkMode = localStorage.getItem('blinkMode') !== '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秒隐藏全景图
}, 300);
}, 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)) {
// 创建眨眼模式切换按钮
var blinkSwitch = document.createElement('button');
blinkSwitch.innerText = "眨眼" + (blinkMode ? "开启" : "关闭");
blinkSwitch.style.position = "fixed";
blinkSwitch.style.top = "5px";
blinkSwitch.style.left = "50%";
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 ? "开启" : "关闭");
// 将状态保存到localStorage
localStorage.setItem('blinkMode', blinkMode);
};
document.body.appendChild(blinkSwitch);
}
// 第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);
// 监听按键事件
document.addEventListener('keydown', handleKeyPressForRefresh);
document.addEventListener('keydown', handleKeyPressForAnotherSelector);
})();