我的插件
当前为
// ==UserScript==
// @name 图寻我的插件
// @namespace http://tampermonkey.net/
// @version 2.64
// @description 我的插件
// @author yukejun
// @match https://tuxun.fun/*
// @run-at document-end
// @grant none
// ==/UserScript==
(function() {
'use strict';
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;
}
let imgElement;
function bindClickEvent() {
if (!imgElement) {
imgElement = document.querySelector('img[src="https://i.chao-fan.com/biz/1662830707508_d7e5c8ce884a4fb692096396a5405f5b_0.png"]');
if(imgElement) {
imgElement.addEventListener("click", function() {
let modifiedURL = getModifiedURL(window.location.href);
window.open(modifiedURL, '_blank');
});
}
}
}
let roundDiv, roundObserver;
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 });
}
}
}
function handleKeyDown(e) {
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();
}
});
}
}
document.addEventListener('keydown', handleKeyDown);
const mainObserver = new MutationObserver(function(mutations) {
let shouldBindClick = false;
let shouldMonitorRound = false;
mutations.forEach(function(mutation) {
if (mutation.addedNodes) {
if (!imgElement) shouldBindClick = true;
if (!roundDiv) shouldMonitorRound = true;
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';
}
}
});
}
});
if (shouldBindClick) bindClickEvent();
if (shouldMonitorRound) monitorRoundChange();
});
mainObserver.observe(document.body, {
childList: true,
subtree: true
});
// ... 拖拽功能代码 ...
// 注意: 在拖拽开始时添加 'mousemove' 和 'mouseup' 事件监听器,并在拖拽结束时移除它们。
// 拖拽功能
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);
}
});
}
}
});
dragObserver.observe(document.body, {
childList: true,
subtree: true
});
})();