淘宝隐藏无效评论

隐藏无效评论

// ==UserScript==
// @name         淘宝隐藏无效评论
// @namespace    http://tampermonkey.net/
// @version      1.2
// @description  隐藏无效评论
// @match        https://*.taobao.com/*
// @match        https://*.tmall.com/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // 记录滑动次数
    let scrollCount = 0;
    const maxScrollCount = 300; // 最大滑动次数

    // 查找页面中的所有滑块元素
    function findScrollableElements() {
        return document.querySelectorAll('div[style*="overflow-y: scroll"], div[style*="overflow: scroll"]');
    }

    // 滚动页面
    function scrollPage() {
        if (scrollCount >= maxScrollCount) {
            return; // 如果滑动次数超过最大限制,则不再滚动
        }

        const scrollableElements = findScrollableElements();
        if (scrollableElements.length > 0) {
            const targetElement = scrollableElements[0]; // 选取第一个找到的可滚动元素
            targetElement.scrollTop += 70; // 每次滚动70px
            scrollCount++; // 滚动次数加1
        }
    }

    // 删除无效评论并触发滚动
    function removeInvalidComments() {
        const comments = document.querySelectorAll('.Comment--KkPcz74T');
        let deletedCount = 0; // 记录删除的评论数量

        comments.forEach((comment) => {
            const content = comment.querySelector('.content--FpIOzHeP');

            if (content && (content.textContent.trim() === '此用户没有填写评价。' ||
                            content.textContent.trim() === '评价方未及时做出评价,系统默认好评!')) {
                // 删除评论
                setTimeout(() => {
                    comment.remove();
                    deletedCount++;

                    // 滚动页面(确保每次删除后只滚动一次)
                    if (deletedCount === 1) {
                        scrollPage();
                    }
                }, deletedCount * 500); // 每个删除动作间隔0.5秒
            }
        });
    }

    // 在页面加载完成后运行脚本,并监听动态加载的评论
    const observer = new MutationObserver(() => {
        removeInvalidComments();
    });
    observer.observe(document.body, { childList: true, subtree: true });

    // 初始运行一次
    removeInvalidComments();
})();