mirror of
https://github.com/gorhill/uBlock.git
synced 2026-03-11 09:04:36 +00:00
[mv3] Fix potentially unremovable custom filters
Related issue: https://github.com/uBlockOrigin/uBOL-home/issues/426
This commit is contained in:
parent
19a3de901c
commit
a1a5f3690f
1 changed files with 20 additions and 4 deletions
|
|
@ -178,14 +178,30 @@ export async function addCustomFilter(hostname, selector) {
|
|||
/******************************************************************************/
|
||||
|
||||
export async function removeCustomFilter(hostname, selector) {
|
||||
const key = `site.${hostname}`;
|
||||
const promises = [];
|
||||
let hn = hostname;
|
||||
while ( hn !== '' ) {
|
||||
promises.push(
|
||||
removeCustomFilterByKey(`site.${hn}`, selector).catch(( ) => false)
|
||||
);
|
||||
const pos = hn.indexOf('.');
|
||||
if ( pos === -1 ) { break; }
|
||||
hn = hn.slice(pos + 1);
|
||||
}
|
||||
const results = await Promise.all(promises);
|
||||
return results.some(a => a);
|
||||
}
|
||||
|
||||
async function removeCustomFilterByKey(key, selector) {
|
||||
const selectors = await localRead(key);
|
||||
if ( selectors === undefined ) { return false; }
|
||||
const i = selectors.indexOf(selector);
|
||||
if ( i === -1 ) { return false; }
|
||||
selectors.splice(i, 1);
|
||||
await selectors.length !== 0
|
||||
? localWrite(key, selectors)
|
||||
: localRemove(key);
|
||||
if ( selectors.length !== 0 ) {
|
||||
await localWrite(key, selectors);
|
||||
} else {
|
||||
await localRemove(key);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue