mirror of
https://github.com/gorhill/uBlock.git
synced 2026-03-11 09:04:36 +00:00
Improve json-prune-related scriptlets
New special properties:
- `[-]`: remove an array entry if part right of `[-]` matches the
inspected item.
- `{-}`: remove a property if part right of `{-}` mmatches the
inspected item.
This is useful to remove entries which have unspecified names.
This commit is contained in:
parent
664dd95700
commit
e7a0f8c781
1 changed files with 22 additions and 3 deletions
|
|
@ -861,14 +861,33 @@ function objectFindOwnerFn(
|
|||
return modified;
|
||||
}
|
||||
const prop = chain.slice(0, pos);
|
||||
const next = chain.slice(pos + 1);
|
||||
let found = false;
|
||||
if ( prop === '[-]' && Array.isArray(owner) ) {
|
||||
let i = owner.length;
|
||||
while ( i-- ) {
|
||||
if ( objectFindOwnerFn(owner[i], next) === false ) { continue; }
|
||||
owner.splice(i, 1);
|
||||
found = true;
|
||||
}
|
||||
return found;
|
||||
}
|
||||
if ( prop === '{-}' && owner instanceof Object ) {
|
||||
for ( const key of Object.keys(owner) ) {
|
||||
if ( objectFindOwnerFn(owner[key], next) === false ) { continue; }
|
||||
delete owner[key];
|
||||
found = true;
|
||||
}
|
||||
return found;
|
||||
}
|
||||
if (
|
||||
prop === '[]' && Array.isArray(owner) ||
|
||||
prop === '{}' && owner instanceof Object ||
|
||||
prop === '*' && owner instanceof Object
|
||||
) {
|
||||
const next = chain.slice(pos + 1);
|
||||
let found = false;
|
||||
for ( const key of Object.keys(owner) ) {
|
||||
found = objectFindOwnerFn(owner[key], next, prune) || found;
|
||||
if (objectFindOwnerFn(owner[key], next, prune) === false ) { continue; }
|
||||
found = true;
|
||||
}
|
||||
return found;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue