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

report filter count accurately, better prevent duplicates for cosmetic filters

This commit is contained in:
gorhill 2014-07-16 10:43:34 -04:00
parent d122cbf163
commit 3b3850f988
2 changed files with 21 additions and 16 deletions

View File

@ -1015,9 +1015,10 @@ var FilterContainer = function() {
this.tokenEnd = 0;
this.filterParser = new FilterParser();
this.processedFilterCount = 0;
this.supportedFilterCount = 0;
this.acceptedCount = 0;
this.allowFilterCount = 0;
this.blockFilterCount = 0;
this.duplicateCount = 0;
// This is for hostname-based-any-request filters
this.blockedAnyPartyHostnames = new µBlock.LiquidDict();
@ -1051,9 +1052,11 @@ FilterContainer.prototype.makeCategoryKey = function(category) {
FilterContainer.prototype.addAnyPartyHostname = function(hostname) {
if ( this.blockedAnyPartyHostnames.add(hostname) ) {
this.blockFilterCount += 1;
this.acceptedCount++;
this.blockFilterCount++;
return true;
}
this.duplicateCount++;
return false;
};
@ -1061,9 +1064,11 @@ FilterContainer.prototype.addAnyPartyHostname = function(hostname) {
FilterContainer.prototype.add3rdPartyHostname = function(hostname) {
if ( this.blocked3rdPartyHostnames.add(hostname) ) {
this.blockFilterCount += 1;
this.acceptedCount++;
this.blockFilterCount++;
return true;
}
this.duplicateCount++;
return false;
};
@ -1090,6 +1095,7 @@ FilterContainer.prototype.add = function(s) {
}
if ( this.duplicates[s] ) {
this.duplicateCount++;
return false;
}
this.duplicates[s] = true;
@ -1102,13 +1108,13 @@ FilterContainer.prototype.add = function(s) {
return false;
}
this.supportedFilterCount += 1;
// Ignore optionless hostname rules, these will be taken care of by µBlock.
if ( parsed.hostname && parsed.fopts === '' && parsed.action === BlockAction && reHostnameRule.test(parsed.f) ) {
return false;
}
this.acceptedCount += 1;
// Pure third-party hostnames, use more efficient liquid dict
if ( reHostnameRule.test(parsed.f) && parsed.hostname && parsed.action === BlockAction ) {
if ( parsed.fopts === 'third-party' ) {
@ -1231,9 +1237,10 @@ FilterContainer.prototype.addToCategory = function(category, tokenKey, filter) {
FilterContainer.prototype.reset = function() {
this.processedFilterCount = 0;
this.supportedFilterCount = 0;
this.acceptedCount = 0;
this.allowFilterCount = 0;
this.blockFilterCount = 0;
this.duplicateCount = 0;
this.categories = {};
this.blockedAnyPartyHostnames.reset();
this.blocked3rdPartyHostnames.reset();

View File

@ -261,8 +261,8 @@
// https://adblockplus.org/en/filters
var abpFilters = this.abpFilters;
var abpHideFilters = this.userSettings.parseAllABPHideFilters ? this.abpHideFilters : null;
var thisListCount = 0;
var thisListUsedCount = 0;
var duplicateCount = abpFilters.duplicateCount + abpHideFilters.duplicateCount;
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 reAdblockFilter = /^[^a-z0-9:]|[^a-z0-9]$|[^a-z0-9_:.-]/;
var reAdblockHostFilter = /^\|\|([a-z0-9.-]+[a-z0-9])\^?$/;
@ -334,8 +334,6 @@
if ( reAdblockFilter.test(line) ) {
if ( abpFilters !== null ) {
if ( abpFilters.add(line) ) {
thisListCount++;
thisListUsedCount++;
continue;
}
}
@ -352,16 +350,16 @@
continue;
}
thisListCount++;
if ( abpFilters.addAnyPartyHostname(line) ) {
thisListUsedCount++;
}
abpFilters.addAnyPartyHostname(line);
}
// For convenience, store the number of entries for this
// blacklist, user might be happy to know this information.
this.remoteBlacklists[details.path].entryCount = thisListCount;
this.remoteBlacklists[details.path].entryUsedCount = thisListUsedCount;
duplicateCount = abpFilters.duplicateCount + abpHideFilters.duplicateCount - duplicateCount;
acceptedCount = abpFilters.acceptedCount + abpHideFilters.acceptedCount - acceptedCount;
this.remoteBlacklists[details.path].entryCount = acceptedCount + duplicateCount;
this.remoteBlacklists[details.path].entryUsedCount = acceptedCount;
};
/******************************************************************************/