to support toggling a "branch" of switches

This commit is contained in:
gorhill 2015-04-07 12:35:19 -04:00
parent f067a95e01
commit ddb8fc9cf6
2 changed files with 27 additions and 1 deletions

View File

@ -73,6 +73,7 @@ var proceedPermanent = function() {
what: 'toggleHostnameSwitch', what: 'toggleHostnameSwitch',
name: 'noStrictBlocking', name: 'noStrictBlocking',
hostname: getTargetHostname(), hostname: getTargetHostname(),
fromHostname: details.hn,
state: true state: true
}, proceedToURL); }, proceedToURL);
}; };

View File

@ -319,7 +319,32 @@ var matchWhitelistDirective = function(url, hostname, directive) {
/******************************************************************************/ /******************************************************************************/
µBlock.toggleHostnameSwitch = function(details) { µBlock.toggleHostnameSwitch = function(details) {
if ( this.hnSwitches.toggleZ(details.name, details.hostname, details.state) ) { var hostname = details.hostname;
var fromHostname = details.fromHostname || hostname;
var changed = false;
var fromHostnames = [];
var pos;
for (;;) {
fromHostnames.push(fromHostname);
if ( fromHostname === hostname ) {
break;
}
pos = fromHostname.indexOf('.');
if ( pos === -1 ) {
break;
}
fromHostname = fromHostname.slice(pos + 1);
}
var i = fromHostnames.length;
while ( i-- ) {
if ( this.hnSwitches.toggleZ(details.name, fromHostnames[i], details.state) ) {
changed = true;
}
}
if ( changed ) {
this.saveHostnameSwitches(); this.saveHostnameSwitches();
} }