Skip to content

Commit

Permalink
update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
stanislav-atr committed Jan 19, 2023
1 parent 7fa8b46 commit c179e6f
Show file tree
Hide file tree
Showing 2 changed files with 121 additions and 1 deletion.
63 changes: 62 additions & 1 deletion wiki/about-scriptlets.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
* [dir-string](#dir-string)
* [disable-newtab-links](#disable-newtab-links)
* [hide-in-shadow-dom](#hide-in-shadow-dom)
* [inject-css-in-shadow-dom](#inject-css-in-shadow-dom)
* [json-prune](#json-prune)
* [log-addEventListener](#log-addeventlistener)
* [log-eval](#log-eval)
Expand Down Expand Up @@ -447,6 +448,33 @@ virustotal.com#%#//scriptlet('hide-in-shadow-dom', 'vt-ui-contact-fab')
[Scriptlet source](../src/scriptlets/hide-in-shadow-dom.js)
* * *

### <a id="inject-css-in-shadow-dom"></a> ⚡️ inject-css-in-shadow-dom

Injects CSS rule into selected Shadow DOM subtrees on a page

**Syntax**
```
example.org#%#//scriptlet('inject-css-in-shadow-dom', cssRule[, hostSelector])
```

- `cssRule` - required, string representing a single css rule
- `hostSelector` - optional, string, selector to match shadow host elements. CSS rule will be only applied to shadow roots inside these elements.
Defaults to injecting css rule into all available roots.

**Examples**
1. Apply style to all shadow dom subtrees
```
example.org#%#//scriptlet('inject-css-in-shadow-dom', '#advertisement { display: none !important; }')
```

2. Apply style to a specific shadow dom subtree
```
example.org#%#//scriptlet('inject-css-in-shadow-dom', '#content { margin-top: 0 !important; }', '.row > #hidden')
```

[Scriptlet source](../src/scriptlets/inject-css-in-shadow-dom.js)
* * *

### <a id="json-prune"></a> ⚡️ json-prune

Removes specified properties from the result of calling JSON.parse and returns the caller
Expand Down Expand Up @@ -970,6 +998,7 @@ If not set, prevents all `setInterval` calls due to specified `matchDelay`.
- `matchDelay` - optional, must be an integer.
If starts with `!`, scriptlet will not match the delay but all other will be defused.
If do not start with `!`, the delay passed to the `setInterval` call will be matched.
Decimal delay values will be rounded down, e.g `10.95` will be matched by `matchDelay` with value `10`.
> If `prevent-setInterval` log looks like `setInterval(undefined, 1000)`,
it means that no callback was passed to setInterval() and that's not scriptlet issue
Expand Down Expand Up @@ -1045,6 +1074,21 @@ and obviously it can not be matched by `matchCallback`.
}, 500);
```
5. Prevents `setInterval` calls if the callback contains `value` and delay is a decimal.
```
example.org#%#//scriptlet('prevent-setInterval', 'value', '300')
```
For instance, the following calls will be prevented:
```javascript
setInterval(function () {
window.test = "value";
}, 300);
setInterval(function () {
window.test = "value";
}, 300 + Math.random());
```
[Scriptlet source](../src/scriptlets/prevent-setInterval.js)
* * *
Expand Down Expand Up @@ -1072,6 +1116,7 @@ If not set, prevents all `setTimeout` calls due to specified `matchDelay`.
- `matchDelay` - optional, must be an integer.
If starts with `!`, scriptlet will not match the delay but all other will be defused.
If do not start with `!`, the delay passed to the `setTimeout` call will be matched.
Decimal delay values will be rounded down, e.g `10.95` will be matched by `matchDelay` with value `10`.
> If `prevent-setTimeout` log looks like `setTimeout(undefined, 1000)`,
it means that no callback was passed to setTimeout() and that's not scriptlet issue
Expand Down Expand Up @@ -1147,6 +1192,21 @@ and obviously it can not be matched by `matchCallback`.
}, 500);
```
5. Prevents `setTimeout` calls if the callback contains `value` and delay is a decimal.
```
example.org#%#//scriptlet('prevent-setTimeout', 'value', '300')
```
For instance, the following calls will be prevented:
```javascript
setTimeout(function () {
window.test = "value";
}, 300);
setTimeout(function () {
window.test = "value";
}, 300 + Math.random());
```
[Scriptlet source](../src/scriptlets/prevent-setTimeout.js)
* * *
Expand Down Expand Up @@ -1538,8 +1598,10 @@ example.org#%#//scriptlet('set-constant', property, value[, stack])
- `emptyObj` - empty object
- `emptyArr` - empty array
- `noopFunc` - function with empty body
- `noopCallbackFunc` - function returning noopFunc
- `trueFunc` - function returning true
- `falseFunc` - function returning false
- `throwFunc` - function throwing an error
- `noopPromiseResolve` - function returning Promise object that is resolved with an empty response
- `noopPromiseReject` - function returning Promise.reject()
- `''` - empty string
Expand Down Expand Up @@ -1732,7 +1794,6 @@ example.org#%#//scriptlet('set-session-storage-item', 'exit-intent-marketing', '
Removes an element from the specified XML.
**Syntax**
```
example.org#%#//scriptlet('xml-prune'[, propsToMatch[, optionalProp[, urlToMatch]]])
Expand Down
59 changes: 59 additions & 0 deletions wiki/about-trusted-scriptlets.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* [trusted-click-element](#trusted-click-element)
* [trusted-replace-fetch-response](#trusted-replace-fetch-response)
* [trusted-replace-xhr-response](#trusted-replace-xhr-response)
* [trusted-set-constant](#trusted-set-constant)
* [trusted-set-cookie-reload](#trusted-set-cookie-reload)
* [trusted-set-cookie](#trusted-set-cookie)
* [trusted-set-local-storage-item](#trusted-set-local-storage-item)
Expand Down Expand Up @@ -171,6 +172,64 @@ which is useful for debugging but not permitted for production filter lists.
[Scriptlet source](../src/scriptlets/trusted-replace-xhr-response.js)
* * *

### <a id="trusted-set-constant"></a> ⚡️ trusted-set-constant

Creates a constant property and assigns it a specified value.

> Actually, it's not a constant. Please note, that it can be rewritten with a value of a different type.
> If empty object is present in chain it will be trapped until chain leftovers appear.
> Use [set-constant](./about-scriptlets.md#set-constant) to set predefined values and functions.
**Syntax**
```
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"'`;
- `stack` - optional, string or regular expression that must match the current function call stack trace;
if regular expression is invalid it will be skipped

**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'
! Set inferred null value
example.org#%#//scriptlet('trusted-set-constant', 'click_r', 'null')
✔ window.click_r === null
✔ typeof window.click_r === 'object'
! Set number type value
example.org#%#//scriptlet('trusted-set-constant', 'click_r', '48')
✔ window.click_r === 48
✔ typeof window.click_r === 'number'
! 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"}}')
```

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')
✔ document.first === 1 // if the condition described above is met
```

[Scriptlet source](../src/scriptlets/trusted-set-constant.js)
* * *

### <a id="trusted-set-cookie-reload"></a> ⚡️ trusted-set-cookie-reload

Sets a cookie with arbitrary name and value,
Expand Down

0 comments on commit c179e6f

Please sign in to comment.