删除淘宝/天猫默认评论

删除淘宝/天猫包含指定关键词的评论

安裝腳本?
作者推薦腳本

您可能也會喜歡 淘宝广告屏蔽助手

安裝腳本
// ==UserScript==
// @name         删除淘宝/天猫默认评论
// @namespace    http://tampermonkey.net/
// @version      1.2
// @description  删除淘宝/天猫包含指定关键词的评论
// @author       oldip
// @match        https://item.taobao.com/item.htm?*
// @match        https://detail.tmall.com/item.htm?*
// @grant        none
// @license      MIT
// ==/UserScript==

(function () {
    'use strict';

    // 定义需要完全匹配的关键词数组
    const keywords = [
        "评价方未及时做出评价,系统默认好评!",
        "此用户没有填写评价。",
        "系统默认评论",
        "15天内买家未作出评价"
    ];

    // 主函数:搜索并删除匹配的评论
    function removeDefaultFeedback(root = document) {
        const elements = root.querySelectorAll('.content--FpIOzHeP'); // 搜索指定类名的元素
        elements.forEach(element => {
            // 检查内容是否完全匹配任意一个关键词
            if (keywords.includes(element.innerText.trim())) {
                const parentComment = element.closest('.Comment--KkPcz74T'); // 找到父容器
                if (parentComment) {
                    // 检查是否存在多个 content--FpIOzHeP
                    const contentElements = parentComment.querySelectorAll('.content--FpIOzHeP');
                    if (contentElements.length > 1) {
                        // console.log(`跳过追评评论: ${element.innerText}`);
                        return; // 如果存在多个内容,跳过删除
                    }
                    // console.log(`删除默认评论: ${element.innerText}`);
                    parentComment.remove(); // 删除父容器
                }
            }
        });
    }

    // DOM观察器,用于处理动态加载的内容
    const observer = new MutationObserver(mutations => {
        mutations.forEach(mutation => {
            mutation.addedNodes.forEach(node => {
                if (node.nodeType === 1) {
                    removeDefaultFeedback(node); // 检查新增的节点
                }
            });
        });
    });

    // 开启观察整个页面
    observer.observe(document.body, { childList: true, subtree: true });

    // 初次加载时清理页面上的匹配评论
    removeDefaultFeedback();
})();