Skip to content

Commit 9a97415

Browse files
committed
AG-39644 Update scriptlets documentation. #478
Squashed commit of the following: commit 9ecc924 Author: Adam Wróblewski <[email protected]> Date: Fri Feb 14 18:23:58 2025 +0100 Update scriptlets documentation
1 parent aca8013 commit 9a97415

File tree

7 files changed

+35
-6
lines changed

7 files changed

+35
-6
lines changed

src/scriptlets/prevent-canvas.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import { type Source } from './scriptlets';
2020
*
2121
* ### Syntax
2222
*
23-
* ```adblock
23+
* ```text
2424
* example.org#%#//scriptlet('prevent-canvas'[, contextType])
2525
* ```
2626
*

src/scriptlets/prevent-element-src-loading.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import {
3131
* 1. Prevent script source loading
3232
*
3333
* ```adblock
34-
* example.org#%#//scriptlet('prevent-element-src-loading', 'script' ,'adsbygoogle')
34+
* example.org#%#//scriptlet('prevent-element-src-loading', 'script', 'adsbygoogle')
3535
* ```
3636
*
3737
* @added v1.6.2.

src/scriptlets/prevent-refresh.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import {
3535
* 1. Prevent reloading of a document with delay
3636
*
3737
* ```adblock
38-
* example.com#%#//scriptlet('prevent-refresh', 3)
38+
* example.com#%#//scriptlet('prevent-refresh', '3')
3939
* ```
4040
*
4141
* @added v1.6.2.

src/scriptlets/remove-node-text.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import {
2323
*
2424
* ### Syntax
2525
*
26-
* ```adblock
26+
* ```text
2727
* example.org#%#//scriptlet('remove-node-text', nodeName, textMatch[, parentSelector])
2828
* ```
2929
*

src/scriptlets/trusted-replace-fetch-response.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import {
3434
* - `*` to match all text content
3535
* - non-empty string
3636
* - regular expression
37+
* By default only first occurrence is replaced. To replace all occurrences use `g` flag in RegExp - `/pattern/g`.
3738
* - `replacement` — optional, should be set if `pattern` is set. String to replace the response text content
3839
* matched by `pattern`. Empty string to remove content. Defaults to empty string.
3940
* - `propsToMatch` — optional, string of space-separated properties to match; possible props:
@@ -101,6 +102,12 @@ import {
101102
* example.org#%#//scriptlet('trusted-replace-fetch-response', 'foo', 'bar', 'example.com', 'true')
102103
* ```
103104
*
105+
* 1. Replace all "noAds=false" text content with "noAds=true" of all fetch responses for example.com and log original and modified text content <!-- markdownlint-disable-line line-length -->
106+
*
107+
* ```adblock
108+
* example.org#%#//scriptlet('trusted-replace-fetch-response', '/noAds=false/g', 'noAds=true', 'example.com', 'true')
109+
* ```
110+
*
104111
* @added v1.7.3.
105112
*/
106113
/* eslint-enable max-len */

src/scriptlets/trusted-replace-node-text.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import {
3030
* - `textMatch` — required, string or RegExp to match against node's text content.
3131
* If matched, the `pattern` will be replaced by the `replacement`. Case sensitive.
3232
* - `pattern` — required, string or regexp for matching contents of `node.textContent` that should be replaced.
33+
* By default only first occurrence is replaced. To replace all occurrences use `g` flag in RegExp - `/pattern/g`.
3334
* - `replacement` — required, string to replace text content matched by `pattern`.
3435
* - `...extraArgs` — optional, string, if includes 'verbose' will log original and modified text content.
3536
*
@@ -55,7 +56,7 @@ import {
5556
* <span>some text</span>
5657
* ```
5758
*
58-
* 2. Replace node's text content, matching both node name, text and pattern by RegExp:
59+
* 1. Replace node's text content, matching both node name, text and pattern by RegExp:
5960
*
6061
* ```adblock
6162
* example.org#%#//scriptlet('trusted-replace-node-text', '/[a-z]*[0-9]/', '/s\dme/', '/t\dxt/', 'other text')
@@ -73,7 +74,21 @@ import {
7374
* <span>some text</span>
7475
* ```
7576
*
76-
* 3. Replace node's text content and log original and modified text content:
77+
* 1. Replace all occurrences in node's text content, matching both node name and text:
78+
*
79+
* ```adblock
80+
* example.org#%#//scriptlet('trusted-replace-node-text', 'p', 'bar', '/a/g', 'x')
81+
* ```
82+
*
83+
* ```html
84+
* <!-- before -->
85+
* <p>foa bar baz</p> // this node is going to be matched by both node name and text
86+
*
87+
* <!-- after -->
88+
* <p>fox bxr bxz</p> // text content has changed
89+
* ```
90+
*
91+
* 1. Replace node's text content and log original and modified text content:
7792
*
7893
* ```adblock
7994
* example.org#%#//scriptlet('trusted-replace-node-text', 'div', 'some', 'text', 'other text', 'verbose')

src/scriptlets/trusted-replace-xhr-response.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import {
3232
* - `*` to match all text content
3333
* - non-empty string
3434
* - regular expression
35+
* By default only first occurrence is replaced. To replace all occurrences use `g` flag in RegExp - `/pattern/g`.
3536
* - `replacement` — optional, should be set if `pattern` is set. String to replace matched content with.
3637
* Empty string to remove content.
3738
* - `propsToMatch` — optional, string of space-separated properties to match for extra condition; possible props:
@@ -94,6 +95,12 @@ import {
9495
* example.org#%#//scriptlet('trusted-replace-xhr-response', 'foo', 'bar', 'example.com', 'true')
9596
* ```
9697
*
98+
* 1. Replace all "noAds=false" text content with "noAds=true" of all XMLHttpRequests for example.com and log original and modified text content <!-- markdownlint-disable-line line-length -->
99+
*
100+
* ```adblock
101+
* example.org#%#//scriptlet('trusted-replace-xhr-response', '/noAds=false/g', 'noAds=true', 'example.com', 'true')
102+
* ```
103+
*
97104
* @added v1.7.3.
98105
*/
99106
/* eslint-enable max-len */

0 commit comments

Comments
 (0)