Greasy Fork is available in English.

MT Image viewing

MT 鼠标悬停图片展示图片内容

// ==UserScript==
// @name         MT Image viewing
// @namespace    http://tampermonkey.net/
// @version      2024-03-24 1.8
// @description  MT 鼠标悬停图片展示图片内容
// @author       Yo
// @match        http*://xp.m-team.io/*/*
// @match        http*://xp.m-team.io/*
// @match        http*://kp.m-team.cc/*/*
// @match        http*://kp.m-team.cc/*
// @match        http*://zp.m-team.io/*/*
// @match        http*://zp.m-team.io/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=m-team.io
// @grant        none
// @license MIT
// ==/UserScript==

(function() {
    function clearDom() {
        var elements = document.getElementsByClassName('imgdom');
        var elementsArray = Array.from(elements);
        elementsArray.forEach(function (element) {
            element.parentNode.removeChild(element);
        });
    }

    function loadScript() {
        const hoverableImages = document.querySelectorAll('.ant-image');
        hoverableImages.forEach((image) => {
            image.addEventListener('mouseover', (event) => {
                if (event && event.target && event.target.previousElementSibling && event.target.previousElementSibling.src && event.target.previousElementSibling.src !== '') {
                    clearDom();
                    const div = document.createElement('div');
                    div.classList.add('imgdom');
                    let img = document.createElement('img');
                    img.src = event.target.previousElementSibling.src;
                    img.alt = '18x';
                    img.style.cssText = 'width: 70%;object-position: center;object-fit: contain';
                    img.id = 'imgProId';
                    div.style.cssText = 'position: fixed;top: 50%;left: 50%;transform: translate(-50%, -50%);max-width: 100%;';
                    div.appendChild(img);
                    document.body.appendChild(div);
                }
            });
        });
        document.getElementById('app-content').onscroll = () => clearDom();
    }

    function init() {
        if (location.pathname.indexOf('/browse/adult') !== -1) {
            let checkExist = setInterval(() => {
                if (document.querySelectorAll('.ant-image').length > 0) {
                    loadScript();
                    clearInterval(checkExist);
                }
            }, 1000);
        }
    }

    let old = history.pushState
    history.pushState = (...arg) => {
        init();
        return old.call(this, ...arg)
    }

    window.addEventListener('click', (e) => {
        if (e.target) {
            if (e.target.dataset && e.target.dataset.icon && typeof e.target.dataset.icon === 'string' && e.target.dataset.icon === 'search') {
                init();
            } else if (e.target.className !== '' && e.target.className.indexOf && e.target.className.indexOf('ant-input-search-button') !== -1) {
                init();
            } else if (e.target.firstChild && e.target.firstChild.getAttribute && e.target.firstChild.getAttribute('d').indexOf('M909.6 854.5L649.9 594.8C690.2 542.7 712 479 712 412c0-80.2-31.3-155.4-87.9-212') !== -1) {
                init();
            } else if (e.target.getAttribute('d') && e.target.getAttribute('d').indexOf('M909.6 854.5L649.9 594.8C690.2 542.7 712 479 712 412c0-80.2-31.3-155.4-87.9-212') !== -1) {
               init();
            } else if (e.target.id && e.target.id === 'imgProId') {
                clearDom();
            } else if (e.target.getAttribute && e.target.getAttribute('rel') === 'nofollow') {
+              init();
            }
        }
    })

    window.addEventListener('keydown', (e) => {
        if (e.target && e.target.placeholder === '搜索關鍵字') {
             init();
        }
    })

    init();
})();