如何编写UBlock过滤规则,隐藏含指定子元素内容的目标列表项?
Hey there! Let's get that uBlock filter working for you. The problem with your initial attempts is that you were trying to target attributes or text directly on the <li> element, but the mp-Listing-priority class and "Topad" text belong to a child <span>—not the list item itself.
The Working Filter Rule
Here's the exact filter you need to hide only those <li> elements containing the specific "Topad" span:
li.mp-Listing--list-item:has(.mp-Listing-priority:contains("Topad"))
If you want to keep it concise (since the class is specific enough), this shorter version also works:
mp-Listing--list-item:has(.mp-Listing-priority:contains("Topad"))
Why Your Original Rules Failed
Let's break down what went wrong with your initial attempts:
##li.mp-Listing--list-item[class="mp-Listing-priority"]: This rule looks for<li>elements that have themp-Listing-priorityclass, but that class is assigned to the child<span>, not the list item itself.##li.mp-Listing--list-item["Topad"]: This syntax is invalid for uBlock filters. You can't target text content on a parent element directly like this—you need to use the:contains()pseudo-class on the specific child element that holds the text.
Optional: More Precise Nesting (For Edge Cases)
If you're worried about accidental matches with other elements on the page, you can lock in the exact nesting structure from your HTML:
li.mp-Listing.mp-Listing--list-item:has(.mp-Listing-content .mp-Listing-group--aside .mp-Listing-group--bottom-block .mp-Listing-priority:contains("Topad"))
This ensures only list items with that exact hierarchy of child elements get hidden.
Just a quick note: Make sure your uBlock Origin is updated to a recent version—has() and contains() support has been stable for a while, but an update ensures you're running the latest filtering capabilities.
内容的提问来源于stack exchange,提问作者user11857424

