mirror of https://github.com/gorhill/uBlock.git
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.
This commit is contained in:
parent
95396d8dbf
commit
13a4f869d2
|
@ -33,6 +33,7 @@ import {
|
||||||
import {
|
import {
|
||||||
hostnamesFromMatches,
|
hostnamesFromMatches,
|
||||||
isDescendantHostnameOfIter,
|
isDescendantHostnameOfIter,
|
||||||
|
toBroaderHostname,
|
||||||
} from './utils.js';
|
} from './utils.js';
|
||||||
|
|
||||||
import {
|
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) => {
|
const eqSets = (setBefore, setAfter) => {
|
||||||
for ( const hn of setAfter ) {
|
for ( const hn of setAfter ) {
|
||||||
if ( setBefore.has(hn) === false ) { return false; }
|
if ( setBefore.has(hn) === false ) { return false; }
|
||||||
|
@ -203,9 +215,13 @@ async function setFilteringModeDetails(afterDetails) {
|
||||||
async function getFilteringMode(hostname) {
|
async function getFilteringMode(hostname) {
|
||||||
const filteringModes = await getFilteringModeDetails();
|
const filteringModes = await getFilteringModeDetails();
|
||||||
if ( filteringModes.none.has(hostname) ) { return 0; }
|
if ( filteringModes.none.has(hostname) ) { return 0; }
|
||||||
|
if ( isDescendantHostnameOfIter(hostname, filteringModes.none) ) { return 0; }
|
||||||
if ( filteringModes.network.has(hostname) ) { return 1; }
|
if ( filteringModes.network.has(hostname) ) { return 1; }
|
||||||
|
if ( isDescendantHostnameOfIter(hostname, filteringModes.network) ) { return 1; }
|
||||||
if ( filteringModes.extendedSpecific.has(hostname) ) { return 2; }
|
if ( filteringModes.extendedSpecific.has(hostname) ) { return 2; }
|
||||||
|
if ( isDescendantHostnameOfIter(hostname, filteringModes.extendedSpecific) ) { return 2; }
|
||||||
if ( filteringModes.extendedGeneric.has(hostname) ) { return 3; }
|
if ( filteringModes.extendedGeneric.has(hostname) ) { return 3; }
|
||||||
|
if ( isDescendantHostnameOfIter(hostname, filteringModes.extendedGeneric) ) { return 3; }
|
||||||
return getDefaultFilteringMode();
|
return getDefaultFilteringMode();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -233,16 +249,16 @@ async function setFilteringMode(hostname, afterLevel) {
|
||||||
} = filteringModes;
|
} = filteringModes;
|
||||||
switch ( beforeLevel ) {
|
switch ( beforeLevel ) {
|
||||||
case 0:
|
case 0:
|
||||||
none.delete(hostname);
|
pruneHostnameFromSet(hostname, none);
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
network.delete(hostname);
|
pruneHostnameFromSet(hostname, network);
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
extendedSpecific.delete(hostname);
|
pruneHostnameFromSet(hostname, extendedSpecific);
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
extendedGeneric.delete(hostname);
|
pruneHostnameFromSet(hostname, extendedGeneric);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if ( afterLevel !== defaultLevel ) {
|
if ( afterLevel !== defaultLevel ) {
|
||||||
|
|
|
@ -1284,11 +1284,10 @@ async function main() {
|
||||||
|
|
||||||
// Assemble all default lists as the default ruleset
|
// Assemble all default lists as the default ruleset
|
||||||
const contentURLs = [
|
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/badware.txt',
|
||||||
'https://ublockorigin.github.io/uAssets/filters/privacy.txt',
|
'https://ublockorigin.github.io/uAssets/filters/privacy.min.txt',
|
||||||
'https://ublockorigin.github.io/uAssets/filters/resource-abuse.txt',
|
'https://ublockorigin.github.io/uAssets/filters/unbreak.min.txt',
|
||||||
'https://ublockorigin.github.io/uAssets/filters/unbreak.txt',
|
|
||||||
'https://ublockorigin.github.io/uAssets/filters/quick-fixes.txt',
|
'https://ublockorigin.github.io/uAssets/filters/quick-fixes.txt',
|
||||||
'https://ublockorigin.github.io/uAssets/filters/ubol-filters.txt',
|
'https://ublockorigin.github.io/uAssets/filters/ubol-filters.txt',
|
||||||
'https://ublockorigin.github.io/uAssets/thirdparties/easylist.txt',
|
'https://ublockorigin.github.io/uAssets/thirdparties/easylist.txt',
|
||||||
|
|
Loading…
Reference in New Issue