mirror of
https://github.com/gorhill/uBlock.git
synced 2024-11-07 03:12:33 +01:00
move branch toggling into switches manager
This commit is contained in:
parent
ddb8fc9cf6
commit
c6668391e0
@ -73,7 +73,7 @@ var proceedPermanent = function() {
|
|||||||
what: 'toggleHostnameSwitch',
|
what: 'toggleHostnameSwitch',
|
||||||
name: 'noStrictBlocking',
|
name: 'noStrictBlocking',
|
||||||
hostname: getTargetHostname(),
|
hostname: getTargetHostname(),
|
||||||
fromHostname: details.hn,
|
deep: true,
|
||||||
state: true
|
state: true
|
||||||
}, proceedToURL);
|
}, proceedToURL);
|
||||||
};
|
};
|
||||||
|
@ -126,7 +126,7 @@ HnSwitches.prototype.toggle = function(switchName, hostname, newVal) {
|
|||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
HnSwitches.prototype.toggleZ = function(switchName, hostname, newState) {
|
HnSwitches.prototype.toggleOneZ = function(switchName, hostname, newState) {
|
||||||
var bitOffset = switchBitOffsets[switchName];
|
var bitOffset = switchBitOffsets[switchName];
|
||||||
if ( bitOffset === undefined ) {
|
if ( bitOffset === undefined ) {
|
||||||
return false;
|
return false;
|
||||||
@ -155,6 +155,47 @@ HnSwitches.prototype.toggleZ = function(switchName, hostname, newState) {
|
|||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
|
HnSwitches.prototype.toggleBranchZ = function(switchName, targetHostname, newState) {
|
||||||
|
var changed = this.toggleOneZ(switchName, targetHostname, newState);
|
||||||
|
|
||||||
|
var targetLen = targetHostname.length;
|
||||||
|
var hostnames = [];
|
||||||
|
|
||||||
|
for ( var hostname in this.switches ) {
|
||||||
|
if ( this.switches.hasOwnProperty(hostname) === false ) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if ( hostname === targetHostname ) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if ( hostname.length <= targetLen ) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if ( hostname.slice(-targetLen) !== targetHostname ) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if ( hostname.charAt(hostname.length - targetLen - 1) !== '.' ) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
hostnames.push(hostname);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Decreasing length order so that all switch states are inherited from
|
||||||
|
// targetHostname.
|
||||||
|
hostnames.sort(function(a, b) {
|
||||||
|
return b.length - a.length;
|
||||||
|
});
|
||||||
|
|
||||||
|
var i = hostnames.length;
|
||||||
|
while ( i-- ) {
|
||||||
|
changed = this.toggleOneZ(switchName, hostnames[i], newState) || changed;
|
||||||
|
}
|
||||||
|
|
||||||
|
return changed;
|
||||||
|
};
|
||||||
|
|
||||||
|
/******************************************************************************/
|
||||||
|
|
||||||
// 0 = inherit from broader scope, up to default state
|
// 0 = inherit from broader scope, up to default state
|
||||||
// 1 = non-default state
|
// 1 = non-default state
|
||||||
// 2 = forced default state (to override a broader non-default state)
|
// 2 = forced default state (to override a broader non-default state)
|
||||||
|
@ -319,29 +319,12 @@ var matchWhitelistDirective = function(url, hostname, directive) {
|
|||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
µBlock.toggleHostnameSwitch = function(details) {
|
µBlock.toggleHostnameSwitch = function(details) {
|
||||||
var hostname = details.hostname;
|
|
||||||
var fromHostname = details.fromHostname || hostname;
|
|
||||||
var changed = false;
|
var changed = false;
|
||||||
|
|
||||||
var fromHostnames = [];
|
if ( details.deep === true ) {
|
||||||
var pos;
|
changed = this.hnSwitches.toggleBranchZ(details.name, details.hostname, details.state);
|
||||||
for (;;) {
|
} else {
|
||||||
fromHostnames.push(fromHostname);
|
changed = this.hnSwitches.toggleOneZ(details.name, details.hostname, details.state);
|
||||||
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 ) {
|
if ( changed ) {
|
||||||
|
Loading…
Reference in New Issue
Block a user