mirror of
https://github.com/gorhill/uBlock.git
synced 2024-11-07 03:12:33 +01:00
report filter count accurately, better prevent duplicates for cosmetic filters
This commit is contained in:
parent
d122cbf163
commit
3b3850f988
@ -1015,9 +1015,10 @@ var FilterContainer = function() {
|
|||||||
this.tokenEnd = 0;
|
this.tokenEnd = 0;
|
||||||
this.filterParser = new FilterParser();
|
this.filterParser = new FilterParser();
|
||||||
this.processedFilterCount = 0;
|
this.processedFilterCount = 0;
|
||||||
this.supportedFilterCount = 0;
|
this.acceptedCount = 0;
|
||||||
this.allowFilterCount = 0;
|
this.allowFilterCount = 0;
|
||||||
this.blockFilterCount = 0;
|
this.blockFilterCount = 0;
|
||||||
|
this.duplicateCount = 0;
|
||||||
|
|
||||||
// This is for hostname-based-any-request filters
|
// This is for hostname-based-any-request filters
|
||||||
this.blockedAnyPartyHostnames = new µBlock.LiquidDict();
|
this.blockedAnyPartyHostnames = new µBlock.LiquidDict();
|
||||||
@ -1051,9 +1052,11 @@ FilterContainer.prototype.makeCategoryKey = function(category) {
|
|||||||
|
|
||||||
FilterContainer.prototype.addAnyPartyHostname = function(hostname) {
|
FilterContainer.prototype.addAnyPartyHostname = function(hostname) {
|
||||||
if ( this.blockedAnyPartyHostnames.add(hostname) ) {
|
if ( this.blockedAnyPartyHostnames.add(hostname) ) {
|
||||||
this.blockFilterCount += 1;
|
this.acceptedCount++;
|
||||||
|
this.blockFilterCount++;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
this.duplicateCount++;
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -1061,9 +1064,11 @@ FilterContainer.prototype.addAnyPartyHostname = function(hostname) {
|
|||||||
|
|
||||||
FilterContainer.prototype.add3rdPartyHostname = function(hostname) {
|
FilterContainer.prototype.add3rdPartyHostname = function(hostname) {
|
||||||
if ( this.blocked3rdPartyHostnames.add(hostname) ) {
|
if ( this.blocked3rdPartyHostnames.add(hostname) ) {
|
||||||
this.blockFilterCount += 1;
|
this.acceptedCount++;
|
||||||
|
this.blockFilterCount++;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
this.duplicateCount++;
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -1090,6 +1095,7 @@ FilterContainer.prototype.add = function(s) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ( this.duplicates[s] ) {
|
if ( this.duplicates[s] ) {
|
||||||
|
this.duplicateCount++;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
this.duplicates[s] = true;
|
this.duplicates[s] = true;
|
||||||
@ -1102,13 +1108,13 @@ FilterContainer.prototype.add = function(s) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.supportedFilterCount += 1;
|
|
||||||
|
|
||||||
// Ignore optionless hostname rules, these will be taken care of by µBlock.
|
// Ignore optionless hostname rules, these will be taken care of by µBlock.
|
||||||
if ( parsed.hostname && parsed.fopts === '' && parsed.action === BlockAction && reHostnameRule.test(parsed.f) ) {
|
if ( parsed.hostname && parsed.fopts === '' && parsed.action === BlockAction && reHostnameRule.test(parsed.f) ) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.acceptedCount += 1;
|
||||||
|
|
||||||
// Pure third-party hostnames, use more efficient liquid dict
|
// Pure third-party hostnames, use more efficient liquid dict
|
||||||
if ( reHostnameRule.test(parsed.f) && parsed.hostname && parsed.action === BlockAction ) {
|
if ( reHostnameRule.test(parsed.f) && parsed.hostname && parsed.action === BlockAction ) {
|
||||||
if ( parsed.fopts === 'third-party' ) {
|
if ( parsed.fopts === 'third-party' ) {
|
||||||
@ -1231,9 +1237,10 @@ FilterContainer.prototype.addToCategory = function(category, tokenKey, filter) {
|
|||||||
|
|
||||||
FilterContainer.prototype.reset = function() {
|
FilterContainer.prototype.reset = function() {
|
||||||
this.processedFilterCount = 0;
|
this.processedFilterCount = 0;
|
||||||
this.supportedFilterCount = 0;
|
this.acceptedCount = 0;
|
||||||
this.allowFilterCount = 0;
|
this.allowFilterCount = 0;
|
||||||
this.blockFilterCount = 0;
|
this.blockFilterCount = 0;
|
||||||
|
this.duplicateCount = 0;
|
||||||
this.categories = {};
|
this.categories = {};
|
||||||
this.blockedAnyPartyHostnames.reset();
|
this.blockedAnyPartyHostnames.reset();
|
||||||
this.blocked3rdPartyHostnames.reset();
|
this.blocked3rdPartyHostnames.reset();
|
||||||
|
@ -261,8 +261,8 @@
|
|||||||
// https://adblockplus.org/en/filters
|
// https://adblockplus.org/en/filters
|
||||||
var abpFilters = this.abpFilters;
|
var abpFilters = this.abpFilters;
|
||||||
var abpHideFilters = this.userSettings.parseAllABPHideFilters ? this.abpHideFilters : null;
|
var abpHideFilters = this.userSettings.parseAllABPHideFilters ? this.abpHideFilters : null;
|
||||||
var thisListCount = 0;
|
var duplicateCount = abpFilters.duplicateCount + abpHideFilters.duplicateCount;
|
||||||
var thisListUsedCount = 0;
|
var acceptedCount = abpFilters.acceptedCount + abpHideFilters.acceptedCount;
|
||||||
var reLocalhost = /(^|\s)(localhost\.localdomain|localhost|local|broadcasthost|0\.0\.0\.0|127\.0\.0\.1|::1|fe80::1%lo0)(?=\s|$)/g;
|
var reLocalhost = /(^|\s)(localhost\.localdomain|localhost|local|broadcasthost|0\.0\.0\.0|127\.0\.0\.1|::1|fe80::1%lo0)(?=\s|$)/g;
|
||||||
var reAdblockFilter = /^[^a-z0-9:]|[^a-z0-9]$|[^a-z0-9_:.-]/;
|
var reAdblockFilter = /^[^a-z0-9:]|[^a-z0-9]$|[^a-z0-9_:.-]/;
|
||||||
var reAdblockHostFilter = /^\|\|([a-z0-9.-]+[a-z0-9])\^?$/;
|
var reAdblockHostFilter = /^\|\|([a-z0-9.-]+[a-z0-9])\^?$/;
|
||||||
@ -334,8 +334,6 @@
|
|||||||
if ( reAdblockFilter.test(line) ) {
|
if ( reAdblockFilter.test(line) ) {
|
||||||
if ( abpFilters !== null ) {
|
if ( abpFilters !== null ) {
|
||||||
if ( abpFilters.add(line) ) {
|
if ( abpFilters.add(line) ) {
|
||||||
thisListCount++;
|
|
||||||
thisListUsedCount++;
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -352,16 +350,16 @@
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
thisListCount++;
|
abpFilters.addAnyPartyHostname(line);
|
||||||
if ( abpFilters.addAnyPartyHostname(line) ) {
|
|
||||||
thisListUsedCount++;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// For convenience, store the number of entries for this
|
// For convenience, store the number of entries for this
|
||||||
// blacklist, user might be happy to know this information.
|
// blacklist, user might be happy to know this information.
|
||||||
this.remoteBlacklists[details.path].entryCount = thisListCount;
|
duplicateCount = abpFilters.duplicateCount + abpHideFilters.duplicateCount - duplicateCount;
|
||||||
this.remoteBlacklists[details.path].entryUsedCount = thisListUsedCount;
|
acceptedCount = abpFilters.acceptedCount + abpHideFilters.acceptedCount - acceptedCount;
|
||||||
|
|
||||||
|
this.remoteBlacklists[details.path].entryCount = acceptedCount + duplicateCount;
|
||||||
|
this.remoteBlacklists[details.path].entryUsedCount = acceptedCount;
|
||||||
};
|
};
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
Loading…
Reference in New Issue
Block a user