mirror of https://github.com/gorhill/uBlock.git
Code review of `trusted-replace-node-text` scriptlet
This commit is contained in:
parent
ec568b614d
commit
bf75dc2f90
|
@ -714,8 +714,12 @@ function replaceNodeTextFn(
|
|||
const reNodeName = safe.patternToRegex(nodeName, 'i', true);
|
||||
const rePattern = safe.patternToRegex(pattern, 'gms');
|
||||
const extraArgs = safe.getExtraArgs(Array.from(arguments), 3);
|
||||
const reIncludes = safe.patternToRegex(extraArgs.includes || extraArgs.condition || '', 'ms');
|
||||
const reExcludes = safe.patternToRegex(extraArgs.excludes || '.^', 'ms');
|
||||
const reIncludes = extraArgs.includes || extraArgs.condition
|
||||
? safe.patternToRegex(extraArgs.includes || extraArgs.condition, 'ms')
|
||||
: null;
|
||||
const reExcludes = extraArgs.excludes
|
||||
? safe.patternToRegex(extraArgs.excludes, 'ms')
|
||||
: null;
|
||||
const stop = (takeRecord = true) => {
|
||||
if ( takeRecord ) {
|
||||
handleMutations(observer.takeRecords());
|
||||
|
@ -728,10 +732,14 @@ function replaceNodeTextFn(
|
|||
let sedCount = extraArgs.sedCount || 0;
|
||||
const handleNode = node => {
|
||||
const before = node.textContent;
|
||||
if ( reIncludes ) {
|
||||
reIncludes.lastIndex = 0;
|
||||
if ( safe.RegExp_test.call(reIncludes, before) === false ) { return true; }
|
||||
}
|
||||
if ( reExcludes ) {
|
||||
reExcludes.lastIndex = 0;
|
||||
if ( safe.RegExp_test.call(reExcludes, before) ) { return true; }
|
||||
}
|
||||
rePattern.lastIndex = 0;
|
||||
if ( safe.RegExp_test.call(rePattern, before) === false ) { return true; }
|
||||
rePattern.lastIndex = 0;
|
||||
|
|
Loading…
Reference in New Issue