mirror of
https://github.com/gorhill/uBlock.git
synced 2024-11-07 03:12:33 +01:00
this partially addresses #236
This commit is contained in:
parent
e550887514
commit
2e11b38a67
@ -141,14 +141,15 @@
|
|||||||
µBlock.appendUserFilters = function(content) {
|
µBlock.appendUserFilters = function(content) {
|
||||||
var µb = this;
|
var µb = this;
|
||||||
|
|
||||||
var onFiltersReady = function() {
|
|
||||||
};
|
|
||||||
|
|
||||||
var onSaved = function(details) {
|
var onSaved = function(details) {
|
||||||
if ( details.error ) {
|
if ( details.error ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
µb.loadFilterLists(onFiltersReady);
|
µb.mergeFilterText(content);
|
||||||
|
µb.netFilteringEngine.freeze();
|
||||||
|
µb.cosmeticFilteringEngine.freeze();
|
||||||
|
µb.destroySelfie();
|
||||||
|
µb.toSelfieAsync();
|
||||||
};
|
};
|
||||||
|
|
||||||
var onLoaded = function(details) {
|
var onLoaded = function(details) {
|
||||||
@ -281,7 +282,7 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
var mergeBlacklist = function(details) {
|
var mergeBlacklist = function(details) {
|
||||||
µb.mergeUbiquitousBlacklist(details);
|
µb.mergeFilterList(details);
|
||||||
blacklistLoadCount -= 1;
|
blacklistLoadCount -= 1;
|
||||||
if ( blacklistLoadCount === 0 ) {
|
if ( blacklistLoadCount === 0 ) {
|
||||||
loadBlacklistsEnd();
|
loadBlacklistsEnd();
|
||||||
@ -319,26 +320,38 @@
|
|||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
µBlock.mergeUbiquitousBlacklist = function(details) {
|
µBlock.mergeFilterList = function(details) {
|
||||||
// console.log('µBlock > mergeUbiquitousBlacklist from "%s": "%s..."', details.path, details.content.slice(0, 40));
|
// console.log('µBlock > mergeFilterList from "%s": "%s..."', details.path, details.content.slice(0, 40));
|
||||||
|
|
||||||
var rawText = details.content;
|
var netFilteringEngine = this.netFilteringEngine;
|
||||||
|
var cosmeticFilteringEngine = this.cosmeticFilteringEngine;
|
||||||
|
var duplicateCount = netFilteringEngine.duplicateCount + cosmeticFilteringEngine.duplicateCount;
|
||||||
|
var acceptedCount = netFilteringEngine.acceptedCount + cosmeticFilteringEngine.acceptedCount;
|
||||||
|
|
||||||
|
this.mergeFilterText(details.content);
|
||||||
|
|
||||||
|
// For convenience, store the number of entries for this
|
||||||
|
// blacklist, user might be happy to know this information.
|
||||||
|
duplicateCount = netFilteringEngine.duplicateCount + cosmeticFilteringEngine.duplicateCount - duplicateCount;
|
||||||
|
acceptedCount = netFilteringEngine.acceptedCount + cosmeticFilteringEngine.acceptedCount - acceptedCount;
|
||||||
|
|
||||||
|
this.remoteBlacklists[details.path].entryCount = acceptedCount;
|
||||||
|
this.remoteBlacklists[details.path].entryUsedCount = acceptedCount - duplicateCount;
|
||||||
|
};
|
||||||
|
|
||||||
|
/******************************************************************************/
|
||||||
|
|
||||||
|
µBlock.mergeFilterText = function(rawText) {
|
||||||
var rawEnd = rawText.length;
|
var rawEnd = rawText.length;
|
||||||
|
|
||||||
// rhill 2013-10-21: No need to prefix with '* ', the hostname is just what
|
|
||||||
// we need for preset blacklists. The prefix '* ' is ONLY needed when
|
|
||||||
// used as a filter in temporary blacklist.
|
|
||||||
|
|
||||||
// rhill 2014-01-22: Transpose possible Adblock Plus-filter syntax
|
|
||||||
// into a plain hostname if possible.
|
|
||||||
// Useful references:
|
// Useful references:
|
||||||
// https://adblockplus.org/en/filter-cheatsheet
|
// https://adblockplus.org/en/filter-cheatsheet
|
||||||
// https://adblockplus.org/en/filters
|
// https://adblockplus.org/en/filters
|
||||||
var netFilteringEngine = this.netFilteringEngine;
|
var netFilteringEngine = this.netFilteringEngine;
|
||||||
var cosmeticFilteringEngine = this.cosmeticFilteringEngine;
|
var cosmeticFilteringEngine = this.cosmeticFilteringEngine;
|
||||||
var parseCosmeticFilters = this.userSettings.parseAllABPHideFilters;
|
var parseCosmeticFilters = this.userSettings.parseAllABPHideFilters;
|
||||||
var duplicateCount = netFilteringEngine.duplicateCount + cosmeticFilteringEngine.duplicateCount;
|
|
||||||
var acceptedCount = netFilteringEngine.acceptedCount + cosmeticFilteringEngine.acceptedCount;
|
var reIsCosmeticFilter = /#@?#/;
|
||||||
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 reAsciiSegment = /^[\x21-\x7e]+$/;
|
var reAsciiSegment = /^[\x21-\x7e]+$/;
|
||||||
var matches;
|
var matches;
|
||||||
@ -347,9 +360,9 @@
|
|||||||
|
|
||||||
while ( lineBeg < rawEnd ) {
|
while ( lineBeg < rawEnd ) {
|
||||||
lineEnd = rawText.indexOf('\n', lineBeg);
|
lineEnd = rawText.indexOf('\n', lineBeg);
|
||||||
if ( lineEnd < 0 ) {
|
if ( lineEnd === -1 ) {
|
||||||
lineEnd = rawText.indexOf('\r', lineBeg);
|
lineEnd = rawText.indexOf('\r', lineBeg);
|
||||||
if ( lineEnd < 0 ) {
|
if ( lineEnd === -1 ) {
|
||||||
lineEnd = rawEnd;
|
lineEnd = rawEnd;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -367,12 +380,13 @@
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2014-05-18: ABP element hide filters are allowed to contain space
|
// Parse or skip cosmetic filters
|
||||||
// characters
|
|
||||||
if ( parseCosmeticFilters ) {
|
if ( parseCosmeticFilters ) {
|
||||||
if ( cosmeticFilteringEngine.add(line) ) {
|
if ( cosmeticFilteringEngine.add(line) ) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
} else if ( reIsCosmeticFilter.test(line) ) {
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( c === '#' ) {
|
if ( c === '#' ) {
|
||||||
@ -391,7 +405,7 @@
|
|||||||
// whitespaces
|
// whitespaces
|
||||||
matches = reAsciiSegment.exec(line);
|
matches = reAsciiSegment.exec(line);
|
||||||
if ( matches === null ) {
|
if ( matches === null ) {
|
||||||
//console.debug('µBlock.mergeUbiquitousBlacklist(): skipping "%s"', lineRaw);
|
//console.debug('µBlock.mergeFilterList(): skipping "%s"', lineRaw);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -399,20 +413,12 @@
|
|||||||
// For example, when a filter contains whitespace characters, or
|
// For example, when a filter contains whitespace characters, or
|
||||||
// whatever else outside the range of printable ascii characters.
|
// whatever else outside the range of printable ascii characters.
|
||||||
if ( matches[0] !== line ) {
|
if ( matches[0] !== line ) {
|
||||||
// console.error('"%s": "%s" !== "%s"', details.path, matches[0], line);
|
// console.error('"%s" !== "%s"', matches[0], line);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
netFilteringEngine.add(matches[0]);
|
netFilteringEngine.add(matches[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// For convenience, store the number of entries for this
|
|
||||||
// blacklist, user might be happy to know this information.
|
|
||||||
duplicateCount = netFilteringEngine.duplicateCount + cosmeticFilteringEngine.duplicateCount - duplicateCount;
|
|
||||||
acceptedCount = netFilteringEngine.acceptedCount + cosmeticFilteringEngine.acceptedCount - acceptedCount;
|
|
||||||
|
|
||||||
this.remoteBlacklists[details.path].entryCount = acceptedCount;
|
|
||||||
this.remoteBlacklists[details.path].entryUsedCount = acceptedCount - duplicateCount;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
@ -508,6 +514,7 @@
|
|||||||
// This is to be sure the selfie is generated in a sane manner: the selfie will
|
// This is to be sure the selfie is generated in a sane manner: the selfie will
|
||||||
// be generated if the user doesn't change his filter lists selection for
|
// be generated if the user doesn't change his filter lists selection for
|
||||||
// some set time.
|
// some set time.
|
||||||
|
|
||||||
µBlock.toSelfieAsync = function(after) {
|
µBlock.toSelfieAsync = function(after) {
|
||||||
if ( typeof after !== 'number' ) {
|
if ( typeof after !== 'number' ) {
|
||||||
after = this.selfieAfter;
|
after = this.selfieAfter;
|
||||||
|
Loading…
Reference in New Issue
Block a user