AdguardTeam / AdguardTeam/Scriptlets

New approach to scriptlets

オープン
#83 コメント 0 件 リアクション 0 件 担当者 1 名 @ameshkov が担当を希望しています GitHub で見る
enhancement Priority: P4 Version: Scriptlets v3.0
主要言語
JavaScript
スター
195
フォーク
33
PR マージ指標
30日以内にマージされた PR はありません

説明

_Originally posted by @ameshkov in https://github.com/AdguardTeam/Scriptlets/issues/82#issuecomment-625230500_

Check out all the comments in the thread.

Here are some thoughts on this.

Currently, there are two important scriptlets groups:

* Override a property get/set and do something.
* Override a function call and do something.

The algorithm, in general, may look like this:

1. Override a property or a function.
2. Once it's called, check the "matchers" specified in the rule: stack trace, script content, function call arguments.
3. Apply one of the possible actions.

Here are some of the existing scriptlets written this way (don't mind the naming, I am coming up with this right now):
```
! noeval
function('window.eval'):match-argument(1, /regex/):noop()
! set-constant
property('window.test', 'get'):return-constant(true)
! log-eval
function('window.eval):log()'
! prevent-setInterval / no-setInterval-if
function('window.setInterval'):match-argument(1, /regex/):match-argument(2, 500):noop()
! json-prune
function('JSON.parse'):match-argument-json-props(1, 'someProp'):remove-json-props-and-return(1, 'someProp')
```
> I am not sure about the `JSON.parse` example, though. Having the capability to apply this kind of modification to an arbitrary function call can be dangerous in the wrong hands.

This approach makes adding new matching criteria really easy. Just a couple of examples that can be useful: `match-url`, `match-selector`, etc.

Some scriptlets that cannot be categorized as "function", "property" or "matcher" will be categorized as "actions", and it should still be possible to apply some "matchers" to them. For instance:
```
! run remove-attr only on a specific page
:match-url('some-page-url'):remove-attr('onclick', 'selector>here')
```

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。