拼多多网页版,隐藏1天内的追加评价

根据条件隐藏带有特定属性的元素的上级元素

目前為 2023-06-27 提交的版本,檢視 最新版本

// ==UserScript==
// @name         拼多多网页版,隐藏1天内的追加评价
// @namespace    your-namespace
// @version      1.1
// @description  根据条件隐藏带有特定属性的元素的上级元素
// @author       weakestan
// @match        *://mobile.pinduoduo.com/*
// @grant        none
// @license      GPLv3
// ==/UserScript==



(function() {
    'use strict';


    // 定义目标 div 的 class 和要匹配的子元素的 class 和内容条件
    var targetDivClass = 'pdd-list-container';
//    var targetElementClass = '_1KM3e9rm';
    // 自定义 "用户1天"(正则表达式定义)
    var targetValueRegex = /用户1天/;

    // 监听页面的变化,当目标 div 下的子元素发生变化时进行处理
    var observer = new MutationObserver(function(mutationsList) {
        for (var mutation of mutationsList) {
            if (mutation.type === 'childList' && mutation.target.classList.contains(targetDivClass)) {
                handleChildListChange(mutation.target);
            }
        }
    });

    // 开始监听根节点的子节点变化
    observer.observe(document.documentElement, { childList: true, subtree: true });

    // 处理目标 div 下子元素的变化
    function handleChildListChange(targetDiv) {
        var childElements = targetDiv.querySelectorAll('*');

        childElements.forEach(function(element) {
            var content = element.textContent.trim();
            if (targetValueRegex.test(content)) {
                hideParentDiv(element);
            }
        });
    }

    // 隐藏上一级 div
    function hideParentDiv(element) {
        var parentDiv = element.closest('div');
        if (parentDiv) {
            parentDiv.style.display = 'none';
        }
    }
})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址