我的插件
当前为
// ==UserScript==
// @name 图寻我的插件
// @namespace http://tampermonkey.net/
// @version 2.70
// @description 我的插件
// @author yukejun
// @match https://tuxun.fun/*
// @run-at document-end
// @grant none
// ==/UserScript==
(function() {
'use strict';
// 功能1:点击坐标可查看位置
// 判断URL是否匹配
const urlPattern = /^https:\/\/tuxun\.fun\/replay\?gameId=[\w-]+$/;
if (urlPattern.test(window.location.href)) {
// 如果URL匹配,直接退出脚本
return;
}
let currentRound = 1;
function getModifiedURL(originalURL) {
let match = originalURL.match(/(gameId|infinityId|challengeId|streakId)=([\w-]+)/);
if (match && match[2]) {
return `https://tuxun.fun/replay_pano?gameId=${match[2]}&round=${currentRound}`;
}
return originalURL;
}
document.addEventListener("click", function(event) {
const imgElement = event.target.closest('img');
if (imgElement && /https:\/\/i\.chao-fan\.com\/biz\/\d+_[\w-]+_0\.png/.test(imgElement.src)) {
let modifiedURL = getModifiedURL(window.location.href);
window.open(modifiedURL, '_blank');
}
});
let roundDiv, roundObserver;
function delayedMonitorRoundChange() {
setTimeout(monitorRoundChange, 2000);
}
function monitorRoundChange() {
if (!roundDiv) {
roundDiv = document.querySelector("div[data-v-26f5391c]");
if(roundDiv) {
roundObserver = new MutationObserver(function(mutations) {
mutations.forEach(function(mutation) {
if(mutation.type === "childList") {
let match = roundDiv.textContent.match(/第 (\d+) 轮/);
if(match && match[1]) {
currentRound = parseInt(match[1], 10);
}
}
});
});
roundObserver.observe(roundDiv, { childList: true, subtree: true });
}
}
}
// 调用 delayedMonitorRoundChange 来在2秒后执行 monitorRoundChange
delayedMonitorRoundChange();
// Rest of the code for dragging and other functionalities...
// 功能4:拖拽指南针功能
function setInitialPositionFromStorage(element, selector) {
const storedPos = localStorage.getItem(selector);
if (storedPos) {
const { left, top } = JSON.parse(storedPos);
element.style.left = left;
element.style.top = top;
}
}
function makeDraggable(element, selector) {
let isDragging = false;
let startX, startY, initialX, initialY;
if (!element) return;
if (window.getComputedStyle(element).position === 'static') {
element.style.position = 'relative';
}
setInitialPositionFromStorage(element, selector);
element.addEventListener('mousedown', function(event) {
isDragging = true;
startX = event.clientX;
startY = event.clientY;
initialX = parseInt(element.style.left || 0);
initialY = parseInt(element.style.top || 0);
const map = window.map || document.querySelector('#map').__gm;
if (map && map.setOptions) {
map.setOptions({draggable: false});
}
event.stopPropagation();
event.preventDefault();
});
document.addEventListener('mousemove', function(event) {
if (!isDragging) return;
let dx = event.clientX - startX;
let dy = event.clientY - startY;
element.style.left = (initialX + dx) + 'px';
element.style.top = (initialY + dy) + 'px';
event.stopPropagation();
event.preventDefault();
});
document.addEventListener('mouseup', function(event) {
if (isDragging) {
const map = window.map || document.querySelector('#map').__gm;
if (map && map.setOptions) {
map.setOptions({draggable: true});
}
localStorage.setItem(selector, JSON.stringify({
left: element.style.left,
top: element.style.top
}));
}
isDragging = false;
event.stopPropagation();
});
}
document.addEventListener('dblclick', function(event) {
if (event.target.closest('#tuxun')) {
event.preventDefault();
event.stopPropagation();
}
}, true);
const selectors = [
'#viewer > div > div:nth-child(14) > div.gmnoprint.gm-bundled-control.gm-bundled-control-on-bottom > div'
];
const dragObserver = new MutationObserver(mutations => {
for (const mutation of mutations) {
if (mutation.addedNodes.length) {
selectors.forEach(selector => {
const element = document.querySelector(selector);
if (element) {
makeDraggable(element, selector);
}
});
}
}
});
// 功能3:按空格键触发另一个选择器
document.addEventListener('keydown', function(e) {
// 输出到控制台,确保事件被触发
console.log('Key pressed:', e.keyCode);
if (e.keyCode === 32) {
const buttons = document.querySelectorAll('button');
buttons.forEach(function(button) {
if (button.textContent.includes('开始(经典5轮)') || button.textContent.includes('再来一局') || button.textContent.includes('保留')) {
button.click();
}
});
}
});
// 功能4:隐藏包含 "比赛已经开始或者这一轮游戏还未结束" 文本的提示
const observer = new MutationObserver(function(mutations) {
mutations.forEach(function(mutation) {
if (mutation.addedNodes) {
mutation.addedNodes.forEach(function(node) {
if (node.nodeType === Node.ELEMENT_NODE && node.matches('.van-toast.van-toast--middle.van-toast--text')) {
const innerDiv = node.querySelector('.van-toast__text');
if (innerDiv && innerDiv.textContent.trim() === "比赛已经开始或者这一轮游戏还未结束") {
node.style.display = 'none';
}
}
});
}
});
});
dragObserver.observe(document.body, {
childList: true,
subtree: true
});
})();