Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for plaintext selectors? #1654

Closed
8 tasks done
peace2000 opened this issue Jul 8, 2021 · 15 comments
Closed
8 tasks done

Add support for plaintext selectors? #1654

peace2000 opened this issue Jul 8, 2021 · 15 comments
Labels
declined declined enhancement New feature or request

Comments

@peace2000
Copy link
Member

peace2000 commented Jul 8, 2021

Prerequisites

I tried to reproduce the issue when...

  • uBO is the only extension
  • uBO with default lists/settings
  • using a new, unmodified browser profile

Description

I was trying to create a filter to pick a specific plaintext element, without picking it's parent p element. The parent element contained other plaintext elements as well which is why I didn't want to pick it - I only want to pick a specific plaintext, not it's siblings. Firefox's element inspector tool can pick it individually (I can even remove it):

kuva

The text I want to pick in that picture is Windows 11:n tapauksessa.

Can you add support for Ubo to pick plaintext elements like that (and make filters concerning them), without the need to pick it's parent element, thus picking also all it's siblings at the same time?

Related conversation: https://www.reddit.com/r/uBlockOrigin/comments/og9ayc/selector_for_plaintext_elements/

A specific URL where the issue occurs

https://www.mikrobitti.fi/uutiset/windows-11-paivitys-ilmainen-vain-rajoitetun-ajan-nain-kauan-tarjous-on-vahintaan-voimassa/dc7afa1e-23ce-4a99-9732-842bf4b6353d

Steps to Reproduce

Try to select any plaintext chunk via Ubo on any website (but not choosing it's parent element).

Expected behavior

Ubo would be able to select a plaintext element individually.

Actual behavior

Ubo cannot choose a plaintext element, no matter how I tried to make a filter via various #text and has-text() combinations.

uBlock Origin version

1.36.2

Browser name and version

Mozilla Firefox 89.0.2

Operating System and version

Windows 10

@gwarser gwarser added the enhancement New feature or request label Jul 8, 2021
@gwarser
Copy link

gwarser commented Jul 8, 2021

This was discussed recently in team https://github.com/orgs/uBlockOrigin/teams/ublock-issues-volunteers/discussions/282

What gorhill said:

All operators expect element nodes as input, including remove(). Allowing text nodes in the output set would mean that each operator would have to check whether the input node is an element.

If supporting text nodes is really something that comes up more than in just this case, than I could modify :xpath() to wrap text nodes when they occur into span elements in the resultset.


Modifying the DOM is a bad idea after all, so only solution I see is to make all operators and code using operators be mindful that a text node could be present as input -- not a trivial change.


An easier solution would be to have a new operator which purpose is to remove text node which are immediate child of the subject node:

###instructions:remove-text(Advertisement)

a new operator which purpose is to remove text node which are immediate child of the subject node

It's not a trivial change after all, so at this point not sure it's worth the amount of work for two cases which are not really that big of a deal.

@gorhill
Copy link
Member

gorhill commented Jul 8, 2021

What I am reading in the opening comment does not convince me it's worth the amount of work and risks to stability.

Also I would like the case to be better made, "I only want" sounds a lot like a personal itch (I cant load the site at the moment, and also I dont read Finnish)

@peace2000
Copy link
Member Author

An ability to remove plaintext elements would probably be the most urgent as it comes to plain adblocking.

The main reason for me personally to open this was that I would be able to make :style rules for plaintext elements in websites. I use Ubo a lot for website styling purposes as well to make websites less annoying and more comfortable, in addition to adblocking.
(Though sometimes :style rules are needed as an adblocking supplement as well - which is why I think that styling support for plaintext nodes would be reasonable to add as well, if removing of plaintext elements were to be implemented).

Yeah that Reddit thread is mine, peace2000 was already taken in Reddit so had to use another nick.

@uBlock-user
Copy link
Contributor

Talks haven't progressed at CSSWG issue -- w3c/csswg-drafts#2208

@gorhill
Copy link
Member

gorhill commented Jul 9, 2021

Source:

I was looking a way to use Ubo to restyle some plaintext elements

I visited the site, and from Google Translate, the text you want to target is part of the article, i.e. this has nothing with uBO's primary purpose -- and anyway you can't restyle text nodes. There are cases of text nodes which might benefit from being removed, but this is not what the issue here is about.

Declined.

Also, any issue presented as "I want" vs. stating the exact problem to solve is unwelcome when the issue has nothign to do with uBO's primary purpose, I do not want to be used to scratch personal itches, you will have to ask or hire someone else for this.

@gorhill gorhill closed this as completed Jul 9, 2021
@gorhill gorhill added the declined declined label Jul 9, 2021
@Yuki2718
Copy link

Yuki2718 commented Sep 9, 2021

AdguardTeam/AdguardFilters#94170
"スポンサーリンク" (Sponsored link) leftover can only be hidden by such a selector, but I know a similar case was mentioned in Reddit and don't know if it justify the selector.

@gorhill
Copy link
Member

gorhill commented Sep 9, 2021

That would really be not trivial to add such capability, so this would have to become a much more widespread serious issue before I would want to spend time on this.

@Yuki2718
Copy link

Yuki2718 commented Sep 9, 2021

maybe possible to achieve what you want:

No, see the DOM tree. The texts don't belong to ANY tag that can be hidden, so xpath doesn't help here.

@peace2000
Copy link
Member Author

peace2000 commented Sep 9, 2021

@Yuki2718 I agree that "remove-text" would be useful for this, though for this particular case...

Why not just sweep them under the rug? :D

resizer.myct.jp##a[href^="https://resizer.myct.jp/"] ~ br:nth-of-type(3)
resizer.myct.jp##img[src="images/ware-stitle01-e.gif"]:style(margin-top: -1em !important)

resizer.myct.jp##img[src="images/ware-stitle02-e.gif"] ~ br:nth-of-type(even)
resizer.myct.jp##img[src="images/ware-stitle03-e.gif"]:style(margin-top: -1em !important)

For the last sponsored text I couldn't find a good css style filter as I'm not that advanced with css.

My filters work for the English side https://resizer.myct.jp/index-e.php for Japanese and Chinese side, other filters are needed.

Someone better can continue... :)

@Yuki2718
Copy link

Yuki2718 commented Sep 9, 2021

@peace2000 Yeah, css trick can be used, but I'm not much willing to just for them. I never know when they change site structure and the filters starts mal-behavior - it'll sound like a general concern, but the risk is much higher when :nth-of-type and :style() are involvned.

@peace2000
Copy link
Member Author

True, though that particular site is very simple looking so I think that risk is lower.

@Yuki2718
Copy link

Yuki2718 commented Sep 9, 2021

In any case I'll leave it to AG guys :D

@Yuki2718
Copy link

https://gitlab.com/eyeo/adblockplus/abc/adblockpluscore/-/issues/240

It seems this idea makes things easier to implement @gorhill

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
declined declined enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

6 participants
@gorhill @gwarser @peace2000 @uBlock-user @Yuki2718 and others