MTean 苹果壳

MT 鼠标悬停图片展示图片内容,排序当前页面内容(2024-10-03)

질문, 리뷰하거나, 이 스크립트를 신고하세요.
// ==UserScript==
// @name         MTean 苹果壳
// @namespace    http://tampermonkey.net/
// @version      2024-10-03 2.3
// @description  MT 鼠标悬停图片展示图片内容,排序当前页面内容(2024-10-03)
// @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 && e.target.firstChild.getAttribute('d') && 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();
            }
        }
    })


    const originalXHR = window.XMLHttpRequest;
    function newXHR() {
        const xhr = new originalXHR();
        const originalOpen = xhr.open;
        const originalSend = xhr.send;

        // 添加一个变量来存储请求方法
        let requestMethod;

        xhr.open = function() {
            requestMethod = arguments[0].toUpperCase(); // 保存请求方法
            this.url = arguments[1];
            return originalOpen.apply(this, arguments);
        };

        xhr.send = function(data) {
            // 处理请求体数据
            let modifiedData = data;
            if (requestMethod === 'POST' && this.url.indexOf('/api/torrent/search') !== -1) {
                try {
                    // 根据内容类型处理请求体
                    const contentType = this.getRequestHeader('Content-Type');
                    if (contentType && contentType.includes('application/json')) {
                        // JSON 数据
                        let jsonData = JSON.parse(data);
                        // 修改 JSON 数据
                        jsonData = {
                            ...jsonData,
                            // 在这里添加或修改参数
                            pageSize: 200,
                        };
                        modifiedData = JSON.stringify(jsonData);
                    } else if (contentType && contentType.includes('application/x-www-form-urlencoded')) {
                        // 表单数据
                        const formData = new URLSearchParams(data);
                        // 修改表单数据
                        formData.append('modifiedParam', 'newValue');
                        modifiedData = formData.toString();
                    }
                    // 如果需要,还可以处理其他类型的数据,如 FormData
                } catch (error) {
                    console.error('Error modifying request data:', error);
                }
            }

            const originalOnReadyStateChange = xhr.onreadystatechange;
            xhr.onreadystatechange = function() {
                if (this.readyState === 4) {
                    if (this.status === 200) {
                        let response = this.response;
                        let url = this.url;
                        if (url.indexOf('/api/torrent/search') !== -1 && response !== '') {
                            try {
                                const dataParse = JSON.parse(response);
                                if (Array.isArray(dataParse.data.data) && dataParse.data.data.length > 0) {

                                    let now = new Date(); // 当前时间
                                    let previous24Hours = new Date(now.getTime() - 24 * 60 * 60 * 1000); // 当前时间往前推24小时

                                    // 分离过去24小时内和非过去24小时的数据,并为每一项添加 sum 值
                                    let { within24HoursData, otherData } = dataParse.data.data.reduce((acc, item) => {
                                        let sum = 0;
                                        if (item.status) {
                                            sum = parseInt(item.status.leechers, 10) + parseInt(item.status.seeders, 10);
                                        }

                                        // 判断是否在当前时间和过去24小时之间
                                        let createdDate = new Date(item.createdDate);
                                        if (createdDate >= previous24Hours && createdDate <= now) {
                                            acc.within24HoursData.push({ ...item, sum });
                                        } else {
                                            acc.otherData.push({ ...item, sum });
                                        }
                                        return acc;
                                    }, { within24HoursData: [], otherData: [] });

                                    // 过去24小时内的数据按 createdDate 时间升序排序
                                    within24HoursData.sort((a, b) => new Date(b.createdDate) - new Date(a.createdDate));

                                    // 非过去24小时的数据按 sum 值降序排序
                                    otherData.sort((a, b) => b.sum - a.sum);

                                    // 合并 24小时内的数据和其他数据
                                    let tempData = [...within24HoursData, ...otherData];

                                    const modifiedResponse = JSON.stringify({
                                        ...dataParse,
                                        data: {
                                            ...dataParse.data,
                                            data: tempData,
                                        }
                                    });
                                    Object.defineProperty(this, 'response', {
                                        get: function() {
                                            return modifiedResponse;
                                        }
                                    });
                                    Object.defineProperty(this, 'responseText', {
                                        get: function() {
                                            return modifiedResponse;
                                        }
                                    });
                                }
                            } catch (error) {
                                console.error('Error parsing or modifying response:', error);
                            }
                        }
                    }
                    if (originalOnReadyStateChange) {
                        originalOnReadyStateChange.apply(this, arguments);
                    }
                }
            };

            // 使用修改后的数据发送请求
            return originalSend.call(this, modifiedData);
        };

        // 添加一个辅助方法来获取请求头
        xhr.getRequestHeader = function(name) {
            return this.requestHeaders ? this.requestHeaders[name] : null;
        };

        // 重写 setRequestHeader 方法来保存请求头
        const originalSetRequestHeader = xhr.setRequestHeader;
        xhr.requestHeaders = {};
        xhr.setRequestHeader = function(name, value) {
            this.requestHeaders[name] = value;
            return originalSetRequestHeader.apply(this, arguments);
        };

        return xhr;
    }
    window.XMLHttpRequest = newXHR;



    init();
})();