Skip to content

Commit

Permalink
Fix sticky blocking mode
Browse files Browse the repository at this point in the history
Related issue:
- uBlockOrigin/uBOL-home#42

Take into account that subdomains inherit the blocking mode
of their parent domain when toggling blocking mode of specific
hostnames.
  • Loading branch information
gorhill committed May 19, 2023
1 parent 95396d8 commit 13a4f86
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
24 changes: 20 additions & 4 deletions platform/mv3/extension/js/mode-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import {
import {
hostnamesFromMatches,
isDescendantHostnameOfIter,
toBroaderHostname,
} from './utils.js';

import {
Expand All @@ -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; }
Expand Down Expand Up @@ -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();
}

Expand Down Expand Up @@ -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 ) {
Expand Down
7 changes: 3 additions & 4 deletions platform/mv3/make-rulesets.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit 13a4f86

Please sign in to comment.