Skip to content

Commit 13a4f86

Browse files
committed
Fix sticky blocking mode
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.
1 parent 95396d8 commit 13a4f86

File tree

2 files changed

+23
-8
lines changed

2 files changed

+23
-8
lines changed

platform/mv3/extension/js/mode-manager.js

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import {
3333
import {
3434
hostnamesFromMatches,
3535
isDescendantHostnameOfIter,
36+
toBroaderHostname,
3637
} from './utils.js';
3738

3839
import {
@@ -54,6 +55,17 @@ const pruneDescendantHostnamesFromSet = (hostname, hnSet) => {
5455

5556
/******************************************************************************/
5657

58+
const pruneHostnameFromSet = (hostname, hnSet) => {
59+
let hn = hostname;
60+
for (;;) {
61+
hnSet.delete(hn);
62+
hn = toBroaderHostname(hn);
63+
if ( hn === '*' ) { break; }
64+
}
65+
};
66+
67+
/******************************************************************************/
68+
5769
const eqSets = (setBefore, setAfter) => {
5870
for ( const hn of setAfter ) {
5971
if ( setBefore.has(hn) === false ) { return false; }
@@ -203,9 +215,13 @@ async function setFilteringModeDetails(afterDetails) {
203215
async function getFilteringMode(hostname) {
204216
const filteringModes = await getFilteringModeDetails();
205217
if ( filteringModes.none.has(hostname) ) { return 0; }
218+
if ( isDescendantHostnameOfIter(hostname, filteringModes.none) ) { return 0; }
206219
if ( filteringModes.network.has(hostname) ) { return 1; }
220+
if ( isDescendantHostnameOfIter(hostname, filteringModes.network) ) { return 1; }
207221
if ( filteringModes.extendedSpecific.has(hostname) ) { return 2; }
222+
if ( isDescendantHostnameOfIter(hostname, filteringModes.extendedSpecific) ) { return 2; }
208223
if ( filteringModes.extendedGeneric.has(hostname) ) { return 3; }
224+
if ( isDescendantHostnameOfIter(hostname, filteringModes.extendedGeneric) ) { return 3; }
209225
return getDefaultFilteringMode();
210226
}
211227

@@ -233,16 +249,16 @@ async function setFilteringMode(hostname, afterLevel) {
233249
} = filteringModes;
234250
switch ( beforeLevel ) {
235251
case 0:
236-
none.delete(hostname);
252+
pruneHostnameFromSet(hostname, none);
237253
break;
238254
case 1:
239-
network.delete(hostname);
255+
pruneHostnameFromSet(hostname, network);
240256
break;
241257
case 2:
242-
extendedSpecific.delete(hostname);
258+
pruneHostnameFromSet(hostname, extendedSpecific);
243259
break;
244260
case 3:
245-
extendedGeneric.delete(hostname);
261+
pruneHostnameFromSet(hostname, extendedGeneric);
246262
break;
247263
}
248264
if ( afterLevel !== defaultLevel ) {

platform/mv3/make-rulesets.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1284,11 +1284,10 @@ async function main() {
12841284

12851285
// Assemble all default lists as the default ruleset
12861286
const contentURLs = [
1287-
'https://ublockorigin.github.io/uAssets/filters/filters.txt',
1287+
'https://ublockorigin.github.io/uAssets/filters/filters.min.txt',
12881288
'https://ublockorigin.github.io/uAssets/filters/badware.txt',
1289-
'https://ublockorigin.github.io/uAssets/filters/privacy.txt',
1290-
'https://ublockorigin.github.io/uAssets/filters/resource-abuse.txt',
1291-
'https://ublockorigin.github.io/uAssets/filters/unbreak.txt',
1289+
'https://ublockorigin.github.io/uAssets/filters/privacy.min.txt',
1290+
'https://ublockorigin.github.io/uAssets/filters/unbreak.min.txt',
12921291
'https://ublockorigin.github.io/uAssets/filters/quick-fixes.txt',
12931292
'https://ublockorigin.github.io/uAssets/filters/ubol-filters.txt',
12941293
'https://ublockorigin.github.io/uAssets/thirdparties/easylist.txt',

0 commit comments

Comments
 (0)