1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-09-18 17:02:27 +02:00

whitelisting must have precedence over strict blocking

This commit is contained in:
gorhill 2015-04-09 12:20:24 -04:00
parent f70224bb57
commit d01a73e636
2 changed files with 20 additions and 22 deletions

View File

@ -51,13 +51,15 @@ var fromLegacySwitchNames = {
}; };
var switchStateToNameMap = { var switchStateToNameMap = {
'1': 'true', '1': 'on',
'2': 'false' '2': 'off'
}; };
var nameToSwitchStateMap = { var nameToSwitchStateMap = {
'true': 1, 'true': 1,
'false': 2 'false': 2,
'on': 1,
'off': 2
}; };
/******************************************************************************/ /******************************************************************************/
@ -160,10 +162,10 @@ HnSwitches.prototype.toggleOneZ = function(switchName, hostname, newState) {
HnSwitches.prototype.toggleBranchZ = function(switchName, targetHostname, newState) { HnSwitches.prototype.toggleBranchZ = function(switchName, targetHostname, newState) {
var changed = this.toggleOneZ(switchName, targetHostname, newState); var changed = this.toggleOneZ(switchName, targetHostname, newState);
var targetLen = targetHostname.length; var targetLen = targetHostname.length;
var hostnames = [];
// Turn off all descendant switches, they will inherit the state of the
// branch's origin.
for ( var hostname in this.switches ) { for ( var hostname in this.switches ) {
if ( this.switches.hasOwnProperty(hostname) === false ) { if ( this.switches.hasOwnProperty(hostname) === false ) {
continue; continue;
@ -180,18 +182,7 @@ HnSwitches.prototype.toggleBranchZ = function(switchName, targetHostname, newSta
if ( hostname.charAt(hostname.length - targetLen - 1) !== '.' ) { if ( hostname.charAt(hostname.length - targetLen - 1) !== '.' ) {
continue; continue;
} }
hostnames.push(hostname); changed = this.toggle(switchName, hostname, 0) || changed;
}
// 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; return changed;

View File

@ -153,19 +153,26 @@ var onBeforeRootFrameRequest = function(details) {
var result = ''; var result = '';
// If the site is whitelisted, disregard strict blocking
if ( µb.getNetFilteringSwitch(requestURL) === false ) {
result = 'ua:whitelisted';
}
// Permanently unrestricted? // Permanently unrestricted?
if ( result === '' && µb.hnSwitches.evaluateZ('no-strict-blocking', requestHostname) ) { if ( result === '' && µb.hnSwitches.evaluateZ('no-strict-blocking', requestHostname) ) {
result = 'ua:no-strict-blocking true'; result = 'ua:no-strict-blocking on';
} }
// Temporarily whitelisted? // Temporarily whitelisted?
result = isTemporarilyWhitelisted(result, requestHostname); if ( result === '' ) {
if ( result.charAt(1) === 'a' ) { result = isTemporarilyWhitelisted(result, requestHostname);
return; if ( result.charAt(1) === 'a' ) {
result = 'ua:no-strict-blocking on(temporary)';
}
} }
// Filtering // Filtering
if ( result === '' && µb.getNetFilteringSwitch(requestURL) ) { if ( result === '' ) {
result = µb.staticNetFilteringEngine.matchString(context); result = µb.staticNetFilteringEngine.matchString(context);
// https://github.com/chrisaljoudi/uBlock/issues/1128 // https://github.com/chrisaljoudi/uBlock/issues/1128
// Do not block if the match begins after the hostname. // Do not block if the match begins after the hostname.