mirror of
https://github.com/gorhill/uBlock.git
synced 2024-11-16 23:42:39 +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
@ -4906,14 +4906,17 @@ builtinScriptlets.push({
|
|||||||
});
|
});
|
||||||
function trustedReplaceOutboundText(
|
function trustedReplaceOutboundText(
|
||||||
propChain = '',
|
propChain = '',
|
||||||
pattern = '',
|
rawPattern = '',
|
||||||
replacement = '',
|
rawReplacement = '',
|
||||||
...args
|
...args
|
||||||
) {
|
) {
|
||||||
if ( propChain === '' ) { return; }
|
if ( propChain === '' ) { return; }
|
||||||
const safe = safeSelf();
|
const safe = safeSelf();
|
||||||
const logPrefix = safe.makeLogPrefix('trusted-replace-outbound-text', propChain, pattern, replacement, ...args);
|
const logPrefix = safe.makeLogPrefix('trusted-replace-outbound-text', propChain, rawPattern, rawReplacement, ...args);
|
||||||
const rePattern = safe.patternToRegex(pattern);
|
const rePattern = safe.patternToRegex(rawPattern);
|
||||||
|
const replacement = rawReplacement.startsWith('json:')
|
||||||
|
? safe.JSON_parse(rawReplacement.slice(5))
|
||||||
|
: rawReplacement;
|
||||||
const extraArgs = safe.getExtraArgs(args);
|
const extraArgs = safe.getExtraArgs(args);
|
||||||
const reCondition = safe.patternToRegex(extraArgs.condition || '');
|
const reCondition = safe.patternToRegex(extraArgs.condition || '');
|
||||||
const reflector = proxyApplyFn(propChain, function(...args) {
|
const reflector = proxyApplyFn(propChain, function(...args) {
|
||||||
@ -4923,7 +4926,7 @@ function trustedReplaceOutboundText(
|
|||||||
try { textBefore = self.atob(encodedTextBefore); }
|
try { textBefore = self.atob(encodedTextBefore); }
|
||||||
catch(ex) { return encodedTextBefore; }
|
catch(ex) { return encodedTextBefore; }
|
||||||
}
|
}
|
||||||
if ( pattern === '' ) {
|
if ( rawPattern === '' ) {
|
||||||
safe.uboLog(logPrefix, 'Decoded outbound text:\n', textBefore);
|
safe.uboLog(logPrefix, 'Decoded outbound text:\n', textBefore);
|
||||||
return encodedTextBefore;
|
return encodedTextBefore;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user