mirror of
https://github.com/gorhill/uBlock.git
synced 2024-11-06 02:42:33 +01:00
Improve trusted-replace-node-text
scriptlet
Related discussion: https://github.com/brave/adblock-resources/pull/194
This commit is contained in:
parent
d42329a3a3
commit
4f0d1301ab
@ -730,6 +730,18 @@ function replaceNodeTextFn(
|
||||
safe.uboLog(logPrefix, 'Quitting');
|
||||
}
|
||||
};
|
||||
const textContentFactory = (( ) => {
|
||||
const out = { createScript: s => s };
|
||||
const { trustedTypes: tt } = self;
|
||||
if ( tt instanceof Object ) {
|
||||
if ( typeof tt.getPropertyType === 'function' ) {
|
||||
if ( tt.getPropertyType('script', 'textContent') === 'TrustedScript' ) {
|
||||
return tt.createPolicy('uBO', out);
|
||||
}
|
||||
}
|
||||
}
|
||||
return out;
|
||||
})();
|
||||
let sedCount = extraArgs.sedCount || 0;
|
||||
const handleNode = node => {
|
||||
const before = node.textContent;
|
||||
@ -747,7 +759,9 @@ function replaceNodeTextFn(
|
||||
const after = pattern !== ''
|
||||
? before.replace(rePattern, replacement)
|
||||
: replacement;
|
||||
node.textContent = after;
|
||||
node.textContent = node.nodeName === 'SCRIPT'
|
||||
? textContentFactory.createScript(after)
|
||||
: after;
|
||||
if ( safe.logLevel > 1 ) {
|
||||
safe.uboLog(logPrefix, `Text before:\n${before.trim()}`);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user