mirror of
https://github.com/gorhill/uBlock.git
synced 2024-11-10 01:02:08 +01:00
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:
parent
0cc8b7864f
commit
9562b19a93
1 changed files with 19 additions and 18 deletions
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue