From 13a4f869d273b24ac48ba00e6be127d7893963eb Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Fri, 19 May 2023 15:06:15 -0400 Subject: [PATCH] Fix sticky blocking mode Related issue: - https://github.com/uBlockOrigin/uBOL-issues/issues/42 Take into account that subdomains inherit the blocking mode of their parent domain when toggling blocking mode of specific hostnames. --- platform/mv3/extension/js/mode-manager.js | 24 +++++++++++++++++++---- platform/mv3/make-rulesets.js | 7 +++---- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/platform/mv3/extension/js/mode-manager.js b/platform/mv3/extension/js/mode-manager.js index 8ac0ccfd2..918dba68e 100644 --- a/platform/mv3/extension/js/mode-manager.js +++ b/platform/mv3/extension/js/mode-manager.js @@ -33,6 +33,7 @@ import { import { hostnamesFromMatches, isDescendantHostnameOfIter, + toBroaderHostname, } from './utils.js'; import { @@ -54,6 +55,17 @@ const pruneDescendantHostnamesFromSet = (hostname, hnSet) => { /******************************************************************************/ +const pruneHostnameFromSet = (hostname, hnSet) => { + let hn = hostname; + for (;;) { + hnSet.delete(hn); + hn = toBroaderHostname(hn); + if ( hn === '*' ) { break; } + } +}; + +/******************************************************************************/ + const eqSets = (setBefore, setAfter) => { for ( const hn of setAfter ) { if ( setBefore.has(hn) === false ) { return false; } @@ -203,9 +215,13 @@ async function setFilteringModeDetails(afterDetails) { async function getFilteringMode(hostname) { const filteringModes = await getFilteringModeDetails(); if ( filteringModes.none.has(hostname) ) { return 0; } + if ( isDescendantHostnameOfIter(hostname, filteringModes.none) ) { return 0; } if ( filteringModes.network.has(hostname) ) { return 1; } + if ( isDescendantHostnameOfIter(hostname, filteringModes.network) ) { return 1; } if ( filteringModes.extendedSpecific.has(hostname) ) { return 2; } + if ( isDescendantHostnameOfIter(hostname, filteringModes.extendedSpecific) ) { return 2; } if ( filteringModes.extendedGeneric.has(hostname) ) { return 3; } + if ( isDescendantHostnameOfIter(hostname, filteringModes.extendedGeneric) ) { return 3; } return getDefaultFilteringMode(); } @@ -233,16 +249,16 @@ async function setFilteringMode(hostname, afterLevel) { } = filteringModes; switch ( beforeLevel ) { case 0: - none.delete(hostname); + pruneHostnameFromSet(hostname, none); break; case 1: - network.delete(hostname); + pruneHostnameFromSet(hostname, network); break; case 2: - extendedSpecific.delete(hostname); + pruneHostnameFromSet(hostname, extendedSpecific); break; case 3: - extendedGeneric.delete(hostname); + pruneHostnameFromSet(hostname, extendedGeneric); break; } if ( afterLevel !== defaultLevel ) { diff --git a/platform/mv3/make-rulesets.js b/platform/mv3/make-rulesets.js index 5f632178e..ccc2f1b5c 100644 --- a/platform/mv3/make-rulesets.js +++ b/platform/mv3/make-rulesets.js @@ -1284,11 +1284,10 @@ async function main() { // Assemble all default lists as the default ruleset const contentURLs = [ - 'https://ublockorigin.github.io/uAssets/filters/filters.txt', + 'https://ublockorigin.github.io/uAssets/filters/filters.min.txt', 'https://ublockorigin.github.io/uAssets/filters/badware.txt', - 'https://ublockorigin.github.io/uAssets/filters/privacy.txt', - 'https://ublockorigin.github.io/uAssets/filters/resource-abuse.txt', - 'https://ublockorigin.github.io/uAssets/filters/unbreak.txt', + 'https://ublockorigin.github.io/uAssets/filters/privacy.min.txt', + 'https://ublockorigin.github.io/uAssets/filters/unbreak.min.txt', 'https://ublockorigin.github.io/uAssets/filters/quick-fixes.txt', 'https://ublockorigin.github.io/uAssets/filters/ubol-filters.txt', 'https://ublockorigin.github.io/uAssets/thirdparties/easylist.txt',