mirror of
https://github.com/gorhill/uBlock.git
synced 2024-11-11 17:41:03 +01:00
fix #2103
This commit is contained in:
parent
4d0eaf3b3c
commit
d62059ccc7
2 changed files with 47 additions and 27 deletions
|
@ -316,7 +316,7 @@ PageStore.prototype.init = function(tabId) {
|
||||||
this.internalRedirectionCount = 0;
|
this.internalRedirectionCount = 0;
|
||||||
|
|
||||||
this.noCosmeticFiltering = µb.hnSwitches.evaluateZ('no-cosmetic-filtering', tabContext.rootHostname) === true;
|
this.noCosmeticFiltering = µb.hnSwitches.evaluateZ('no-cosmetic-filtering', tabContext.rootHostname) === true;
|
||||||
if ( µb.logger.isEnabled() && this.noCosmeticFiltering ) {
|
if ( this.noCosmeticFiltering && µb.logger.isEnabled() ) {
|
||||||
µb.logger.writeOne(
|
µb.logger.writeOne(
|
||||||
tabId,
|
tabId,
|
||||||
'cosmetic',
|
'cosmetic',
|
||||||
|
@ -331,12 +331,13 @@ PageStore.prototype.init = function(tabId) {
|
||||||
// Support `generichide` filter option.
|
// Support `generichide` filter option.
|
||||||
this.noGenericCosmeticFiltering = this.noCosmeticFiltering;
|
this.noGenericCosmeticFiltering = this.noCosmeticFiltering;
|
||||||
if ( this.noGenericCosmeticFiltering !== true ) {
|
if ( this.noGenericCosmeticFiltering !== true ) {
|
||||||
this.noGenericCosmeticFiltering = µb.staticNetFilteringEngine.matchStringExactType(
|
var result = µb.staticNetFilteringEngine.matchStringExactType(
|
||||||
this.createContextFromPage(),
|
this.createContextFromPage(),
|
||||||
tabContext.normalURL,
|
tabContext.normalURL,
|
||||||
'generichide'
|
'generichide'
|
||||||
) === false;
|
);
|
||||||
if ( µb.logger.isEnabled() && this.noGenericCosmeticFiltering ) {
|
this.noGenericCosmeticFiltering = result === false;
|
||||||
|
if ( result !== undefined && µb.logger.isEnabled() ) {
|
||||||
µb.logger.writeOne(
|
µb.logger.writeOne(
|
||||||
tabId,
|
tabId,
|
||||||
'net',
|
'net',
|
||||||
|
|
|
@ -106,6 +106,9 @@ var AllowAnyTypeAnyParty = AllowAction | AnyType | AnyParty;
|
||||||
var AllowAnyType = AllowAction | AnyType;
|
var AllowAnyType = AllowAction | AnyType;
|
||||||
var AllowAnyParty = AllowAction | AnyParty;
|
var AllowAnyParty = AllowAction | AnyParty;
|
||||||
|
|
||||||
|
var genericHideException = AllowAction | AnyParty | typeNameToTypeValue.generichide,
|
||||||
|
genericHideImportant = BlockAction | AnyParty | typeNameToTypeValue.generichide | Important;
|
||||||
|
|
||||||
// ABP filters: https://adblockplus.org/en/filters
|
// ABP filters: https://adblockplus.org/en/filters
|
||||||
// regex tester: http://regex101.com/
|
// regex tester: http://regex101.com/
|
||||||
|
|
||||||
|
@ -1262,7 +1265,7 @@ FilterParser.prototype.parseOptions = function(s) {
|
||||||
// `generichide` concept already supported, just a matter of
|
// `generichide` concept already supported, just a matter of
|
||||||
// adding support for the new keyword.
|
// adding support for the new keyword.
|
||||||
if ( opt === 'elemhide' || opt === 'generichide' ) {
|
if ( opt === 'elemhide' || opt === 'generichide' ) {
|
||||||
if ( this.action === AllowAction ) {
|
if ( not === false ) {
|
||||||
this.parseOptType('generichide', false);
|
this.parseOptType('generichide', false);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -2188,11 +2191,43 @@ FilterContainer.prototype.matchTokens = function(bucket, url) {
|
||||||
|
|
||||||
// Specialized handlers
|
// Specialized handlers
|
||||||
|
|
||||||
|
// https://github.com/gorhill/uBlock/issues/1477
|
||||||
|
// Special case: blocking-generichide filter ALWAYS exists, it is implicit --
|
||||||
|
// thus we always first check for exception filters, then for important block
|
||||||
|
// filter if and only if there was a hit on an exception filter.
|
||||||
|
// https://github.com/gorhill/uBlock/issues/2103
|
||||||
|
// User may want to override `generichide` exception filters.
|
||||||
|
|
||||||
|
FilterContainer.prototype.matchStringGenericHide = function(context, requestURL) {
|
||||||
|
var url = this.urlTokenizer.setURL(requestURL);
|
||||||
|
|
||||||
|
var bucket = this.categories.get(toHex(genericHideException));
|
||||||
|
if ( !bucket || this.matchTokens(bucket, url) === false ) {
|
||||||
|
this.fRegister = null;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
bucket = this.categories.get(toHex(genericHideImportant));
|
||||||
|
if ( bucket && this.matchTokens(bucket, url) ) {
|
||||||
|
this.keyRegister = genericHideImportant;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.keyRegister = genericHideException;
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
|
||||||
|
/******************************************************************************/
|
||||||
|
|
||||||
// https://github.com/chrisaljoudi/uBlock/issues/116
|
// https://github.com/chrisaljoudi/uBlock/issues/116
|
||||||
// Some type of requests are exceptional, they need custom handling,
|
// Some type of requests are exceptional, they need custom handling,
|
||||||
// not the generic handling.
|
// not the generic handling.
|
||||||
|
|
||||||
FilterContainer.prototype.matchStringExactType = function(context, requestURL, requestType) {
|
FilterContainer.prototype.matchStringExactType = function(context, requestURL, requestType) {
|
||||||
|
// Special case.
|
||||||
|
if ( requestType === 'generichide' ) {
|
||||||
|
return this.matchStringGenericHide(context, requestURL);
|
||||||
|
}
|
||||||
// Be prepared to support unknown types
|
// Be prepared to support unknown types
|
||||||
var type = typeNameToTypeValue[requestType];
|
var type = typeNameToTypeValue[requestType];
|
||||||
if ( type === undefined ) {
|
if ( type === undefined ) {
|
||||||
|
@ -2206,30 +2241,14 @@ FilterContainer.prototype.matchStringExactType = function(context, requestURL, r
|
||||||
pageHostnameRegister = context.pageHostname || '';
|
pageHostnameRegister = context.pageHostname || '';
|
||||||
requestHostnameRegister = µb.URI.hostnameFromURI(url);
|
requestHostnameRegister = µb.URI.hostnameFromURI(url);
|
||||||
|
|
||||||
var party = isFirstParty(context.pageDomain, requestHostnameRegister) ? FirstParty : ThirdParty;
|
var party = isFirstParty(context.pageDomain, requestHostnameRegister) ? FirstParty : ThirdParty,
|
||||||
|
categories = this.categories,
|
||||||
|
key, bucket;
|
||||||
|
|
||||||
this.fRegister = null;
|
this.fRegister = null;
|
||||||
|
|
||||||
var categories = this.categories;
|
|
||||||
var key, bucket;
|
|
||||||
|
|
||||||
// https://github.com/gorhill/uBlock/issues/1477
|
|
||||||
// Special case: blocking generichide filter ALWAYS exists, it is implicit --
|
|
||||||
// thus we always and only check for exception filters.
|
|
||||||
if ( requestType === 'generichide' ) {
|
|
||||||
key = AllowAnyParty | type;
|
|
||||||
if (
|
|
||||||
(bucket = categories.get(toHex(key))) &&
|
|
||||||
this.matchTokens(bucket, url)
|
|
||||||
) {
|
|
||||||
this.keyRegister = key;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
// https://github.com/chrisaljoudi/uBlock/issues/139
|
// https://github.com/chrisaljoudi/uBlock/issues/139
|
||||||
// Test against important block filters
|
// Test against important block filters
|
||||||
key = BlockAnyParty | Important | type;
|
key = BlockAnyParty | Important | type;
|
||||||
if ( (bucket = categories.get(toHex(key))) ) {
|
if ( (bucket = categories.get(toHex(key))) ) {
|
||||||
if ( this.matchTokens(bucket, url) ) {
|
if ( this.matchTokens(bucket, url) ) {
|
||||||
|
|
Loading…
Reference in a new issue