mirror of
https://github.com/gorhill/uBlock.git
synced 2024-10-06 09:37:12 +02:00
[mv3] Mind service workers for sites in "no filtering" mode
Related issue: https://github.com/uBlockOrigin/uBOL-home/issues/114
This commit is contained in:
parent
ad88ff213b
commit
0e8ff10e92
@ -288,34 +288,53 @@ async function writeFilteringModeDetails(afterDetails) {
|
|||||||
|
|
||||||
async function filteringModesToDNR(modes) {
|
async function filteringModesToDNR(modes) {
|
||||||
const dynamicRuleMap = await getDynamicRules();
|
const dynamicRuleMap = await getDynamicRules();
|
||||||
const presentRule = dynamicRuleMap.get(TRUSTED_DIRECTIVE_BASE_RULE_ID);
|
const presentRule = dynamicRuleMap.get(TRUSTED_DIRECTIVE_BASE_RULE_ID+0);
|
||||||
const presentNone = new Set(
|
const presentNone = new Set(
|
||||||
presentRule && presentRule.condition.requestDomains
|
presentRule && presentRule.condition.requestDomains
|
||||||
);
|
);
|
||||||
if ( eqSets(presentNone, modes.none) ) { return; }
|
if ( eqSets(presentNone, modes.none) ) { return; }
|
||||||
const removeRuleIds = [];
|
const removeRuleIds = [];
|
||||||
if ( presentRule !== undefined ) {
|
if ( presentRule !== undefined ) {
|
||||||
removeRuleIds.push(TRUSTED_DIRECTIVE_BASE_RULE_ID);
|
removeRuleIds.push(TRUSTED_DIRECTIVE_BASE_RULE_ID+0);
|
||||||
dynamicRuleMap.delete(TRUSTED_DIRECTIVE_BASE_RULE_ID);
|
removeRuleIds.push(TRUSTED_DIRECTIVE_BASE_RULE_ID+1);
|
||||||
|
dynamicRuleMap.delete(TRUSTED_DIRECTIVE_BASE_RULE_ID+0);
|
||||||
|
dynamicRuleMap.delete(TRUSTED_DIRECTIVE_BASE_RULE_ID+1);
|
||||||
}
|
}
|
||||||
const addRules = [];
|
const addRules = [];
|
||||||
if ( modes.none.size !== 0 ) {
|
const noneHostnames = [ ...modes.none ];
|
||||||
const rule = {
|
const notNoneHostnames = [ ...modes.basic, ...modes.optimal, ...modes.complete ];
|
||||||
id: TRUSTED_DIRECTIVE_BASE_RULE_ID,
|
if ( noneHostnames.length !== 0 ) {
|
||||||
|
const rule0 = {
|
||||||
|
id: TRUSTED_DIRECTIVE_BASE_RULE_ID+0,
|
||||||
action: { type: 'allowAllRequests' },
|
action: { type: 'allowAllRequests' },
|
||||||
condition: {
|
condition: {
|
||||||
resourceTypes: [ 'main_frame' ],
|
resourceTypes: [ 'main_frame' ],
|
||||||
},
|
},
|
||||||
priority: 100,
|
priority: 100,
|
||||||
};
|
};
|
||||||
if (
|
if ( modes.none.has('all-urls') === false ) {
|
||||||
modes.none.size !== 1 ||
|
rule0.condition.requestDomains = noneHostnames.slice();
|
||||||
modes.none.has('all-urls') === false
|
} else if ( notNoneHostnames.length !== 0 ) {
|
||||||
) {
|
rule0.condition.excludedRequestDomains = notNoneHostnames.slice();
|
||||||
rule.condition.requestDomains = Array.from(modes.none);
|
|
||||||
}
|
}
|
||||||
addRules.push(rule);
|
addRules.push(rule0);
|
||||||
dynamicRuleMap.set(TRUSTED_DIRECTIVE_BASE_RULE_ID, rule);
|
dynamicRuleMap.set(TRUSTED_DIRECTIVE_BASE_RULE_ID+0, rule0);
|
||||||
|
// https://github.com/uBlockOrigin/uBOL-home/issues/114
|
||||||
|
const rule1 = {
|
||||||
|
id: TRUSTED_DIRECTIVE_BASE_RULE_ID+1,
|
||||||
|
action: { type: 'allow' },
|
||||||
|
condition: {
|
||||||
|
resourceTypes: [ 'script' ],
|
||||||
|
},
|
||||||
|
priority: 100,
|
||||||
|
};
|
||||||
|
if ( modes.none.has('all-urls') === false ) {
|
||||||
|
rule1.condition.initiatorDomains = noneHostnames.slice();
|
||||||
|
} else if ( notNoneHostnames.length !== 0 ) {
|
||||||
|
rule1.condition.excludedInitiatorDomains = notNoneHostnames.slice();
|
||||||
|
}
|
||||||
|
addRules.push(rule1);
|
||||||
|
dynamicRuleMap.set(TRUSTED_DIRECTIVE_BASE_RULE_ID+1, rule1);
|
||||||
}
|
}
|
||||||
const updateOptions = {};
|
const updateOptions = {};
|
||||||
if ( addRules.length ) {
|
if ( addRules.length ) {
|
||||||
|
Loading…
Reference in New Issue
Block a user