mirror of
https://github.com/gorhill/uBlock.git
synced 2024-11-10 01:02:08 +01:00
Improve trusted-replace-outbound-text
scriptlet
When the replacement starts with `json:`, it will be first decoded using JSON.parse(). Example: example.com##+js(trusted-replace-outbound-text, somefn, json:"ok") The doublequotes are required since this is what JSON.parse() expects as a valid JSON string.
This commit is contained in:
parent
f5f042a6f0
commit
0dcb985601
1 changed files with 8 additions and 5 deletions
|
@ -4906,14 +4906,17 @@ builtinScriptlets.push({
|
|||
});
|
||||
function trustedReplaceOutboundText(
|
||||
propChain = '',
|
||||
pattern = '',
|
||||
replacement = '',
|
||||
rawPattern = '',
|
||||
rawReplacement = '',
|
||||
...args
|
||||
) {
|
||||
if ( propChain === '' ) { return; }
|
||||
const safe = safeSelf();
|
||||
const logPrefix = safe.makeLogPrefix('trusted-replace-outbound-text', propChain, pattern, replacement, ...args);
|
||||
const rePattern = safe.patternToRegex(pattern);
|
||||
const logPrefix = safe.makeLogPrefix('trusted-replace-outbound-text', propChain, rawPattern, rawReplacement, ...args);
|
||||
const rePattern = safe.patternToRegex(rawPattern);
|
||||
const replacement = rawReplacement.startsWith('json:')
|
||||
? safe.JSON_parse(rawReplacement.slice(5))
|
||||
: rawReplacement;
|
||||
const extraArgs = safe.getExtraArgs(args);
|
||||
const reCondition = safe.patternToRegex(extraArgs.condition || '');
|
||||
const reflector = proxyApplyFn(propChain, function(...args) {
|
||||
|
@ -4923,7 +4926,7 @@ function trustedReplaceOutboundText(
|
|||
try { textBefore = self.atob(encodedTextBefore); }
|
||||
catch(ex) { return encodedTextBefore; }
|
||||
}
|
||||
if ( pattern === '' ) {
|
||||
if ( rawPattern === '' ) {
|
||||
safe.uboLog(logPrefix, 'Decoded outbound text:\n', textBefore);
|
||||
return encodedTextBefore;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue