Skip to content

Commit

Permalink
fix trusted scriptlets docs md-linter errors
Browse files Browse the repository at this point in the history
  • Loading branch information
slavaleleka committed May 24, 2023
1 parent 3e28abb commit ccf22c0
Show file tree
Hide file tree
Showing 7 changed files with 295 additions and 216 deletions.
107 changes: 63 additions & 44 deletions src/scriptlets/trusted-click-element.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,67 +12,86 @@ import {
* @trustedScriptlet trusted-click-element
*
* @description
* Clicks selected elements in a strict sequence, ordered by selectors passed, and waiting for them to render in the DOM first.
* Clicks selected elements in a strict sequence, ordered by selectors passed,
* and waiting for them to render in the DOM first.
* Deactivates after all elements have been clicked or by 10s timeout.
*
* **Syntax**
* ```
* ### Syntax
*
* ```text
* example.com#%#//scriptlet('trusted-click-element', selectors[, extraMatch[, delay]])
* ```
*
* - `selectors` — required, string with query selectors delimited by comma
* - `extraMatch` — optional, extra condition to check on a page; allows to match `cookie` and `localStorage`; can be set as `name:key[=value]` where `value` is optional.
* If `cookie`/`localStorage` starts with `!` then the element will only be clicked if specified cookie/localStorage item does not exist.
* Multiple conditions are allowed inside one `extraMatch` but they should be delimited by comma and each of them should match the syntax. Possible `name`s:
* - `cookie` - test string or regex against cookies on a page
* - `localStorage` - check if localStorage item is present
* - `extraMatch` — optional, extra condition to check on a page; allows to match `cookie` and `localStorage`;
* can be set as `name:key[=value]` where `value` is optional.
* If `cookie`/`localStorage` starts with `!` then the element will only be clicked
* if specified cookie/localStorage item does not exist.
* Multiple conditions are allowed inside one `extraMatch` but they should be delimited by comma
* and each of them should match the syntax. Possible `name`s:
* - `cookie` - test string or regex against cookies on a page
* - `localStorage` - check if localStorage item is present
* - `delay` — optional, time in ms to delay scriptlet execution, defaults to instant execution.
*
* **Examples**
* ### Examples
*
* 1. Click single element by selector
* ```
* example.com#%#//scriptlet('trusted-click-element', 'button[name="agree"]')
* ```
*
* 2. Delay click execution by 500ms
* ```
* example.com#%#//scriptlet('trusted-click-element', 'button[name="agree"]', '', '500')
* ```
* ```adblock
* example.com#%#//scriptlet('trusted-click-element', 'button[name="agree"]')
* ```
*
* 3. Click multiple elements by selector with a delay
* ```
* example.com#%#//scriptlet('trusted-click-element', 'button[name="agree"], button[name="check"], input[type="submit"][value="akkoord"]', '', '500')
* ```
* 1. Delay click execution by 500ms
*
* 4. Match cookies by keys using regex and string
* ```
* example.com#%#//scriptlet('trusted-click-element', 'button[name="agree"]', 'cookie:userConsentCommunity, cookie:/cmpconsent|cmp/')
* ```
* ```adblock
* example.com#%#//scriptlet('trusted-click-element', 'button[name="agree"]', '', '500')
* ```
*
* 5. Match by cookie key=value pairs using regex and string
* ```
* example.com#%#//scriptlet('trusted-click-element', 'button[name="agree"]', 'cookie:userConsentCommunity=true, cookie:/cmpconsent|cmp/=/[a-z]{1,5}/')
* ```
* 1. Click multiple elements by selector with a delay
*
* 6. Match by localStorage item 'promo' key
* ```
* example.com#%#//scriptlet('trusted-click-element', 'button[name="agree"]', 'localStorage:promo')
* ```
* <!-- markdownlint-disable line-length -->
*
* 7. Click multiple elements with delay and matching by both cookie string and localStorage item
* ```
* example.com#%#//scriptlet('trusted-click-element', 'button[name="agree"], input[type="submit"][value="akkoord"]', 'cookie:cmpconsent, localStorage:promo', '250')
* ```
* ```adblock
* example.com#%#//scriptlet('trusted-click-element', 'button[name="agree"], button[name="check"], input[type="submit"][value="akkoord"]', '', '500')
* ```
*
* 8. Click element only if cookie with name `cmpconsent` does not exist
* ```
* example.com#%#//scriptlet('trusted-click-element', 'button[name="agree"]', '!cookie:cmpconsent')
* ```
* 1. Match cookies by keys using regex and string
*
* 9. Click element only if specified cookie string and localStorage item does not exist
* ```
* example.com#%#//scriptlet('trusted-click-element', 'button[name="agree"]', '!cookie:cmpconsent, !localStorage:promo')
* ```
* ```adblock
* example.com#%#//scriptlet('trusted-click-element', 'button[name="agree"]', 'cookie:userConsentCommunity, cookie:/cmpconsent|cmp/')
* ```
*
* 1. Match by cookie key=value pairs using regex and string
*
* ```adblock
* example.com#%#//scriptlet('trusted-click-element', 'button[name="agree"]', 'cookie:userConsentCommunity=true, cookie:/cmpconsent|cmp/=/[a-z]{1,5}/')
* ```
*
* 1. Match by localStorage item 'promo' key
*
* ```adblock
* example.com#%#//scriptlet('trusted-click-element', 'button[name="agree"]', 'localStorage:promo')
* ```
*
* 1. Click multiple elements with delay and matching by both cookie string and localStorage item
*
* ```adblock
* example.com#%#//scriptlet('trusted-click-element', 'button[name="agree"], input[type="submit"][value="akkoord"]', 'cookie:cmpconsent, localStorage:promo', '250')
* ```
*
* <!-- markdownlint-enable line-length -->
*
* 1. Click element only if cookie with name `cmpconsent` does not exist
*
* ```adblock
* example.com#%#//scriptlet('trusted-click-element', 'button[name="agree"]', '!cookie:cmpconsent')
* ```
*
* 1. Click element only if specified cookie string and localStorage item does not exist
*
* ```adblock
* example.com#%#//scriptlet('trusted-click-element', 'button[name="agree"]', '!cookie:consent, !localStorage:promo')
* ```
*
* @added v1.7.3.
*/
Expand Down
67 changes: 43 additions & 24 deletions src/scriptlets/trusted-replace-fetch-response.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,52 +24,71 @@ import {
* @description
* Replaces response text content of `fetch` requests if **all** given parameters match.
*
* **Syntax**
* ```
* ### Syntax
*
* ```text
* example.org#%#//scriptlet('trusted-replace-fetch-response'[, pattern, replacement[, propsToMatch]])
* ```
*
* - `pattern` — optional, argument for matching contents of responseText that should be replaced. If set, `replacement` is required;
* possible values:
* - `*` to match all text content
* - non-empty string
* - regular expression
* - `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.
* - `pattern` — optional, argument for matching contents of responseText that should be replaced.
* If set, `replacement` is required. Possible values:
* - `*` to match all text content
* - non-empty string
* - regular expression
* - `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:
* - string or regular expression for matching the URL passed to fetch call; empty string, wildcard `*` or invalid regular expression will match all fetch calls
* - colon-separated pairs `name:value` where
* - `name` is [`init` option name](https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch#parameters)
* - `value` is string or regular expression for matching the value of the option passed to fetch call; invalid regular expression will cause any value matching
* - string or regular expression for matching the URL passed to fetch call;
* empty string, wildcard `*` or invalid regular expression will match all fetch calls
* - colon-separated pairs `name:value` where
* <!-- markdownlint-disable-next-line line-length -->
* - `name` is [`init` option name](https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch#parameters)
* - `value` is string or regular expression for matching the value of the option passed to fetch call;
* invalid regular expression will cause any value matching
*
* > Usage with no arguments will log fetch calls to browser console;
* which is useful for debugging but only allowed for production filter lists.
* > may be is useful for debugging, and not allowed for production filter lists.
*
* > Scriptlet does nothing if response body can't be converted to text.
*
* **Examples**
* ### Examples
*
* 1. Log all fetch calls
* ```
*
* ```adblock
* example.org#%#//scriptlet('trusted-replace-fetch-response')
* ```
*
* 2. Replace response text content of fetch requests with specific url
* ```
* 1. Replace response text content of fetch requests with specific url
*
* <!-- markdownlint-disable line-length -->
*
* ```adblock
* example.org#%#//scriptlet('trusted-replace-fetch-response', 'adb_detect:true', 'adb_detect:false', 'example.org')
* example.org#%#//scriptlet('trusted-replace-fetch-response', '/#EXT-X-VMAP-AD-BREAK[\s\S]*?/', '#EXT-X-ENDLIST', 'example.org')
* ```
*
* 3. Remove all text content of fetch responses with specific request method
* ```
* <!-- markdownlint-enable line-length -->
*
* 1. Remove all text content of fetch responses with specific request method
*
* ```adblock
* example.org#%#//scriptlet('trusted-replace-fetch-response', '*', '', 'method:GET')
* ```
*
* 4. Replace response text content of fetch requests matching by URL regex and request methods
* ```
* 1. Replace response text content of fetch requests matching by URL regex and request methods
*
* <!-- markdownlint-disable line-length -->
*
* ```adblock
* example.org#%#//scriptlet('trusted-replace-fetch-response', '/#EXT-X-VMAP-AD-BREAK[\s\S]*?/', '#EXT-X-ENDLIST', '/\.m3u8/ method:/GET|HEAD/')
* ```
* 5. Remove text content of all fetch responses for example.com
* ```
*
* <!-- markdownlint-enable line-length -->
*
* 1. Remove text content of all fetch responses for example.com
*
* ```adblock
* example.org#%#//scriptlet('trusted-replace-fetch-response', '*', '', 'example.com')
* ```
*
Expand Down
62 changes: 38 additions & 24 deletions src/scriptlets/trusted-replace-xhr-response.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,49 +23,63 @@ import {
* @description
* Replaces response content of `xhr` requests if **all** given parameters match.
*
* **Syntax**
* ```
* ### Syntax
*
* ```text
* example.org#%#//scriptlet('trusted-replace-xhr-response'[, pattern, replacement[, propsToMatch]])
* ```
*
* - `pattern` — optional, argument for matching contents of responseText that should be replaced. If set, `replacement` is required;
* possible values:
* - `*` to match all text content
* - non-empty string
* - regular expression
* - `replacement` — optional, should be set if `pattern` is set. String to replace matched content with. Empty string to remove content.
* - `pattern` — optional, argument for matching contents of responseText that should be replaced.
* If set, `replacement` is required. Possible values:
* - `*` to match all text content
* - non-empty string
* - regular expression
* - `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:
* - string or regular expression for matching the URL passed to `XMLHttpRequest.open()` call;
* - colon-separated pairs `name:value` where
* - `name` — string or regular expression for matching XMLHttpRequest property name
* - `value` — string or regular expression for matching the value of the option passed to `XMLHttpRequest.open()` call
* - string or regular expression for matching the URL passed to `XMLHttpRequest.open()` call;
* - colon-separated pairs `name:value` where
* - `name` — string or regular expression for matching XMLHttpRequest property name
* - `value` — string or regular expression for matching the value of the option
* passed to `XMLHttpRequest.open()` call
*
* > Usage with no arguments will log XMLHttpRequest objects to browser console;
* which is useful for debugging but not permitted for production filter lists.
* > which is useful for debugging but not permitted for production filter lists.
*
* ### Examples
*
* **Examples**
* 1. Log all XMLHttpRequests
* ```
*
* ```adblock
* example.org#%#//scriptlet('trusted-replace-xhr-response')
* ```
*
* 2. Replace text content of XMLHttpRequests with specific url
* ```
* 1. Replace text content of XMLHttpRequests with specific url
*
* <!-- markdownlint-disable line-length -->
*
* ```adblock
* example.org#%#//scriptlet('trusted-replace-xhr-response', 'adb_detect:true', 'adb_detect:false', 'example.org')
* example.org#%#//scriptlet('trusted-replace-xhr-response', '/#EXT-X-VMAP-AD-BREAK[\s\S]*?/', '#EXT-X-ENDLIST', 'example.org')
* ```
*
* 3. Remove all text content of XMLHttpRequests with specific request method
* ```
* <!-- markdownlint-enable line-length -->
*
* 1. Remove all text content of XMLHttpRequests with specific request method
*
* ```adblock
* example.org#%#//scriptlet('trusted-replace-xhr-response', '*', '', 'method:GET')
* ```
*
* 4. Replace text content of XMLHttpRequests matching by URL regex and request methods
* ```
* example.org#%#//scriptlet('trusted-replace-xhr-response', '/#EXT-X-VMAP-AD-BREAK[\s\S]*?/', '#EXT-X-ENDLIST', '/\.m3u8/ method:/GET|HEAD/')
* ```
* 5. Remove all text content of all XMLHttpRequests for example.com
* 1. Replace text content of XMLHttpRequests matching by URL regex and request methods
*
* ```adblock
* example.org#%#//scriptlet('trusted-replace-xhr-response', '/#EXT-X-VMAP-AD-BREAK[\s\S]*?/', '#EXT-X-ENDLIST', '/\.m3u8/ method:/GET|HEAD/') <!-- markdownlint-disable-line line-length -->
* ```
*
* 1. Remove all text content of all XMLHttpRequests for example.com
*
* ```adblock
* example.org#%#//scriptlet('trusted-replace-xhr-response', '*', '', 'example.com')
* ```
*
Expand Down
62 changes: 33 additions & 29 deletions src/scriptlets/trusted-set-constant.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,50 +36,54 @@ import {
*
* > Use [set-constant](./about-scriptlets.md#set-constant) to set predefined values and functions.
*
* **Syntax**
* ```
* ### Syntax
*
* ```text
* example.org#%#//scriptlet('trusted-set-constant', property, value[, stack])
* ```
*
* - `property` — required, path to a property (joined with `.` if needed). The property must be attached to `window`.
* - `value` — required, an arbitrary value to be set; value type is being inferred from the argument, e.g '500' will be set as number;
* to set string type value wrap argument into another pair of quotes: `'"500"'`;
* - `value` — required, an arbitrary value to be set; value type is being inferred from the argument,
* e.g '500' will be set as number; to set string type value wrap argument into another pair of quotes: `'"500"'`;
* - `stack` — optional, string or regular expression that must match the current function call stack trace;
* if regular expression is invalid it will be skipped
* if regular expression is invalid it will be skipped
*
* ### Examples
*
* **Examples**
* 1. Set property values of different types
* ```
* ! Set string value wrapping argument into another pair of quotes
* example.org#%#//scriptlet('trusted-set-constant', 'click_r', '"null"')
*
* ✔ window.click_r === 'null'
* ✔ typeof window.click_r === 'string'
* ```adblock
* ! Set string value wrapping argument into another pair of quotes
* example.org#%#//scriptlet('trusted-set-constant', 'click_r', '"null"')
*
* ! Set inferred null value
* example.org#%#//scriptlet('trusted-set-constant', 'click_r', 'null')
* ✔ window.click_r === 'null'
* ✔ typeof window.click_r === 'string'
*
* ✔ window.click_r === null
* ✔ typeof window.click_r === 'object'
* ! Set inferred null value
* example.org#%#//scriptlet('trusted-set-constant', 'click_r', 'null')
*
* ! Set number type value
* example.org#%#//scriptlet('trusted-set-constant', 'click_r', '48')
* ✔ window.click_r === null
* ✔ typeof window.click_r === 'object'
*
* ✔ window.click_r === 48
* ✔ typeof window.click_r === 'number'
* ! Set number type value
* example.org#%#//scriptlet('trusted-set-constant', 'click_r', '48')
*
* ! Set array or object as property value, argument should be a JSON string
* example.org#%#//scriptlet('trusted-set-constant', 'click_r', '[1,"string"]')
* example.org#%#//scriptlet('trusted-set-constant', 'click_r', '{"aaa":123,"bbb":{"ccc":"string"}}')
* ```
* ✔ window.click_r === 48
* ✔ typeof window.click_r === 'number'
*
* 2. Use script stack matching to set value
* ```
* ! `document.first` will return `1` if the method is related to `checking.js`
* example.org#%#//scriptlet('trusted-set-constant', 'document.first', '1', 'checking.js')
* ! Set array or object as property value, argument should be a JSON string
* example.org#%#//scriptlet('trusted-set-constant', 'click_r', '[1,"string"]')
* example.org#%#//scriptlet('trusted-set-constant', 'click_r', '{"aaa":123,"bbb":{"ccc":"string"}}')
* ```
*
* ✔ document.first === 1 // if the condition described above is met
* ```
* 1. Use script stack matching to set value
*
* ```adblock
* ! `document.first` will return `1` if the method is related to `checking.js`
* example.org#%#//scriptlet('trusted-set-constant', 'document.first', '1', 'checking.js')
*
* ✔ document.first === 1 // if the condition described above is met
* ```
*
* @added v1.8.2.
*/
Expand Down
Loading

0 comments on commit ccf22c0

Please sign in to comment.