mirror of https://github.com/gorhill/uBlock.git
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');
|
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;
|
let sedCount = extraArgs.sedCount || 0;
|
||||||
const handleNode = node => {
|
const handleNode = node => {
|
||||||
const before = node.textContent;
|
const before = node.textContent;
|
||||||
|
@ -747,7 +759,9 @@ function replaceNodeTextFn(
|
||||||
const after = pattern !== ''
|
const after = pattern !== ''
|
||||||
? before.replace(rePattern, replacement)
|
? before.replace(rePattern, replacement)
|
||||||
: replacement;
|
: replacement;
|
||||||
node.textContent = after;
|
node.textContent = node.nodeName === 'SCRIPT'
|
||||||
|
? textContentFactory.createScript(after)
|
||||||
|
: after;
|
||||||
if ( safe.logLevel > 1 ) {
|
if ( safe.logLevel > 1 ) {
|
||||||
safe.uboLog(logPrefix, `Text before:\n${before.trim()}`);
|
safe.uboLog(logPrefix, `Text before:\n${before.trim()}`);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue