AdguardTeam / Scriptlets

AdGuard scriptlets library
GNU General Public License v3.0
138 stars 27 forks source link

Remove string in an element's child text with `remove-node-text` scriptlet #397

Open piquark6046 opened 6 months ago

piquark6046 commented 6 months ago

Sometime a filter maintainer needs to remove a string in an element's child text.

<div id="root">
  REMOVE_THIS_STRING
  <div id="login">
  <div id="stats">
</div>

For a real case, a leftover created by AdGuard CoreLibs-based program is not removed by the remove-node-text scriptlet.

https://zdnet.co.kr/view/?no=20231026135022

Screenshot ![Screenshot from 2024-01-02 23-48-47](https://github.com/AdguardTeam/Scriptlets/assets/98787049/82244b92-97e3-4ff2-8fb8-30dd539a0550)

Before you test the real case, please add the following filter:

zdnet.co.kr#@$#body > div[id^="A1_"][style*="height:"] ~ #wrap { margin-top: -1.5em !important; }
AdamWr commented 6 months ago

You can use #text as a nodeName in remove-node-text, for example something like:

zdnet.co.kr#%#//scriptlet('remove-node-text', '#text', 'Blocked by AdGuard')

Or do you mean that you would like to have something like selector > #text?

piquark6046 commented 6 months ago

I did not test with #text as a second parameter. To avoid an incorrect blocking, I think that selector > #text is better.

By the way, Is using the #text as a second parameter in remove-node-text scriptlet Adguard scriptlet's own feature?

AdamWr commented 6 months ago

By the way, Is using the #text as a second parameter in remove-node-text scriptlet Adguard scriptlet's own feature?

I don't think so. For text nodes, the nodeName returns #text - https://developer.mozilla.org/en-US/docs/Web/API/Node/nodeName, so it's rather not an own feature.