mirror of
https://github.com/gorhill/uBlock.git
synced 2024-10-04 08:37:11 +02: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
@ -861,14 +861,33 @@ function objectFindOwnerFn(
|
|||||||
return modified;
|
return modified;
|
||||||
}
|
}
|
||||||
const prop = chain.slice(0, pos);
|
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 (
|
if (
|
||||||
prop === '[]' && Array.isArray(owner) ||
|
prop === '[]' && Array.isArray(owner) ||
|
||||||
|
prop === '{}' && owner instanceof Object ||
|
||||||
prop === '*' && owner instanceof Object
|
prop === '*' && owner instanceof Object
|
||||||
) {
|
) {
|
||||||
const next = chain.slice(pos + 1);
|
|
||||||
let found = false;
|
|
||||||
for ( const key of Object.keys(owner) ) {
|
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;
|
return found;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user