Fall back to "Basic" when removing all-urls from "No filtering"

Related discussion:
https://github.com/uBlockOrigin/uBOL-home/issues/156#issuecomment-2254576670
This commit is contained in:
Raymond Hill 2024-08-01 11:24:42 -04:00
parent 0cc8b7864f
commit 9562b19a93
No known key found for this signature in database
GPG key ID: 25E1490B761470C2

View file

@ -19,18 +19,17 @@
Home: https://github.com/gorhill/uBlock
*/
/* jshint esversion:11 */
'use strict';
/******************************************************************************/
import {
TRUSTED_DIRECTIVE_BASE_RULE_ID,
getDynamicRules,
} from './ruleset-manager.js';
import {
adminRead,
browser,
dnr,
localRead, localWrite, localRemove,
localRead, localRemove, localWrite,
sessionRead, sessionWrite,
adminRead,
} from './ext.js';
import {
@ -40,11 +39,6 @@ import {
toBroaderHostname,
} from './utils.js';
import {
TRUSTED_DIRECTIVE_BASE_RULE_ID,
getDynamicRules
} from './ruleset-manager.js';
/******************************************************************************/
// 0: no filtering
@ -288,13 +282,15 @@ async function writeFilteringModeDetails(afterDetails) {
async function filteringModesToDNR(modes) {
const dynamicRuleMap = await getDynamicRules();
const presentRule = dynamicRuleMap.get(TRUSTED_DIRECTIVE_BASE_RULE_ID+0);
const presentNone = new Set(
presentRule && presentRule.condition.requestDomains
);
if ( eqSets(presentNone, modes.none) ) { return; }
const trustedRule = dynamicRuleMap.get(TRUSTED_DIRECTIVE_BASE_RULE_ID+0);
const trustedDomainSet = new Set(trustedRule?.condition.requestDomains);
if ( trustedDomainSet.size !== 0 ) {
if ( eqSets(trustedDomainSet, modes.none) ) { return; }
} else if ( trustedRule !== undefined ) {
if ( modes.none.has('all-urls') ) { return; }
}
const removeRuleIds = [];
if ( presentRule !== undefined ) {
if ( trustedRule !== undefined ) {
removeRuleIds.push(TRUSTED_DIRECTIVE_BASE_RULE_ID+0);
removeRuleIds.push(TRUSTED_DIRECTIVE_BASE_RULE_ID+1);
dynamicRuleMap.delete(TRUSTED_DIRECTIVE_BASE_RULE_ID+0);
@ -394,6 +390,11 @@ export async function setTrustedSites(hostnames) {
const { none } = filteringModes;
const hnSet = new Set(hostnames);
let modified = false;
// Set default mode to Basic when removing No-filtering as default mode
if ( none.has('all-urls') && hnSet.has('all-urls') === false ) {
applyFilteringMode(filteringModes, 'all-urls', MODE_BASIC);
modified = true;
}
for ( const hn of none ) {
if ( hnSet.has(hn) ) {
hnSet.delete(hn);