1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-11-06 19:02:30 +01:00
Commit Graph

108 Commits

Author SHA1 Message Date
Raymond Hill
df5437a54f
Revert "Render List stats below on mobile"
This reverts commit 9ea39886b6.
2023-05-17 15:44:11 -04:00
Raymond Hill
9ea39886b6
Render List stats below on mobile 2023-05-16 12:10:40 -04:00
Raymond Hill
6c29ae82f2
Protect against possible page modification to addEventListener 2023-04-28 07:58:23 -04:00
Raymond Hill
3c12173dfe
Add ability to execute aeld scriptlet at a later time
As per discussion with filter list maintainers.

THis requires to use JSON notation for parameter passing:

- "runAt":  "end" = execute scriptlet at `DOMContentLoaded` event
- "runAt": "idle" = execute scriptlet at `load` event
2023-04-27 12:52:17 -04:00
Raymond Hill
349c8ca619
Fix overzealous logging in acs scriptlet 2023-04-23 09:28:59 -04:00
Raymond Hill
cc062d3a8a
No need for redundant "safe" 2023-04-15 11:14:14 -04:00
Raymond Hill
e1500ee88d
Add ability to defer set-constant execution
A new optional parameter has been added to `set-constant`
scriptlet: `runAt`, default to `0`.

 ..##+js(set, document.body.oncontextmenu, null, 2)

When the `runAt` parameter is present, uBO will take it into
account to possibly defer execution of `set-constant`:

- `runAt` not present: execute immediately
- `runAt` = 1: execute immediately
- `runAt` = 2: execute when document state is "interactive"
- `runAt` = 3: execute when document state is `"complete"
2023-04-11 21:45:40 -04:00
Raymond Hill
edbe96a401
Add logging ability to acs scriptlet, for the benefit of filter list
maintainers.

To enable logging, use the JSON approach to pass parameters to
`acs` scriptlet. Example:

    ..##+js(acs, { "target": "document.oncontextmenu", "log": true })

Whereas "target", "needle", and "context" correspond to their
respective positional argument. Using JSON form to pass parameters
allows to specify extra paramters to facilitate debugging of that
scriptlet:

- `"log": true` => output useful information at the dev console.
- `"debug": true` => break at key locations in the scriptlet.

The added logging/debugging capabilities work only in the dev build
of uBO or if the advanced setting `filterAuthorMode` is set to
`true`.
2023-04-02 12:01:58 -04:00
Raymond Hill
b5d78a07bf
Fix type in variable name
Related issue:
- https://github.com/uBlockOrigin/uBlock-issues/issues/2570
2023-03-30 20:46:44 -04:00
Raymond Hill
c8af55e27a
Harden aeld scriptlet against page's tampering
Related feedback:
- https://github.com/uBlockOrigin/uBlock-discussions/discussions/1#discussioncomment-5433222
2023-03-26 14:02:21 -04:00
Raymond Hill
5c9c87e485
Add ability for scriptlets to share local data
Related issue:
- https://github.com/uBlockOrigin/uBlock-issues/issues/1741

As a result of the new capability, usage of RegExp API in `aost`
scriptlet has been shielded from the webpage tampering with the
API.
2023-03-26 12:31:36 -04:00
Raymond Hill
236fb3ad59
Add scriptlet dependencies to reduce code duplication 2023-03-26 09:13:17 -04:00
Raymond Hill
439951824a
Remove addEventListenerLogger, expand addEventListenerDefuser
The scriptlet addEventListenerLogger has been removed.

The logging of addEventListener() calls can now be done with the
addEventListenerDefuser scriptlet, which now supports the
following named arguments:

"type": the event type to match. Default to '', i.e. match-all.

"pattern": the pattern to match against the handler argument
Default to '', i.e. match-all.

"log": an integer value telling when to log:

- 1: log only when both type and pattern matches, i.e. when a
     call to addEventListener() is defused
- 2: log when either the type or pattern matches
- 3: log all calls to addEventListener()

"debug": an integer value telling when to break into the
 debugger, useful to inspect the debugger's call stack.

- 1: break into the debugger when both type and pattern match,
     so effectively when defusing is taking place.
- 2: break into the debugger when either type or pattern matches.

The usage of named arguments is optional, positional arguments
are still supported as documented. Named arguments is required
to use "log" and/or "debug" arguments.

Obviously, do not use "log" or "debug" in any filter list, these
are investigative tools for filter list authors.

Examples of usage using named arguments:

  wikipedia.org##+js(aeld, { "type": "/mouse/", "pattern": "/.^/", "log": 2 })

Above filter will log calls to addEventListener() which have the
pattern "mouse" in the event type (so "mouseover", "mouseout",
etc.) without defusing any of them (because pattern can't match
anything).

  wikipedia.org##+js(aeld, { "type": "/.^/", "log": 2 })

Above filter will log all calls without defusing any of them
(because type can't match anything)

  wikipedia.org##+js(aeld, { "log": 1 })

Above filter will log and defuse all calls to addEventListener().
2023-03-25 12:35:56 -04:00
Raymond Hill
a51130baed
Remove unused scriptlets 2023-03-24 18:46:39 -04:00
Raymond Hill
18a84d2819
Refactor scriptlets injection code
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.
2023-03-24 14:05:18 -04:00
Raymond Hill
e93117cbb6
Add call-nothrow scriptlet
The purpose is to prevent a call to an existing function from
throwing an exception. The exception will be caught by the
scriptlet and neutralized.

The first argument must be a reference to a function call. At
the moment, the function call must exist at the time the
scriptlet is called.
2023-03-14 18:50:01 -04:00
Raymond Hill
fc84fdee52
Fine tune scriptlet 2023-03-14 08:21:22 -04:00
Raymond Hill
b3821e6869
Support removing whole lines of text with regex in m3u-prune scriptlet
Related issue:
- https://github.com/uBlockOrigin/uBlock-issues/issues/2508

If the first argument is a regex with multine flag set, the
scriptlet will execute the regex against the whole text, and
remove matching text from the whole text.

If the matching text does not contains whole lines, the text
won't be removed, i.e. it is not allowed to remove only part
of a line.
2023-03-12 17:45:02 -04:00
Raymond Hill
4b4ef6a60c
Rename href-from-text to href-sanitizer, add argument
Related issue:
- https://github.com/uBlockOrigin/uBlock-issues/issues/2531#issuecomment-1462389539

Usage:
- example.com##+js(href-sanitizer, a[href^="/go?to="]:not([title]))
- example.com##+js(href-sanitizer, a[href^="/go?to="][title], [title])

The second argument is the attribute from which to extract the text
to be used for the `href` attribute of the link. If the second
attribute is absent, the text content of the element will be used.
2023-03-09 13:37:06 -05:00
Raymond Hill
e123256eaf
Add experimental href-from-text scriptlet
Related issue:
- https://github.com/uBlockOrigin/uBlock-issues/issues/2531

Usage:

    example.com##+js(href-from-text, a[href^="/tracker-link?to="]

The above scriptlet will find all elements matching the selector
passed as 1st argument, and replace the `href` attribute with the
text content of the element, if all the following conditions are
met:

- The element is a link (`a`) element
- The link element has an existing `href` attribute
- The text content of the element is a valid `https`-based URL
2023-03-09 08:49:26 -05:00
Raymond Hill
2f646dbdb0
Pull reference Easylist assests from own repo 2022-10-24 12:37:04 -04:00
Raymond Hill
ec83127f6c
Update m3u-prune scriptlet 2022-09-26 22:37:11 -04:00
Raymond Hill
115f7bb687
Fix operator token-to-ctor map
Related issue:
- https://github.com/uBlockOrigin/uBlock-issues/issues/2294
2022-09-26 22:27:50 -04:00
Raymond Hill
6828e1c3b2
Bail out early if missing required argument 2022-09-25 06:57:51 -04:00
Raymond Hill
596145ceb9
Harden xml-prune scriptlet 2022-09-25 06:49:41 -04:00
Raymond Hill
bf690145c4
Add new scriptlet: xml-prune
Related issue:
- https://github.com/uBlockOrigin/uAssets/issues/14849

Arguments:

1. Required. The selector of elements which are to be removed.
   Example: Period[id*="-roll-"][id*="-ad-"]

2. An optional selector that must have a match in the document
   for the pruning to occur. No selector means the pruning can
   be performed regardless.

3. An optional URL which must be a match for the pruning to
   occur. If left blank, the pruning can be performed regardless.
2022-09-24 20:49:00 -04:00
Raymond Hill
65a0561072
Slightly change behavior of window-close-if scriplet
Related discussion:
- https://github.com/uBlockOrigin/uBlock-issues/discussions/2270

If the argument to the window-close-if scriptlet is a regex, the
match will be against the whole location URL, otherwise the
match will be against the part+query part of the location URL.
2022-09-17 12:46:42 -04:00
Raymond Hill
78fccadaf2
Fix bad alias
Related feedback:
- https://github.com/DandelionSprout/adfilt/issues/63#issuecomment-1214131551
2022-08-13 09:09:36 -04:00
Raymond Hill
9d81b7c4d9
Skip testing context when none present in acis scriptlet
Related issue:
- https://github.com/uBlockOrigin/uBlock-issues/issues/2154
2022-06-24 13:35:20 -04:00
Raymond Hill
b76d7c6af6
Also dispatch loadend event in case of match
Related issue:
- https://github.com/AdguardTeam/Scriptlets/issues/199
2022-05-08 11:22:32 -04:00
Raymond Hill
8d7469afcf
Fix typo 2021-12-13 14:28:39 -05:00
Raymond Hill
c198b9a748
Add window.close scriptlet
Related feedback:
- https://github.com/uBlockOrigin/uAssets/issues/10323#issuecomment-992312847

AdGuard's rationale:
- https://github.com/AdguardTeam/Scriptlets/issues/158
2021-12-13 08:14:30 -05:00
Raymond Hill
b3f1f75389
Update twitch scriptlet as suggested
Related discussion:
- https://github.com/uBlockOrigin/uBlock-issues/issues/1789#issuecomment-969416887
2021-11-16 07:22:06 -05:00
Raymond Hill
ddd31f3567
Update twitch-videoad.js scriptlet
Related commit:
- aad8946dab

Related discussion:
- https://github.com/uBlockOrigin/uBlock-issues/issues/1789#issuecomment-962440694
2021-11-14 13:55:34 -05:00
Raymond Hill
3f47172473
Update Twitch scriptlet
Related discussion:
- https://github.com/uBlockOrigin/uBlock-issues/issues/1789#issuecomment-959831926

Related commit:
- 7233b5fd22
2021-11-04 09:24:31 -04:00
pixeltris
cc0008df57
Fix broken twitch.tv functionality (#3858)
* Fix broken twitch.tv functionality

Fixes some features of twitch.tv which are broken due to device id change on every gql request.

Related issues:
- https://github.com/pixeltris/TwitchAdSolutions/issues/50
- https://github.com/pixeltris/TwitchAdSolutions/issues/45

* Use strict equality
2021-10-14 10:03:25 -04:00
Raymond Hill
aceaea0122
Minor code review 2021-10-14 09:22:36 -04:00
Eli Grey
1285f78e05
Don't assume document.documentElement is non-null (#3857)
* Fix uBlockOrigin/uBlock-issues#1756

This PR fixes uBlockOrigin/uBlock-issues#1756.

* fix dom-inspector.js

* more explicit if statements

* these changes should also be safe
2021-10-14 09:08:08 -04:00
Raymond Hill
0d3a1932e9
Update twitch-videoad scriptlet
Related issue:
- https://github.com/uBlockOrigin/uAssets/issues/5184#issuecomment-938379331

Solution contributed by <https://github.com/pixeltris>:
- 6be4c53130
2021-10-08 07:12:58 -04:00
Raymond Hill
c0a43b0d32
Add refresh-defuser scriptlet
To specifically defuse the reloading of a document through
a meta "refresh" tag.

Related feedback:
- https://www.reddit.com/r/uBlockOrigin/comments/q0frv0/

As per solution from AdGuard:
- https://www.reddit.com/r/uBlockOrigin/comments/q0frv0/while_reading_a_sports_article_i_was_redirected/hf7wo9v/
2021-10-03 09:46:24 -04:00
Raymond Hill
33a18c3a1e
Convert fingerprint2.js scriptlet into a redirectable resource
As per internal discussion with volunteer filter list
maintainers.
2021-09-18 10:55:22 -04:00
Raymond Hill
745fbd1c02
Add no-xhr-if scriptlet
As per request from filter list maintainers.
2021-09-11 09:15:39 -04:00
Raymond Hill
5dd91211ae
Catch exceptions thrown Object.defineProperty
Related issue:
- https://github.com/uBlockOrigin/uAssets/issues/9883

Related commit:
- a9e6f9c72c
2021-09-01 18:25:20 -04:00
Raymond Hill
a9e6f9c72c
Assign value in set-constant regardless of configurable property
Related issue:
- https://github.com/uBlockOrigin/uBlock-issues/issues/1694
2021-08-27 10:48:49 -04:00
Raymond Hill
a21ecafbc6
Improve reliability of set-constant scriptlet
Related issue:
- https://github.com/uBlockOrigin/uBlock-issues/issues/1694
2021-08-25 10:48:50 -04:00
Raymond Hill
4fe8126c66
Add ability to match against script content of data: URI
Related commit:
- ebc42ae21e
2021-07-18 08:50:57 -04:00
Raymond Hill
f07b1475a3
Fix hasty last commit 2021-07-17 14:27:37 -04:00
Raymond Hill
ebc42ae21e
Add abort-current-script scriptlet
This scriplet supersedes abort-current-inline-script (acis),
and accepts an optional third argument which is matched
against the `src` property of script resources.

When the third argument is not provided, the scriptlet
behaves essentially the same as `acis`, and because of
this `acis` is now aliased to `abort-current-script`, and
all existing `acis` filters will execute with no change
in behavior.

In the long run, usage of `abort-current-inline-script` or
its alias `acis` should go away and be replaced with
`abort-current-script` or its alias `acs`.
2021-07-17 14:03:50 -04:00
Raymond Hill
c91b4258e9
Put back mistakenly removed newline 2021-07-03 09:23:06 -04:00
Raymond Hill
35d7406214
Add asap behavior to remove-attr scriptlet
Related issue:
- https://github.com/uBlockOrigin/uAssets/issues/9528
2021-07-03 09:19:24 -04:00