Improve trusted-replace-outbound-text scriptlet · gorhill/uBlock@fa6740a (original) (raw)

`@@ -4782,20 +4782,29 @@ function trustedReplaceOutboundText(

`

4782

4782

`const extraArgs = safe.getExtraArgs(args);

`

4783

4783

`const reCondition = safe.patternToRegex(extraArgs.condition || '');

`

4784

4784

`const reflector = proxyApplyFn(propChain, function(...args) {

`

4785

``

`-

const textBefore = reflector(...args);

`

``

4785

`+

const encodedTextBefore = reflector(...args);

`

``

4786

`+

let textBefore = encodedTextBefore;

`

``

4787

`+

if ( extraArgs.encoding === 'base64' ) {

`

``

4788

`+

try { textBefore = self.atob(encodedTextBefore); }

`

``

4789

`+

catch(ex) { return encodedTextBefore; }

`

``

4790

`+

}

`

4786

4791

`if ( pattern === '' ) {

`

4787

``

`-

safe.uboLog(logPrefix, 'Outbound text:\n', textBefore);

`

4788

``

`-

return textBefore;

`

``

4792

`+

safe.uboLog(logPrefix, 'Decoded outbound text:\n', textBefore);

`

``

4793

`+

return encodedTextBefore;

`

4789

4794

`}

`

4790

4795

`reCondition.lastIndex = 0;

`

4791

``

`-

if ( reCondition.test(textBefore) === false ) { return textBefore; }

`

``

4796

`+

if ( reCondition.test(textBefore) === false ) { return encodedTextBefore; }

`

4792

4797

`const textAfter = textBefore.replace(rePattern, replacement);

`

4793

``

`-

if ( textAfter === textBefore ) { return textBefore; }

`

``

4798

`+

if ( textAfter === textBefore ) { return encodedTextBefore; }

`

4794

4799

`safe.uboLog(logPrefix, 'Matched and replaced');

`

4795

4800

`if ( safe.logLevel > 1 ) {

`

4796

``

`-

safe.uboLog(logPrefix, 'Modified outbound text:\n', textAfter);

`

``

4801

`+

safe.uboLog(logPrefix, 'Modified decoded outbound text:\n', textAfter);

`

``

4802

`+

}

`

``

4803

`+

let encodedTextAfter = textAfter;

`

``

4804

`+

if ( extraArgs.encoding === 'base64' ) {

`

``

4805

`+

encodedTextAfter = self.btoa(textAfter);

`

4797

4806

`}

`

4798

``

`-

return textAfter;

`

``

4807

`+

return encodedTextAfter;

`

4799

4808

`});

`

4800

4809

`}

`

4801

4810

``