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

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

Closed
piquark6046 opened this issue Jan 9, 2024 · 3 comments

Comments

@piquark6046
Copy link
Member

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; }
@AdamWr
Copy link
Member

AdamWr commented Jan 9, 2024

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
Copy link
Member Author

piquark6046 commented Jan 9, 2024

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
Copy link
Member

AdamWr commented Jan 9, 2024

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.

@adguard-bot adguard-bot changed the title Remove string in an element's child text with remove-node-text scriptlet Remove string in an element's child text with 'remove-node-text' scriptlet Oct 7, 2024
@slavaleleka slavaleleka added the question Further information is requested label Oct 7, 2024
@adguard-bot adguard-bot assigned jellizaveta and unassigned maximtop Oct 7, 2024
adguard pushed a commit that referenced this issue Oct 11, 2024
@slavaleleka slavaleleka added enhancement Improvement of existent feature and removed question Further information is requested labels Oct 11, 2024
@adguard-bot adguard-bot added the question Further information is requested label Oct 11, 2024
@adguard-bot adguard-bot changed the title Remove string in an element's child text with 'remove-node-text' scriptlet Improve 'remove-node-text' — add an ability to remove text node of specified element Oct 11, 2024
adguard pushed a commit that referenced this issue Oct 15, 2024
…node-text' scriptlet. #397

Squashed commit of the following:

commit 105e53e
Author: jellizaveta <[email protected]>
Date:   Mon Oct 14 17:26:06 2024 +0300

    fix check for text nodes

commit 5047355
Merge: 7169865 dac16b7
Author: jellizaveta <[email protected]>
Date:   Mon Oct 14 13:09:50 2024 +0300

    merge, resolve conflicts

commit 7169865
Author: jellizaveta <[email protected]>
Date:   Fri Oct 11 21:27:06 2024 +0300

    change tests, remove useless and add new

commit bb597a6
Author: jellizaveta <[email protected]>
Date:   Fri Oct 11 18:17:33 2024 +0300

    Revert "add test"

    This reverts commit cbc0ba9.

commit ad96cf2
Author: jellizaveta <[email protected]>
Date:   Fri Oct 11 18:16:00 2024 +0300

    added test

commit 75c6b33
Merge: b6c090f 2d842cd
Author: jellizaveta <[email protected]>
Date:   Fri Oct 11 18:05:32 2024 +0300

    Merge branch 'fix/AG-29354' of ssh://bit.int.agrd.dev:7999/adguard-filters/scriptlets into fix/AG-29354

commit b6c090f
Author: jellizaveta <[email protected]>
Date:   Fri Oct 11 18:01:25 2024 +0300

    update jsDoc

commit d2784e1
Author: jellizaveta <[email protected]>
Date:   Fri Oct 11 17:57:23 2024 +0300

    fix the processing of added elements

commit cbc0ba9
Author: jellizaveta <[email protected]>
Date:   Fri Oct 11 16:35:12 2024 +0300

    add test

commit 2d842cd
Author: Slava Leleka <[email protected]>
Date:   Fri Oct 11 16:16:22 2024 +0300

    src/helpers/node-text-utils.ts edited online with Bitbucket

commit df4862f
Author: jellizaveta <[email protected]>
Date:   Wed Oct 9 14:49:23 2024 +0300

    fix wiki

commit 4234194
Author: jellizaveta <[email protected]>
Date:   Fri Oct 11 14:38:11 2024 +0300

    rename var

commit 58de460
Merge: cafc855 a06b6e3
Author: jellizaveta <[email protected]>
Date:   Fri Oct 11 14:33:30 2024 +0300

    resolve conflicts

commit cafc855
Author: jellizaveta <[email protected]>
Date:   Fri Oct 11 14:13:00 2024 +0300

    update jsDoc, comments, var names

commit a06b6e3
Author: Slava Leleka <[email protected]>
Date:   Fri Oct 11 14:11:23 2024 +0300

    tests/scriptlets/remove-node-text.test.js edited online with Bitbucket

commit aa5de55
Author: Slava Leleka <[email protected]>
Date:   Fri Oct 11 14:11:09 2024 +0300

    src/helpers/node-text-utils.ts edited online with Bitbucket

commit bdd2c5e
Merge: 9fb1125 0ca98f3
Author: jellizaveta <[email protected]>
Date:   Fri Oct 11 13:51:02 2024 +0300

    Merge branch 'master' into fix/AG-29354

commit 9fb1125
Author: jellizaveta <[email protected]>
Date:   Fri Oct 11 13:29:23 2024 +0300

    AG-29354 Add 'parentSelector' option to search for nodes for 'remove-node-text' scriptlet. #397

commit c34a4aa
Author: jellizaveta <[email protected]>
Date:   Fri Oct 11 13:15:11 2024 +0300

    refactor function

commit 559b8d0
Author: jellizaveta <[email protected]>
Date:   Thu Oct 10 19:14:33 2024 +0300

    add a selector search for tags
@slavaleleka slavaleleka removed the question Further information is requested label Nov 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants