Scriptlets icon indicating copy to clipboard operation
Scriptlets copied to clipboard

Improve 'remove-node-text' — add an ability to remove text node of specified element

Open piquark6046 opened this issue 1 year ago • 3 comments

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

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; }

piquark6046 avatar Jan 09 '24 12:01 piquark6046

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?

AdamWr avatar Jan 09 '24 12:01 AdamWr

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?

piquark6046 avatar Jan 09 '24 12:01 piquark6046

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.

AdamWr avatar Jan 09 '24 12:01 AdamWr