From 9a974151a0bee433bd863b4da6fae2bc22831307 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Wr=C3=B3blewski?= Date: Mon, 17 Feb 2025 14:02:22 +0300 Subject: [PATCH] AG-39644 Update scriptlets documentation. #478 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Squashed commit of the following: commit 9ecc9245fb66d82e90d23419357f5484416f2f3a Author: Adam Wróblewski Date: Fri Feb 14 18:23:58 2025 +0100 Update scriptlets documentation --- src/scriptlets/prevent-canvas.ts | 2 +- src/scriptlets/prevent-element-src-loading.js | 2 +- src/scriptlets/prevent-refresh.js | 2 +- src/scriptlets/remove-node-text.js | 2 +- .../trusted-replace-fetch-response.js | 7 +++++++ src/scriptlets/trusted-replace-node-text.js | 19 +++++++++++++++++-- .../trusted-replace-xhr-response.js | 7 +++++++ 7 files changed, 35 insertions(+), 6 deletions(-) diff --git a/src/scriptlets/prevent-canvas.ts b/src/scriptlets/prevent-canvas.ts index 75dff7d6..ce935be7 100644 --- a/src/scriptlets/prevent-canvas.ts +++ b/src/scriptlets/prevent-canvas.ts @@ -20,7 +20,7 @@ import { type Source } from './scriptlets'; * * ### Syntax * - * ```adblock + * ```text * example.org#%#//scriptlet('prevent-canvas'[, contextType]) * ``` * diff --git a/src/scriptlets/prevent-element-src-loading.js b/src/scriptlets/prevent-element-src-loading.js index b815272d..aa22d35e 100644 --- a/src/scriptlets/prevent-element-src-loading.js +++ b/src/scriptlets/prevent-element-src-loading.js @@ -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. diff --git a/src/scriptlets/prevent-refresh.js b/src/scriptlets/prevent-refresh.js index fe64a2c9..febd4f69 100644 --- a/src/scriptlets/prevent-refresh.js +++ b/src/scriptlets/prevent-refresh.js @@ -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. diff --git a/src/scriptlets/remove-node-text.js b/src/scriptlets/remove-node-text.js index b6e903aa..3d200cb5 100644 --- a/src/scriptlets/remove-node-text.js +++ b/src/scriptlets/remove-node-text.js @@ -23,7 +23,7 @@ import { * * ### Syntax * - * ```adblock + * ```text * example.org#%#//scriptlet('remove-node-text', nodeName, textMatch[, parentSelector]) * ``` * diff --git a/src/scriptlets/trusted-replace-fetch-response.js b/src/scriptlets/trusted-replace-fetch-response.js index f8ff039b..1ba5b2a9 100644 --- a/src/scriptlets/trusted-replace-fetch-response.js +++ b/src/scriptlets/trusted-replace-fetch-response.js @@ -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: @@ -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 + * + * ```adblock + * example.org#%#//scriptlet('trusted-replace-fetch-response', '/noAds=false/g', 'noAds=true', 'example.com', 'true') + * ``` + * * @added v1.7.3. */ /* eslint-enable max-len */ diff --git a/src/scriptlets/trusted-replace-node-text.js b/src/scriptlets/trusted-replace-node-text.js index 13a6868d..391b210b 100644 --- a/src/scriptlets/trusted-replace-node-text.js +++ b/src/scriptlets/trusted-replace-node-text.js @@ -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. * @@ -55,7 +56,7 @@ import { * some text * ``` * - * 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') @@ -73,7 +74,21 @@ import { * some text * ``` * - * 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 + * + *

foa bar baz

// this node is going to be matched by both node name and text + * + * + *

fox bxr bxz

// 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') diff --git a/src/scriptlets/trusted-replace-xhr-response.js b/src/scriptlets/trusted-replace-xhr-response.js index 5efb2065..20f3feb7 100644 --- a/src/scriptlets/trusted-replace-xhr-response.js +++ b/src/scriptlets/trusted-replace-xhr-response.js @@ -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: @@ -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 + * + * ```adblock + * example.org#%#//scriptlet('trusted-replace-xhr-response', '/noAds=false/g', 'noAds=true', 'example.com', 'true') + * ``` + * * @added v1.7.3. */ /* eslint-enable max-len */