mirror of https://github.com/gorhill/uBlock.git
[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) {
|
||||
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(
|
||||
presentRule && presentRule.condition.requestDomains
|
||||
);
|
||||
if ( eqSets(presentNone, modes.none) ) { return; }
|
||||
const removeRuleIds = [];
|
||||
if ( presentRule !== undefined ) {
|
||||
removeRuleIds.push(TRUSTED_DIRECTIVE_BASE_RULE_ID);
|
||||
dynamicRuleMap.delete(TRUSTED_DIRECTIVE_BASE_RULE_ID);
|
||||
removeRuleIds.push(TRUSTED_DIRECTIVE_BASE_RULE_ID+0);
|
||||
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 = [];
|
||||
if ( modes.none.size !== 0 ) {
|
||||
const rule = {
|
||||
id: TRUSTED_DIRECTIVE_BASE_RULE_ID,
|
||||
const noneHostnames = [ ...modes.none ];
|
||||
const notNoneHostnames = [ ...modes.basic, ...modes.optimal, ...modes.complete ];
|
||||
if ( noneHostnames.length !== 0 ) {
|
||||
const rule0 = {
|
||||
id: TRUSTED_DIRECTIVE_BASE_RULE_ID+0,
|
||||
action: { type: 'allowAllRequests' },
|
||||
condition: {
|
||||
resourceTypes: [ 'main_frame' ],
|
||||
},
|
||||
priority: 100,
|
||||
};
|
||||
if (
|
||||
modes.none.size !== 1 ||
|
||||
modes.none.has('all-urls') === false
|
||||
) {
|
||||
rule.condition.requestDomains = Array.from(modes.none);
|
||||
if ( modes.none.has('all-urls') === false ) {
|
||||
rule0.condition.requestDomains = noneHostnames.slice();
|
||||
} else if ( notNoneHostnames.length !== 0 ) {
|
||||
rule0.condition.excludedRequestDomains = notNoneHostnames.slice();
|
||||
}
|
||||
addRules.push(rule);
|
||||
dynamicRuleMap.set(TRUSTED_DIRECTIVE_BASE_RULE_ID, rule);
|
||||
addRules.push(rule0);
|
||||
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 = {};
|
||||
if ( addRules.length ) {
|
||||
|
|
Loading…
Reference in New Issue