Greasy Fork

Greasy Fork is available in English.

图寻我的插件

我的插件

当前为 2023-10-24 提交的版本,查看 最新版本

// ==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;
    }

    // 使用事件委托方法
    document.addEventListener("click", function(event) {
        const imgElement = event.target.closest('img[src="https://i.chao-fan.com/biz/1662830707508_d7e5c8ce884a4fb692096396a5405f5b_0.png"]');
        if (imgElement) {
            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 });
            }
        }
    }
    // Rest of the code for dragging and other functionalities...

    // 拖拽功能
    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
    });

})();