Skip to content

Commit

Permalink
Refactor scriptlets injection code
Browse files Browse the repository at this point in the history
Builtin scriptlets are no longer parsed as text-based resources,
they are imported as JS functions, and `toString()` is used to
obtain text-based representation of a scriptlet.

Scriptlet parameters are now passed as function call arguments
rather than by replacing text-based occurrences of `{{i}}`. The
arguments are always string values (see below for exception).

Support for argument as Object has been added. This opens the
door to have scriptlets using named arguments rather than
positional arguments, and hence easier to extend functionality
of existing scriptlets. Example:

    example.com##+js(scriplet, { "prop": "adblock", "value": false, "log": true })

Compatibility with user-provided scriptlets has been preserved.

User-provided scriptlets can benefit some of the changes:

Use the form `function(..){..}` instead of `(function(..){..})();`
in order to received scriptlet arguments as part of function call
-- instead of using `{{i}}`.

If using the form `function(..){..}`, you can choose to receive
an Object as argument -- just be sure that your scriptlet's
parameter is valid JSON notation.
  • Loading branch information
gorhill committed Mar 24, 2023
1 parent 56b8201 commit 18a84d2
Show file tree
Hide file tree
Showing 5 changed files with 530 additions and 314 deletions.
2 changes: 1 addition & 1 deletion .jshintrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"browser": true,
"devel": true,
"eqeqeq": true,
"esversion": 9,
"esversion": 11,
"globals": {
"chrome": false, // global variable in Chromium, Chrome, Opera
"globalThis": false,
Expand Down
Loading

0 comments on commit 18a84d2

Please sign in to comment.