Skip to content

Commit

Permalink
AG-39644 Update scriptlets documentation. #478
Browse files Browse the repository at this point in the history
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
  • Loading branch information
AdamWr committed Feb 17, 2025
1 parent aca8013 commit 9a97415
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/scriptlets/prevent-canvas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { type Source } from './scriptlets';
*
* ### Syntax
*
* ```adblock
* ```text
* example.org#%#//scriptlet('prevent-canvas'[, contextType])
* ```
*
Expand Down
2 changes: 1 addition & 1 deletion src/scriptlets/prevent-element-src-loading.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import {
* 1. Prevent script source loading
*
* ```adblock
* example.org#%#//scriptlet('prevent-element-src-loading', 'script' ,'adsbygoogle')
* example.org#%#//scriptlet('prevent-element-src-loading', 'script', 'adsbygoogle')
* ```
*
* @added v1.6.2.
Expand Down
2 changes: 1 addition & 1 deletion src/scriptlets/prevent-refresh.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import {
* 1. Prevent reloading of a document with delay
*
* ```adblock
* example.com#%#//scriptlet('prevent-refresh', 3)
* example.com#%#//scriptlet('prevent-refresh', '3')
* ```
*
* @added v1.6.2.
Expand Down
2 changes: 1 addition & 1 deletion src/scriptlets/remove-node-text.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
*
* ### Syntax
*
* ```adblock
* ```text
* example.org#%#//scriptlet('remove-node-text', nodeName, textMatch[, parentSelector])
* ```
*
Expand Down
7 changes: 7 additions & 0 deletions src/scriptlets/trusted-replace-fetch-response.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import {
* - `*` to match all text content
* - non-empty string
* - regular expression
* By default only first occurrence is replaced. To replace all occurrences use `g` flag in RegExp - `/pattern/g`.
* - `replacement` — optional, should be set if `pattern` is set. String to replace the response text content
* matched by `pattern`. Empty string to remove content. Defaults to empty string.
* - `propsToMatch` — optional, string of space-separated properties to match; possible props:
Expand Down Expand Up @@ -101,6 +102,12 @@ import {
* example.org#%#//scriptlet('trusted-replace-fetch-response', 'foo', 'bar', 'example.com', 'true')
* ```
*
* 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 -->
*
* ```adblock
* example.org#%#//scriptlet('trusted-replace-fetch-response', '/noAds=false/g', 'noAds=true', 'example.com', 'true')
* ```
*
* @added v1.7.3.
*/
/* eslint-enable max-len */
Expand Down
19 changes: 17 additions & 2 deletions src/scriptlets/trusted-replace-node-text.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {
* - `textMatch` — required, string or RegExp to match against node's text content.
* If matched, the `pattern` will be replaced by the `replacement`. Case sensitive.
* - `pattern` — required, string or regexp for matching contents of `node.textContent` that should be replaced.
* By default only first occurrence is replaced. To replace all occurrences use `g` flag in RegExp - `/pattern/g`.
* - `replacement` — required, string to replace text content matched by `pattern`.
* - `...extraArgs` — optional, string, if includes 'verbose' will log original and modified text content.
*
Expand All @@ -55,7 +56,7 @@ import {
* <span>some text</span>
* ```
*
* 2. Replace node's text content, matching both node name, text and pattern by RegExp:
* 1. Replace node's text content, matching both node name, text and pattern by RegExp:
*
* ```adblock
* example.org#%#//scriptlet('trusted-replace-node-text', '/[a-z]*[0-9]/', '/s\dme/', '/t\dxt/', 'other text')
Expand All @@ -73,7 +74,21 @@ import {
* <span>some text</span>
* ```
*
* 3. Replace node's text content and log original and modified text content:
* 1. Replace all occurrences in node's text content, matching both node name and text:
*
* ```adblock
* example.org#%#//scriptlet('trusted-replace-node-text', 'p', 'bar', '/a/g', 'x')
* ```
*
* ```html
* <!-- before -->
* <p>foa bar baz</p> // this node is going to be matched by both node name and text
*
* <!-- after -->
* <p>fox bxr bxz</p> // text content has changed
* ```
*
* 1. Replace node's text content and log original and modified text content:
*
* ```adblock
* example.org#%#//scriptlet('trusted-replace-node-text', 'div', 'some', 'text', 'other text', 'verbose')
Expand Down
7 changes: 7 additions & 0 deletions src/scriptlets/trusted-replace-xhr-response.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import {
* - `*` to match all text content
* - non-empty string
* - regular expression
* By default only first occurrence is replaced. To replace all occurrences use `g` flag in RegExp - `/pattern/g`.
* - `replacement` — optional, should be set if `pattern` is set. String to replace matched content with.
* Empty string to remove content.
* - `propsToMatch` — optional, string of space-separated properties to match for extra condition; possible props:
Expand Down Expand Up @@ -94,6 +95,12 @@ import {
* example.org#%#//scriptlet('trusted-replace-xhr-response', 'foo', 'bar', 'example.com', 'true')
* ```
*
* 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 -->
*
* ```adblock
* example.org#%#//scriptlet('trusted-replace-xhr-response', '/noAds=false/g', 'noAds=true', 'example.com', 'true')
* ```
*
* @added v1.7.3.
*/
/* eslint-enable max-len */
Expand Down

0 comments on commit 9a97415

Please sign in to comment.