[mv3] Fix potentially unremovable custom filters

Related issue:
https://github.com/uBlockOrigin/uBOL-home/issues/426
This commit is contained in:
Raymond Hill 2025-08-10 12:44:42 -04:00
parent 19a3de901c
commit a1a5f3690f
No known key found for this signature in database
GPG key ID: 25E1490B761470C2

View file

@ -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;
}