@@ -1138,11 +1138,16 @@ https://github.com/gorhill/uBlock/commit/749cec0f095f659d6c0b90eb89b729e9deb07c8
11381138
11391139### Syntax
11401140
1141+ <!-- markdownlint-disable line-length -->
1142+
11411143``` text
1142- example.org#%#//scriptlet('json-prune-fetch-response'[, propsToRemove[, obligatoryProps[, propsToMatch[, stack]]]])
1144+ example.org#%#//scriptlet('json-prune-fetch-response'[, propsToRemove[, obligatoryProps[, propsToMatch[, stack[, mode] ]]]])
11431145```
11441146
1147+ <!-- markdownlint-enable line-length -->
1148+
11451149- ` propsToRemove ` — optional, string of space-separated properties to remove.
1150+ In ` jsonpath ` mode only single JSONPath prune expression is supported.
11461151- ` obligatoryProps ` — optional, string of space-separated properties
11471152 which must be all present for the pruning to occur.
11481153- ` propsToMatch ` — optional, string of space-separated properties to match; possible props:
@@ -1155,6 +1160,11 @@ example.org#%#//scriptlet('json-prune-fetch-response'[, propsToRemove[, obligato
11551160 invalid regular expression will cause any value matching.
11561161- ` stack ` — optional, string or regular expression that must match the current function call stack trace;
11571162 if regular expression is invalid it will be skipped.
1163+ - ` mode ` — optional, syntax mode selector.
1164+ Supported values:
1165+ - ` legacy ` — force the existing legacy path syntax
1166+ - ` jsonpath ` — force JSONPath syntax
1167+ If omitted, the scriptlet detects JSONPath automatically for clearly JSONPath-shaped expressions.
11581168
11591169> Note please that you can use wildcard ` * ` for chain property name,
11601170> e.g. ` ad.*.src ` instead of ` ad.0.src ad.1.src ad.2.src ` .
@@ -1166,12 +1176,20 @@ example.org#%#//scriptlet('json-prune-fetch-response'[, propsToRemove[, obligato
11661176
11671177### Examples
11681178
1179+ <!-- markdownlint-disable line-length -->
1180+
116911811 . Removes property ` example ` from the JSON response of any fetch call:
11701182
11711183 ``` adblock
11721184 example.org#%#//scriptlet('json-prune-fetch-response', 'example')
11731185 ```
11741186
1187+ or `JSONPath` syntax:
1188+
1189+ ```adblock
1190+ example.org#%#//scriptlet('json-prune-fetch-response', '$.example')
1191+ ```
1192+
11751193 For instance, if the JSON response of a fetch call is:
11761194
11771195 ```js
@@ -1190,30 +1208,56 @@ example.org#%#//scriptlet('json-prune-fetch-response'[, propsToRemove[, obligato
11901208 example.org#%#//scriptlet('json-prune-fetch-response', 'a.b', 'ads.url.first')
11911209 ```
11921210
1211+ or `JSONPath` syntax:
1212+
1213+ ```adblock
1214+ example.org#%#//scriptlet('json-prune-fetch-response', '[?(@.ads.url.first)]$.a.b')
1215+ ```
1216+
119312173. Removes property `content.ad` from the JSON response of a fetch call if URL contains `content.json`:
11941218
11951219 ```adblock
11961220 example.org#%#//scriptlet('json-prune-fetch-response', 'content.ad', '', 'content.json')
11971221 ```
11981222
1223+ or `JSONPath` syntax:
1224+
1225+ ```adblock
1226+ example.org#%#//scriptlet('json-prune-fetch-response', '$.content.ad', '', 'content.json')
1227+ ```
1228+
119912294. Removes property `content.ad` from the JSON response of a fetch call if its error stack trace contains `test.js`:
12001230
12011231 ```adblock
12021232 example.org#%#//scriptlet('json-prune-fetch-response', 'content.ad', '', '', 'test.js')
12031233 ```
12041234
1235+ or `JSONPath` syntax:
1236+
1237+ ```adblock
1238+ example.org#%#//scriptlet('json-prune-fetch-response', '$.content.ad', '', '', 'test.js')
1239+ ```
1240+
120512415. A property in a list of properties can be a chain of properties with wildcard in it:
12061242
12071243 ```adblock
12081244 example.org#%#//scriptlet('json-prune-fetch-response', 'content.*.media.src', 'content.*.media.ad')
12091245 ```
12101246
1247+ or `JSONPath` syntax:
1248+
1249+ ```adblock
1250+ example.org#%#//scriptlet('json-prune-fetch-response', '$.content.*.media[?(@.ad)].src')
1251+ ```
1252+
121112536. Log all JSON responses of a fetch call:
12121254
12131255 ```adblock
12141256 example.org#%#//scriptlet('json-prune-fetch-response')
12151257 ```
12161258
1259+ <!-- markdownlint-enable line-length -->
1260+
12171261[Scriptlet source](../src/scriptlets/json-prune-fetch-response.ts)
12181262
12191263* * *
@@ -1229,11 +1273,16 @@ https://github.com/gorhill/uBlock/commit/3152896d428c54c76cfd66c3da110bd4d6506cb
12291273
12301274### Syntax
12311275
1276+ <!-- markdownlint-disable line-length -->
1277+
12321278```text
1233- example.org#%#//scriptlet('json-prune-xhr-response'[, propsToRemove[, obligatoryProps[, propsToMatch[, stack]]]])
1279+ example.org#%#//scriptlet('json-prune-xhr-response'[, propsToRemove[, obligatoryProps[, propsToMatch[, stack[, mode] ]]]])
12341280```
12351281
1282+ <!-- markdownlint-enable line-length -->
1283+
12361284- ` propsToRemove ` — optional, string of space-separated properties to remove
1285+ In ` jsonpath ` mode only single JSONPath prune expression is supported.
12371286- ` obligatoryProps ` — optional, string of space-separated properties
12381287 which must be all present for the pruning to occur
12391288- ` propsToMatch ` — optional, string of space-separated properties to match for extra condition; possible props:
@@ -1244,6 +1293,11 @@ example.org#%#//scriptlet('json-prune-xhr-response'[, propsToRemove[, obligatory
12441293 passed to ` XMLHttpRequest.open() ` call
12451294- ` stack ` — optional, string or regular expression that must match the current function call stack trace;
12461295 if regular expression is invalid it will be skipped
1296+ - ` mode ` — optional, syntax mode selector.
1297+ Supported values:
1298+ - ` legacy ` — force the existing legacy path syntax
1299+ - ` jsonpath ` — force JSONPath syntax
1300+ If omitted, the scriptlet detects JSONPath automatically for clearly JSONPath-shaped expressions.
12471301
12481302> Note please that you can use wildcard ` * ` for chain property name,
12491303> e.g. ` ad.*.src ` instead of ` ad.0.src ad.1.src ad.2.src ` .
@@ -1261,6 +1315,12 @@ example.org#%#//scriptlet('json-prune-xhr-response'[, propsToRemove[, obligatory
12611315 example.org#%#//scriptlet('json-prune-xhr-response', 'example')
12621316 ```
12631317
1318+ or `JSONPath` syntax:
1319+
1320+ ```adblock
1321+ example.org#%#//scriptlet('json-prune-xhr-response', '$.example')
1322+ ```
1323+
12641324 For instance, if the JSON response of a XMLHttpRequest call is:
12651325
12661326 ```js
@@ -1279,25 +1339,49 @@ example.org#%#//scriptlet('json-prune-xhr-response'[, propsToRemove[, obligatory
12791339 example.org#%#//scriptlet('json-prune-xhr-response', 'a.b', 'ads.url.first')
12801340 ```
12811341
1342+ or `JSONPath` syntax:
1343+
1344+ ```adblock
1345+ example.org#%#//scriptlet('json-prune-xhr-response', '[?(@.ads.url.first)]$.a.b')
1346+ ```
1347+
128213483. Removes property `content.ad` from the JSON response of a XMLHttpRequest call if URL contains `content.json`
12831349
12841350 ```adblock
12851351 example.org#%#//scriptlet('json-prune-xhr-response', 'content.ad', '', 'content.json')
12861352 ```
12871353
1354+ or `JSONPath` syntax:
1355+
1356+ ```adblock
1357+ example.org#%#//scriptlet('json-prune-xhr-response', '$.content.ad', '', 'content.json')
1358+ ```
1359+
128813604. Removes property `content.ad` from the JSON response of a XMLHttpRequest call
12891361if its error stack trace contains `test.js`
12901362
12911363 ```adblock
12921364 example.org#%#//scriptlet('json-prune-xhr-response', 'content.ad', '', '', 'test.js')
12931365 ```
12941366
1367+ or `JSONPath` syntax:
1368+
1369+ ```adblock
1370+ example.org#%#//scriptlet('json-prune-xhr-response', '$.content.ad', '', '', 'test.js')
1371+ ```
1372+
129513735. A property in a list of properties can be a chain of properties with wildcard in it
12961374
12971375 ```adblock
12981376 example.org#%#//scriptlet('json-prune-xhr-response', 'content.*.media.src', 'content.*.media.ad')
12991377 ```
13001378
1379+ or `JSONPath` syntax:
1380+
1381+ ```adblock
1382+ example.org#%#//scriptlet('json-prune-xhr-response', '$.content.*.media[?(@.ad)].src')
1383+ ```
1384+
130113856. Log all JSON responses of a XMLHttpRequest call
13021386
13031387 ```adblock
@@ -1323,27 +1407,42 @@ https://gitlab.com/eyeo/snippets/-/blob/main/source/behavioral/json-prune.js
13231407### Syntax
13241408
13251409```text
1326- example.org#%#//scriptlet('json-prune'[, propsToRemove [, obligatoryProps [, stack]]])
1410+ example.org#%#//scriptlet('json-prune'[, propsToRemove [, obligatoryProps [, stack [, mode] ]]])
13271411```
13281412
13291413- ` propsToRemove ` — optional, string of space-separated properties to remove
1414+ In ` jsonpath ` mode only single JSONPath prune expression is supported.
13301415- ` obligatoryProps ` — optional, string of space-separated properties
13311416 which must be all present for the pruning to occur
1417+ In ` jsonpath ` mode this argument is ignored. Express such preconditions
1418+ directly in ` propsToRemove ` with leading JSONPath guards and filters.
13321419- ` stack ` — optional, string or regular expression that must match the current function call stack trace;
13331420 if regular expression is invalid it will be skipped
1421+ - ` mode ` — optional, syntax mode selector.
1422+ Supported values:
1423+ - ` legacy ` — force the existing legacy path syntax
1424+ - ` jsonpath ` — force JSONPath syntax
1425+ If omitted, the scriptlet detects JSONPath automatically only for clearly JSONPath-shaped expressions,
1426+ otherwise it falls back to legacy syntax.
13341427
13351428> Note please that you can use wildcard ` * ` for chain property name,
13361429> e.g. ` ad.*.src ` instead of ` ad.0.src ad.1.src ad.2.src ` .
13371430
13381431### Examples
13391432
1340- 1 . Removes property ` example ` from the results of JSON.parse call
1433+ 1 . Removes property ` example ` from the results of ` JSON.parse ` call
13411434
13421435 ``` adblock
13431436 example.org#%#//scriptlet('json-prune', 'example')
13441437 ```
13451438
1346- JSON.parse call:
1439+ or `JSONPath` syntax:
1440+
1441+ ```adblock
1442+ example.org#%#//scriptlet('json-prune', '$.example')
1443+ ```
1444+
1445+ `JSON.parse` call:
13471446
13481447 ```html
13491448 JSON.parse('{"one":1,"example":true}')
@@ -1366,13 +1465,19 @@ example.org#%#//scriptlet('json-prune'[, propsToRemove [, obligatoryProps [, sta
13661465 }
13671466 ```
13681467
1369- 1. If there are no specified properties in the result of JSON.parse call, pruning will NOT occur
1468+ 1. If there are no specified properties in the result of ` JSON.parse` call, pruning will NOT occur
13701469
13711470 ```adblock
13721471 example.org#%#//scriptlet('json-prune', 'one', 'obligatoryProp')
13731472 ```
13741473
1375- JSON.parse call:
1474+ or `JSONPath` syntax:
1475+
1476+ ```adblock
1477+ example.org#%#//scriptlet('json-prune', '[?(@.obligatoryProp)]$.one')
1478+ ```
1479+
1480+ `JSON.parse` call:
13761481
13771482 ```html
13781483 JSON.parse('{"one":1,"two":2}')
@@ -1402,7 +1507,13 @@ example.org#%#//scriptlet('json-prune'[, propsToRemove [, obligatoryProps [, sta
14021507 example.org#%#//scriptlet('json-prune', 'a.b', 'ads.url.first')
14031508 ```
14041509
1405- JSON.parse call:
1510+ or `JSONPath` syntax:
1511+
1512+ ```adblock
1513+ example.org#%#//scriptlet('json-prune', '[?(@.ads.url.first)]$.a.b')
1514+ ```
1515+
1516+ `JSON.parse` call:
14061517
14071518 ```html
14081519 JSON.parse('{"a":{"b":123},"ads":{"url":{"first":"abc"}}}')
@@ -1436,13 +1547,19 @@ example.org#%#//scriptlet('json-prune'[, propsToRemove [, obligatoryProps [, sta
14361547 }
14371548 ```
14381549
1439- 1. Removes property `content.ad` from the results of JSON.parse call if its error stack trace contains `test.js`
1550+ 1. Removes property `content.ad` from the results of ` JSON.parse` call if its error stack trace contains `test.js`
14401551
14411552 ```adblock
14421553 example.org#%#//scriptlet('json-prune', 'content.ad', '', 'test.js')
14431554 ```
14441555
1445- JSON.parse call:
1556+ or `JSONPath` syntax:
1557+
1558+ ```adblock
1559+ example.org#%#//scriptlet('json-prune', '$.content.ad', '', 'test.js')
1560+ ```
1561+
1562+ `JSON.parse` call:
14461563
14471564 ```html
14481565 JSON.parse('{"content":{"ad":{"src":"a.js"}}}')
@@ -1474,7 +1591,13 @@ example.org#%#//scriptlet('json-prune'[, propsToRemove [, obligatoryProps [, sta
14741591 example.org#%#//scriptlet('json-prune', 'content.*.media.src', 'content.*.media.ad')
14751592 ```
14761593
1477- JSON.parse call:
1594+ or `JSONPath` syntax:
1595+
1596+ ```adblock
1597+ example.org#%#//scriptlet('json-prune', '[?(@.content.*.media.ad)]$.content.*.media.src')
1598+ ```
1599+
1600+ `JSON.parse` call:
14781601
14791602 ```html
14801603 JSON.parse('{"content":{"block1":{"media":{"src":"1.jpg","ad":true}},"block2":{"media":{"src":"2.jpg"}}}}')
@@ -1523,7 +1646,13 @@ example.org#%#//scriptlet('json-prune'[, propsToRemove [, obligatoryProps [, sta
15231646 example.org#%#//scriptlet('json-prune', 'videos.{-}.isAd')
15241647 ```
15251648
1526- JSON.parse call:
1649+ or `JSONPath` syntax:
1650+
1651+ ```adblock
1652+ example.org#%#//scriptlet('json-prune', '$.videos.*[?(@.isAd)]')
1653+ ```
1654+
1655+ `JSON.parse` call:
15271656
15281657 ```html
15291658 JSON.parse('{"videos":{"video1":{"isAd":true,"src":"video1.mp4"},"video2":{"src":"video1.mp4"}}}')
@@ -1563,7 +1692,13 @@ example.org#%#//scriptlet('json-prune'[, propsToRemove [, obligatoryProps [, sta
15631692 example.org#%#//scriptlet('json-prune', 'videos.{-}.isAd.[=].true')
15641693 ```
15651694
1566- JSON.parse call:
1695+ or `JSONPath` syntax:
1696+
1697+ ```adblock
1698+ example.org#%#//scriptlet('json-prune', '$.videos.*[?(@.isAd==true)]')
1699+ ```
1700+
1701+ `JSON.parse` call:
15671702
15681703 ```html
15691704 JSON.parse('{"videos":{"video1":{"isAd":true,"src":"video1.mp4"},"video2":{"isAd":false,"src":"video1.mp4"}}}')
@@ -1626,11 +1761,17 @@ https://github.com/gorhill/uBlock/wiki/Resources-Library#addeventlistener-logger
16261761
16271762### Syntax
16281763
1629- ```adblock
1630- example.org#%#//scriptlet('log-addEventListener')
1764+ ```text
1765+ example.org#%#//scriptlet('log-addEventListener'[, noProtect] )
16311766```
16321767
1633- [ Scriptlet source] ( ../src/scriptlets/log-addEventListener.js )
1768+ - ` noProtect ` — optional, if set to ` 'true' ` , the scriptlet will use simple assignment instead of
1769+ ` Object.defineProperty ` with a no-op setter. This allows other scriptlets or tools to override
1770+ ` addEventListener ` later if needed. By default, the scriptlet protects the override from being
1771+ overwritten by website scripts. If compatibility with other scriptlets is needed,
1772+ set this parameter to ` 'true' ` .
1773+
1774+ [ Scriptlet source] ( ../src/scriptlets/log-addEventListener.ts )
16341775
16351776* * *
16361777
0 commit comments