-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add trusted-source support for privileged scriptlets
At the moment, the only filter lists deemed from a "trusted source" are uBO-specific filter lists (i.e. "uBlock filters -- ..."), and the user's own filters from "My filters". A new scriptlet which can only be used by filter lists from trusted sources has been introduced: `sed.js`. The new `sed.js` scriptlet provides the ability to perform text-level substitutions. Usage: example.org##+js(sed, nodeName, pattern, replacement, ...) `nodeName` The name of the node for which the text content must be substituted. Valid node names can be found at: https://developer.mozilla.org/en-US/docs/Web/API/Node/nodeName `pattern` A string or regex to find in the text content of the node as the target of substitution. `replacement` The replacement text. Can be omitted if the goal is to delete the text which matches the pattern. Cannot be omitted if extra pairs of parameters have to be used (see below). Optionally, extra pairs of parameters to modify the behavior of the scriptlet: `condition, pattern` A string or regex which must be found in the text content of the node in order for the substitution to occur. `sedCount, n` This will cause the scriptlet to stop after n instances of substitution. Since a mutation oberver is used by the scriptlet, it's advised to stop it whenever it becomes pointless. Default to zero, which means the scriptlet never stops. `tryCount, n` This will cause the scriptlet to stop after n instances of mutation observer run (regardless of whether a substitution occurred). Default to zero, which means the scriptlet never stops. `log, 1` This will cause the scriptlet to output information at the console, useful as a debugging tool for filter authors. The logging ability is supported only in the dev build of uBO. Examples of usage: example.com##+js(sed, script, /devtoolsDetector\.launch\(\)\;/, , sedCount, 1) example.com##+js(sed, #text, /^Advertisement$/)
- Loading branch information
Showing
4 changed files
with
165 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
4187633
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was testing this scriptlet on
https://www.iltalehti.fi/
and I noticed that I cannot replace textEtusivu
for some reason.iltalehti.fi##+js(sed, span, Etusivu)
Can you reproduce this @gorhill ?
4187633
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Works great for
ghacks.net
where we can now remove text node titled - "Advertisement" withghacks.net##+js(sed, #text, /^Advertisement$/)
👍4187633
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@peace2000 the nodeName needs to be
#text
to target text, from what I understood.But this brings me to a question: Would it be possible to limit the target of the scriptlet using css selectors to only a certain part of the webpage rather than its entirety? @gorhill
4187633
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The scriptlet acts on mutation events, so the test on whether to target a specific part of the DOM would need to be done after a node is found to pass all conditions. This would add some more work, but yes, feasible. I would want to see a need for this before further changing the scriptlet, which I want to stabilize at this point. More parameters can be added later without compromising backward/forward compatibility.
Note that this wouldn't help efficiency if that is your concern, all mutation events are processed, to test whether a node is part of a specific portion of the DOM would add to the work done.