Skip to content

Add a way to select elements by the amount of classes they have #1211

Description

@DandelionSprout

Prerequisites

  • I verified that this is not a filter issue
  • This is not a support issue or a question
  • I performed a cursory search of the issue tracker to avoid opening a duplicate issue
    • Your issue may already be reported.
  • I tried to reproduce the issue when...
    • uBlock Origin is the only extension
    • uBlock Origin with default lists/settings
    • using a new, unmodified browser profile
  • I am running the latest version of uBlock Origin (v1.29.0)
  • I checked the documentation to understand that the issue I report is not a normal behavior

Description

A steadily higher amount of websites are using randomly generated class names for elements, and a slight majority of such websites also keeps changing those generated class names every month-ish. However, I think I've discovered one thing that can help select specific such elements at least a bit more easily:

On a few of the websites in question, with Twitter and Pixiv as the biggest examples that I personally know of, the amount of classes the elements have are different, and they seem to be fairly consistent.

My wish is that in the setting of the screenshot below, <div class="sc-1nr368f-4 ez9z4y-0 cIk0oy"> would've been selectable with ##div:classes(3), or whatever else you'd want to name it (e.g. :class-number). Likewise it would be selectable with ##div:classes(2) > div:classes(3), and perhaps even ##div:classes(3):has(:scope > section:classes(2)).

image

Currently, it seems that ##div[class*=" "] can cover everything with 2 or more classes, but I can't find any ways to make it more narrowed-down than that.

An alternative could be to add wildcard support for id and class (e.g. ###*.*.*), similar to what I am currently only able to do with singular elements (e.g. ##*)

A specific URL where the issue occurs

https://www.pixiv.net/en/tags/princess_dress/illustrations (If you're not logged in.)
https://www.pixiv.net/en/tags/princess_dress/illustrations?mode=safe (If you're logged in.)

Steps to Reproduce

  1. Visit whichever website, although preferably one with many different class-containing elements.
  2. Open the element picker.
  3. Attempt to add ##.*, ##div:classes(1) and/or ##div:class-number(1), and see that none of them are accepted.
  4. Attempt to add ##div[class*=" "][class*=" "], and see that the amount of successive [class*=" "] has no narrowing-down effect on what is being selected.

Expected behavior:

It becomes possible to select and hide elements based on the amount of classes they have.

Actual behavior:

Currently this can only be done for elements with 0 classes (##div:not([class])) and 1 class (##div[class]:not([class*=" "]). There are currently no known way to specifically select elements by the exact amount of classes they have, if that number is 2 or higher.

Your environment

  • uBlock Origin version: 1.29.0
  • Browser Name and version: Vivaldi 3.2.1967.41 x64
  • Operating System and version: Windows 10 May 2020 Update

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions