2014-06-24 00:42:43 +02:00
|
|
|
|
/*******************************************************************************
|
|
|
|
|
|
2016-06-28 01:09:04 +02:00
|
|
|
|
uBlock Origin - a browser extension to block requests.
|
|
|
|
|
Copyright (C) 2014-2016 Raymond Hill
|
2014-06-24 00:42:43 +02:00
|
|
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
|
along with this program. If not, see {http://www.gnu.org/licenses/}.
|
|
|
|
|
|
|
|
|
|
Home: https://github.com/gorhill/uBlock
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/* jshint bitwise: false */
|
2016-06-28 01:09:04 +02:00
|
|
|
|
/* global punycode */
|
|
|
|
|
|
|
|
|
|
'use strict';
|
2014-06-24 00:42:43 +02:00
|
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
2014-09-08 23:46:58 +02:00
|
|
|
|
µBlock.cosmeticFilteringEngine = (function(){
|
2014-06-24 00:42:43 +02:00
|
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
|
|
var µb = µBlock;
|
|
|
|
|
|
2014-09-08 23:46:58 +02:00
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
|
|
// Could be replaced with encodeURIComponent/decodeURIComponent,
|
|
|
|
|
// which seems faster on Firefox.
|
|
|
|
|
var encode = JSON.stringify;
|
|
|
|
|
var decode = JSON.parse;
|
|
|
|
|
|
2015-10-26 16:23:56 +01:00
|
|
|
|
var isBadRegex = function(s) {
|
|
|
|
|
try {
|
|
|
|
|
void new RegExp(s);
|
|
|
|
|
} catch (ex) {
|
|
|
|
|
isBadRegex.message = ex.toString();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
};
|
|
|
|
|
|
2016-07-12 19:29:30 +02:00
|
|
|
|
var cosmeticSurveyingMissCountMax = parseInt(vAPI.localStorage.getItem('cosmeticSurveyingMissCountMax'), 10) || 15;
|
2016-07-10 01:21:46 +02:00
|
|
|
|
|
2014-06-24 00:42:43 +02:00
|
|
|
|
/******************************************************************************/
|
|
|
|
|
/*
|
|
|
|
|
var histogram = function(label, buckets) {
|
|
|
|
|
var h = [],
|
|
|
|
|
bucket;
|
|
|
|
|
for ( var k in buckets ) {
|
|
|
|
|
if ( buckets.hasOwnProperty(k) === false ) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
bucket = buckets[k];
|
|
|
|
|
h.push({
|
|
|
|
|
k: k,
|
|
|
|
|
n: bucket instanceof FilterBucket ? bucket.filters.length : 1
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
console.log('Histogram %s', label);
|
|
|
|
|
|
|
|
|
|
var total = h.length;
|
|
|
|
|
h.sort(function(a, b) { return b.n - a.n; });
|
|
|
|
|
|
|
|
|
|
// Find indices of entries of interest
|
|
|
|
|
var target = 3;
|
|
|
|
|
for ( var i = 0; i < total; i++ ) {
|
|
|
|
|
if ( h[i].n === target ) {
|
|
|
|
|
console.log('\tEntries with only %d filter(s) start at index %s (key = "%s")', target, i, h[i].k);
|
|
|
|
|
target -= 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
h = h.slice(0, 50);
|
|
|
|
|
|
|
|
|
|
h.forEach(function(v) {
|
|
|
|
|
console.log('\tkey="%s" count=%d', v.k, v.n);
|
|
|
|
|
});
|
|
|
|
|
console.log('\tTotal buckets count: %d', total);
|
|
|
|
|
};
|
|
|
|
|
*/
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
|
|
// Pure id- and class-based filters
|
|
|
|
|
// Examples:
|
|
|
|
|
// #A9AdsMiddleBoxTop
|
|
|
|
|
// .AD-POST
|
|
|
|
|
|
2015-09-13 20:29:43 +02:00
|
|
|
|
var FilterPlain = function() {
|
2014-06-24 00:42:43 +02:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
FilterPlain.prototype.retrieve = function(s, out) {
|
2015-09-13 20:37:35 +02:00
|
|
|
|
out.push(s);
|
2014-06-24 00:42:43 +02:00
|
|
|
|
};
|
|
|
|
|
|
2014-09-08 23:46:58 +02:00
|
|
|
|
FilterPlain.prototype.fid = '#';
|
|
|
|
|
|
|
|
|
|
FilterPlain.prototype.toSelfie = function() {
|
|
|
|
|
};
|
|
|
|
|
|
2015-09-13 20:29:43 +02:00
|
|
|
|
FilterPlain.fromSelfie = function() {
|
|
|
|
|
return filterPlain;
|
2014-09-08 23:46:58 +02:00
|
|
|
|
};
|
|
|
|
|
|
2015-09-13 20:29:43 +02:00
|
|
|
|
var filterPlain = new FilterPlain();
|
|
|
|
|
|
2014-06-24 00:42:43 +02:00
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
|
|
// Id- and class-based filters with extra selector stuff following.
|
|
|
|
|
// Examples:
|
|
|
|
|
// #center_col > div[style="font-size:14px;margin-right:0;min-height:5px"] ...
|
|
|
|
|
// #adframe:not(frameset)
|
|
|
|
|
// .l-container > #fishtank
|
2015-11-19 15:36:15 +01:00
|
|
|
|
// body #sliding-popup
|
2014-06-24 00:42:43 +02:00
|
|
|
|
|
|
|
|
|
var FilterPlainMore = function(s) {
|
|
|
|
|
this.s = s;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
FilterPlainMore.prototype.retrieve = function(s, out) {
|
2015-11-19 15:36:15 +01:00
|
|
|
|
out.push(this.s);
|
2014-06-24 00:42:43 +02:00
|
|
|
|
};
|
|
|
|
|
|
2014-09-08 23:46:58 +02:00
|
|
|
|
FilterPlainMore.prototype.fid = '#+';
|
|
|
|
|
|
|
|
|
|
FilterPlainMore.prototype.toSelfie = function() {
|
|
|
|
|
return this.s;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
FilterPlainMore.fromSelfie = function(s) {
|
|
|
|
|
return new FilterPlainMore(s);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
2014-06-24 00:42:43 +02:00
|
|
|
|
// Any selector specific to a hostname
|
|
|
|
|
// Examples:
|
|
|
|
|
// search.snapdo.com###ABottomD
|
|
|
|
|
// facebook.com##.-cx-PRIVATE-fbAdUnit__root
|
|
|
|
|
// sltrib.com###BLContainer + div[style="height:90px;"]
|
|
|
|
|
// myps3.com.au##.Boxer[style="height: 250px;"]
|
|
|
|
|
// lindaikeji.blogspot.com##a > img[height="600"]
|
|
|
|
|
// japantimes.co.jp##table[align="right"][width="250"]
|
|
|
|
|
// mobilephonetalk.com##[align="center"] > b > a[href^="http://tinyurl.com/"]
|
|
|
|
|
|
|
|
|
|
var FilterHostname = function(s, hostname) {
|
|
|
|
|
this.s = s;
|
|
|
|
|
this.hostname = hostname;
|
|
|
|
|
};
|
|
|
|
|
|
2014-07-13 08:36:38 +02:00
|
|
|
|
FilterHostname.prototype.retrieve = function(hostname, out) {
|
2015-12-15 16:40:40 +01:00
|
|
|
|
if ( hostname.endsWith(this.hostname) ) {
|
2014-07-13 08:36:38 +02:00
|
|
|
|
out.push(this.s);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2014-09-08 23:46:58 +02:00
|
|
|
|
FilterHostname.prototype.fid = 'h';
|
|
|
|
|
|
|
|
|
|
FilterHostname.prototype.toSelfie = function() {
|
|
|
|
|
return encode(this.s) + '\t' + this.hostname;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
FilterHostname.fromSelfie = function(s) {
|
|
|
|
|
var pos = s.indexOf('\t');
|
|
|
|
|
return new FilterHostname(decode(s.slice(0, pos)), s.slice(pos + 1));
|
|
|
|
|
};
|
|
|
|
|
|
2014-08-14 19:59:37 +02:00
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
2016-06-28 01:09:04 +02:00
|
|
|
|
var FilterBucket = function(a, b) {
|
|
|
|
|
this.f = null;
|
|
|
|
|
this.filters = [];
|
|
|
|
|
if ( a !== undefined ) {
|
|
|
|
|
this.filters[0] = a;
|
|
|
|
|
if ( b !== undefined ) {
|
|
|
|
|
this.filters[1] = b;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
FilterBucket.prototype.add = function(a) {
|
|
|
|
|
this.filters.push(a);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
FilterBucket.prototype.retrieve = function(s, out) {
|
|
|
|
|
var i = this.filters.length;
|
|
|
|
|
while ( i-- ) {
|
|
|
|
|
this.filters[i].retrieve(s, out);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
FilterBucket.prototype.fid = '[]';
|
|
|
|
|
|
|
|
|
|
FilterBucket.prototype.toSelfie = function() {
|
|
|
|
|
return this.filters.length.toString();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
FilterBucket.fromSelfie = function() {
|
|
|
|
|
return new FilterBucket();
|
|
|
|
|
};
|
|
|
|
|
|
2014-06-24 00:42:43 +02:00
|
|
|
|
/******************************************************************************/
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
|
|
var FilterParser = function() {
|
2015-10-04 19:27:05 +02:00
|
|
|
|
this.prefix = this.suffix = this.style = '';
|
2014-08-12 18:19:54 +02:00
|
|
|
|
this.unhide = 0;
|
2014-06-24 00:42:43 +02:00
|
|
|
|
this.hostnames = [];
|
|
|
|
|
this.invalid = false;
|
2015-03-16 19:58:35 +01:00
|
|
|
|
this.cosmetic = true;
|
2016-12-01 17:55:05 +01:00
|
|
|
|
this.reNeedHostname = /^(?:script:contains|script:inject|.+?:has|.+?:matches-css(?:-before|-after)?|:xpath)\(.+?\)$/;
|
2014-06-24 00:42:43 +02:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
|
|
FilterParser.prototype.reset = function() {
|
2016-06-28 01:09:04 +02:00
|
|
|
|
this.raw = '';
|
2015-10-04 19:27:05 +02:00
|
|
|
|
this.prefix = this.suffix = this.style = '';
|
2014-08-12 18:19:54 +02:00
|
|
|
|
this.unhide = 0;
|
|
|
|
|
this.hostnames.length = 0;
|
2014-06-24 00:42:43 +02:00
|
|
|
|
this.invalid = false;
|
2015-03-16 19:58:35 +01:00
|
|
|
|
this.cosmetic = true;
|
2014-06-24 00:42:43 +02:00
|
|
|
|
return this;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
2015-10-26 16:23:56 +01:00
|
|
|
|
FilterParser.prototype.parse = function(raw) {
|
2014-06-24 00:42:43 +02:00
|
|
|
|
// important!
|
|
|
|
|
this.reset();
|
|
|
|
|
|
2016-06-28 01:09:04 +02:00
|
|
|
|
this.raw = raw;
|
|
|
|
|
|
2015-11-30 20:47:56 +01:00
|
|
|
|
// Find the bounds of the anchor.
|
|
|
|
|
var lpos = raw.indexOf('#');
|
|
|
|
|
if ( lpos === -1 ) {
|
|
|
|
|
this.cosmetic = false;
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
var rpos = raw.indexOf('#', lpos + 1);
|
|
|
|
|
if ( rpos === -1 ) {
|
|
|
|
|
this.cosmetic = false;
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Coarse-check that the anchor is valid.
|
|
|
|
|
// `##`: l = 1
|
|
|
|
|
// `#@#`, `#$#`, `#%#`: l = 2
|
|
|
|
|
// `#@$#`, `#@%#`: l = 3
|
|
|
|
|
if ( (rpos - lpos) > 3 ) {
|
|
|
|
|
this.cosmetic = false;
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Find out type of cosmetic filter.
|
|
|
|
|
// Exception filter?
|
|
|
|
|
if ( raw.charCodeAt(lpos + 1) === 0x40 /* '@' */ ) {
|
|
|
|
|
this.unhide = 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// https://github.com/gorhill/uBlock/issues/952
|
|
|
|
|
// Find out whether we are dealing with an Adguard-specific cosmetic
|
2016-06-29 23:07:33 +02:00
|
|
|
|
// filter, and if so, translate it if supported, or discard it if not
|
|
|
|
|
// supported.
|
2015-11-30 20:47:56 +01:00
|
|
|
|
var cCode = raw.charCodeAt(rpos - 1);
|
|
|
|
|
if ( cCode !== 0x23 /* '#' */ && cCode !== 0x40 /* '@' */ ) {
|
|
|
|
|
// We have an Adguard cosmetic filter if and only if the character is
|
|
|
|
|
// `$` or `%`, otherwise it's not a cosmetic filter.
|
2016-06-29 23:07:33 +02:00
|
|
|
|
// Not a cosmetic filter.
|
|
|
|
|
if ( cCode !== 0x24 /* '$' */ && cCode !== 0x25 /* '%' */ ) {
|
2015-11-30 20:47:56 +01:00
|
|
|
|
this.cosmetic = false;
|
2016-06-29 23:07:33 +02:00
|
|
|
|
return this;
|
2015-11-30 20:47:56 +01:00
|
|
|
|
}
|
2016-06-29 23:07:33 +02:00
|
|
|
|
// Not supported.
|
|
|
|
|
if ( cCode !== 0x24 /* '$' */ ) {
|
|
|
|
|
this.invalid = true;
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
// CSS injection rule: supported, but translate into uBO's own format.
|
|
|
|
|
raw = this.translateAdguardCSSInjectionFilter(raw);
|
|
|
|
|
if ( raw === '' ) {
|
|
|
|
|
this.invalid = true;
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
rpos = raw.indexOf('#', lpos + 1);
|
2015-11-30 20:47:56 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Extract the hostname(s).
|
|
|
|
|
if ( lpos !== 0 ) {
|
|
|
|
|
this.prefix = raw.slice(0, lpos);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Extract the selector.
|
2016-09-01 21:54:01 +02:00
|
|
|
|
this.suffix = raw.slice(rpos + 1).trim();
|
2015-11-30 20:47:56 +01:00
|
|
|
|
if ( this.suffix.length === 0 ) {
|
2015-03-16 19:58:35 +01:00
|
|
|
|
this.cosmetic = false;
|
2014-06-24 00:42:43 +02:00
|
|
|
|
return this;
|
|
|
|
|
}
|
2015-10-04 19:27:05 +02:00
|
|
|
|
|
2014-06-24 00:42:43 +02:00
|
|
|
|
// 2014-05-23:
|
|
|
|
|
// https://github.com/gorhill/httpswitchboard/issues/260
|
|
|
|
|
// Any sequence of `#` longer than one means the line is not a valid
|
|
|
|
|
// cosmetic filter.
|
2014-08-12 18:19:54 +02:00
|
|
|
|
if ( this.suffix.indexOf('##') !== -1 ) {
|
2015-03-16 19:58:35 +01:00
|
|
|
|
this.cosmetic = false;
|
2014-06-24 00:42:43 +02:00
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-12 18:19:54 +02:00
|
|
|
|
// Normalize high-medium selectors: `href` is assumed to imply `a` tag. We
|
|
|
|
|
// need to do this here in order to correctly avoid duplicates. The test
|
|
|
|
|
// is designed to minimize overhead -- this is a low occurrence filter.
|
2015-12-15 16:40:40 +01:00
|
|
|
|
if ( this.suffix.startsWith('[href^="', 1) ) {
|
2014-08-12 18:19:54 +02:00
|
|
|
|
this.suffix = this.suffix.slice(1);
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-04 19:27:05 +02:00
|
|
|
|
if ( this.prefix !== '' ) {
|
|
|
|
|
this.hostnames = this.prefix.split(/\s*,\s*/);
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-12 16:22:25 +02:00
|
|
|
|
// For some selectors, it is mandatory to have a hostname or entity:
|
|
|
|
|
// ##script:contains(...)
|
|
|
|
|
// ##script:inject(...)
|
|
|
|
|
// ##.foo:has(...)
|
|
|
|
|
// ##.foo:matches-css(...)
|
|
|
|
|
// ##:xpath(...)
|
2016-06-28 01:09:04 +02:00
|
|
|
|
if (
|
|
|
|
|
this.hostnames.length === 0 &&
|
|
|
|
|
this.unhide === 0 &&
|
|
|
|
|
this.reNeedHostname.test(this.suffix)
|
|
|
|
|
) {
|
|
|
|
|
this.invalid = true;
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return this;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
2016-06-29 23:07:33 +02:00
|
|
|
|
// Reference: https://adguard.com/en/filterrules.html#cssInjection
|
|
|
|
|
|
|
|
|
|
FilterParser.prototype.translateAdguardCSSInjectionFilter = function(raw) {
|
|
|
|
|
var matches = /^([^#]*)#(@?)\$#([^{]+)\{([^}]+)\}$/.exec(raw);
|
|
|
|
|
if ( matches === null ) {
|
|
|
|
|
return '';
|
|
|
|
|
}
|
2016-06-30 00:12:21 +02:00
|
|
|
|
// For now we do not allow generic CSS injections (prolly never).
|
|
|
|
|
if ( matches[1] === '' && matches[2] !== '@' ) {
|
|
|
|
|
return '';
|
|
|
|
|
}
|
2016-06-29 23:07:33 +02:00
|
|
|
|
return matches[1] +
|
|
|
|
|
'#' + matches[2] + '#' +
|
|
|
|
|
matches[3].trim() +
|
|
|
|
|
':style(' + matches[4].trim() + ')';
|
|
|
|
|
};
|
|
|
|
|
|
2014-06-24 00:42:43 +02:00
|
|
|
|
/******************************************************************************/
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
2014-08-14 02:03:55 +02:00
|
|
|
|
var SelectorCacheEntry = function() {
|
2014-12-26 21:26:44 +01:00
|
|
|
|
this.reset();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
|
|
SelectorCacheEntry.junkyard = [];
|
|
|
|
|
|
|
|
|
|
SelectorCacheEntry.factory = function() {
|
|
|
|
|
var entry = SelectorCacheEntry.junkyard.pop();
|
|
|
|
|
if ( entry ) {
|
|
|
|
|
return entry.reset();
|
|
|
|
|
}
|
|
|
|
|
return new SelectorCacheEntry();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
2016-08-08 15:53:35 +02:00
|
|
|
|
var netSelectorCacheLowWaterMark = 20;
|
|
|
|
|
var netSelectorCacheHighWaterMark = 30;
|
2014-12-26 21:26:44 +01:00
|
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
|
|
SelectorCacheEntry.prototype.reset = function() {
|
2014-08-14 19:59:37 +02:00
|
|
|
|
this.cosmetic = {};
|
2016-07-10 01:21:46 +02:00
|
|
|
|
this.cosmeticSurveyingMissCount = 0;
|
2014-08-14 19:59:37 +02:00
|
|
|
|
this.net = {};
|
|
|
|
|
this.netCount = 0;
|
2014-08-14 02:03:55 +02:00
|
|
|
|
this.lastAccessTime = Date.now();
|
2014-12-26 21:26:44 +01:00
|
|
|
|
return this;
|
2014-08-14 02:03:55 +02:00
|
|
|
|
};
|
|
|
|
|
|
2014-12-26 21:26:44 +01:00
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
|
|
SelectorCacheEntry.prototype.dispose = function() {
|
|
|
|
|
this.cosmetic = this.net = null;
|
|
|
|
|
if ( SelectorCacheEntry.junkyard.length < 25 ) {
|
|
|
|
|
SelectorCacheEntry.junkyard.push(this);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/******************************************************************************/
|
2014-08-14 19:59:37 +02:00
|
|
|
|
|
2016-10-06 16:49:46 +02:00
|
|
|
|
SelectorCacheEntry.prototype.addCosmetic = function(details) {
|
|
|
|
|
var selectors = details.selectors,
|
|
|
|
|
i = selectors.length || 0;
|
|
|
|
|
// https://github.com/gorhill/uBlock/issues/2011
|
|
|
|
|
// Avoiding seemingly pointless surveys only if they appear costly.
|
|
|
|
|
if ( details.first && i === 0 ) {
|
|
|
|
|
if ( (details.cost || 0) >= 80 ) {
|
|
|
|
|
this.cosmeticSurveyingMissCount += 1;
|
|
|
|
|
}
|
2016-07-10 01:21:46 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
this.cosmeticSurveyingMissCount = 0;
|
|
|
|
|
var dict = this.cosmetic;
|
2014-08-14 19:59:37 +02:00
|
|
|
|
while ( i-- ) {
|
2014-10-17 21:44:19 +02:00
|
|
|
|
dict[selectors[i]] = true;
|
2014-08-14 19:59:37 +02:00
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2014-12-26 21:26:44 +01:00
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
2014-08-15 16:34:13 +02:00
|
|
|
|
SelectorCacheEntry.prototype.addNet = function(selectors) {
|
|
|
|
|
if ( typeof selectors === 'string' ) {
|
|
|
|
|
this.addNetOne(selectors, Date.now());
|
|
|
|
|
} else {
|
|
|
|
|
this.addNetMany(selectors, Date.now());
|
2014-08-14 19:59:37 +02:00
|
|
|
|
}
|
|
|
|
|
// Net request-derived selectors: I limit the number of cached selectors,
|
|
|
|
|
// as I expect cases where the blocked net-requests are never the
|
|
|
|
|
// exact same URL.
|
2016-08-08 15:53:35 +02:00
|
|
|
|
if ( this.netCount < netSelectorCacheHighWaterMark ) {
|
2014-08-14 19:59:37 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
2014-08-15 16:34:13 +02:00
|
|
|
|
var dict = this.net;
|
|
|
|
|
var keys = Object.keys(dict).sort(function(a, b) {
|
|
|
|
|
return dict[b] - dict[a];
|
2016-08-08 15:53:35 +02:00
|
|
|
|
}).slice(netSelectorCacheLowWaterMark);
|
2014-08-15 16:34:13 +02:00
|
|
|
|
var i = keys.length;
|
|
|
|
|
while ( i-- ) {
|
|
|
|
|
delete dict[keys[i]];
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2014-12-26 21:26:44 +01:00
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
2014-08-15 16:34:13 +02:00
|
|
|
|
SelectorCacheEntry.prototype.addNetOne = function(selector, now) {
|
|
|
|
|
var dict = this.net;
|
|
|
|
|
if ( dict[selector] === undefined ) {
|
|
|
|
|
this.netCount += 1;
|
|
|
|
|
}
|
|
|
|
|
dict[selector] = now;
|
|
|
|
|
};
|
|
|
|
|
|
2014-12-26 21:26:44 +01:00
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
2014-08-15 16:34:13 +02:00
|
|
|
|
SelectorCacheEntry.prototype.addNetMany = function(selectors, now) {
|
|
|
|
|
var dict = this.net;
|
|
|
|
|
var i = selectors.length || 0;
|
|
|
|
|
var selector;
|
|
|
|
|
while ( i-- ) {
|
|
|
|
|
selector = selectors[i];
|
|
|
|
|
if ( dict[selector] === undefined ) {
|
|
|
|
|
this.netCount += 1;
|
2014-08-14 19:59:37 +02:00
|
|
|
|
}
|
2014-08-15 16:34:13 +02:00
|
|
|
|
dict[selector] = now;
|
2014-08-14 19:59:37 +02:00
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2014-12-26 21:26:44 +01:00
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
2016-10-06 16:49:46 +02:00
|
|
|
|
SelectorCacheEntry.prototype.add = function(details) {
|
2014-08-14 02:03:55 +02:00
|
|
|
|
this.lastAccessTime = Date.now();
|
2016-10-06 16:49:46 +02:00
|
|
|
|
if ( details.type === 'cosmetic' ) {
|
|
|
|
|
this.addCosmetic(details);
|
2014-08-14 19:59:37 +02:00
|
|
|
|
} else {
|
2016-10-06 16:49:46 +02:00
|
|
|
|
this.addNet(details.selectors);
|
2014-08-14 19:59:37 +02:00
|
|
|
|
}
|
2014-08-14 02:03:55 +02:00
|
|
|
|
};
|
|
|
|
|
|
2014-12-26 21:26:44 +01:00
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
2015-04-07 03:26:05 +02:00
|
|
|
|
// https://github.com/chrisaljoudi/uBlock/issues/420
|
2014-12-17 16:32:50 +01:00
|
|
|
|
SelectorCacheEntry.prototype.remove = function(type) {
|
|
|
|
|
this.lastAccessTime = Date.now();
|
2015-02-11 23:28:19 +01:00
|
|
|
|
if ( type === undefined || type === 'cosmetic' ) {
|
2014-12-17 16:32:50 +01:00
|
|
|
|
this.cosmetic = {};
|
2016-07-10 01:21:46 +02:00
|
|
|
|
this.cosmeticSurveyingMissCount = 0;
|
2015-02-11 23:28:19 +01:00
|
|
|
|
}
|
|
|
|
|
if ( type === undefined || type === 'net' ) {
|
2014-12-17 16:32:50 +01:00
|
|
|
|
this.net = {};
|
|
|
|
|
this.netCount = 0;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2014-12-26 21:26:44 +01:00
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
2014-08-14 19:59:37 +02:00
|
|
|
|
SelectorCacheEntry.prototype.retrieve = function(type, out) {
|
2014-08-14 02:03:55 +02:00
|
|
|
|
this.lastAccessTime = Date.now();
|
2014-08-14 19:59:37 +02:00
|
|
|
|
var dict = type === 'cosmetic' ? this.cosmetic : this.net;
|
|
|
|
|
for ( var selector in dict ) {
|
|
|
|
|
if ( dict.hasOwnProperty(selector) ) {
|
|
|
|
|
out.push(selector);
|
|
|
|
|
}
|
2014-08-14 02:03:55 +02:00
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
2014-08-12 18:19:54 +02:00
|
|
|
|
// Two Unicode characters:
|
|
|
|
|
// T0HHHHHHH HHHHHHHHH
|
2014-10-17 21:44:19 +02:00
|
|
|
|
// | | |
|
|
|
|
|
// | | |
|
|
|
|
|
// | | |
|
2014-08-12 18:19:54 +02:00
|
|
|
|
// | | +-- bit 8-0 of FNV
|
|
|
|
|
// | |
|
|
|
|
|
// | +-- bit 15-9 of FNV
|
|
|
|
|
// |
|
|
|
|
|
// +-- filter type (0=hide 1=unhide)
|
|
|
|
|
//
|
2014-06-24 00:42:43 +02:00
|
|
|
|
|
2016-09-12 16:22:25 +02:00
|
|
|
|
var makeHash = function(token) {
|
2014-08-12 18:19:54 +02:00
|
|
|
|
// Ref: Given a URL, returns a unique 4-character long hash string
|
|
|
|
|
// Based on: FNV32a
|
|
|
|
|
// http://www.isthe.com/chongo/tech/comp/fnv/index.html#FNV-reference-source
|
2016-09-12 16:22:25 +02:00
|
|
|
|
// The rest is custom, suited for uBlock.
|
2014-08-12 18:19:54 +02:00
|
|
|
|
var i1 = token.length;
|
|
|
|
|
var i2 = i1 >> 1;
|
|
|
|
|
var i4 = i1 >> 2;
|
|
|
|
|
var i8 = i1 >> 3;
|
|
|
|
|
var hval = (0x811c9dc5 ^ token.charCodeAt(0)) >>> 0;
|
|
|
|
|
hval += (hval<<1) + (hval<<4) + (hval<<7) + (hval<<8) + (hval<<24);
|
|
|
|
|
hval >>>= 0;
|
|
|
|
|
hval ^= token.charCodeAt(i8);
|
|
|
|
|
hval += (hval<<1) + (hval<<4) + (hval<<7) + (hval<<8) + (hval<<24);
|
|
|
|
|
hval >>>= 0;
|
|
|
|
|
hval ^= token.charCodeAt(i4);
|
|
|
|
|
hval += (hval<<1) + (hval<<4) + (hval<<7) + (hval<<8) + (hval<<24);
|
|
|
|
|
hval >>>= 0;
|
|
|
|
|
hval ^= token.charCodeAt(i4+i8);
|
|
|
|
|
hval += (hval<<1) + (hval<<4) + (hval<<7) + (hval<<8) + (hval<<24);
|
|
|
|
|
hval >>>= 0;
|
|
|
|
|
hval ^= token.charCodeAt(i2);
|
|
|
|
|
hval += (hval<<1) + (hval<<4) + (hval<<7) + (hval<<8) + (hval<<24);
|
|
|
|
|
hval >>>= 0;
|
|
|
|
|
hval ^= token.charCodeAt(i2+i8);
|
|
|
|
|
hval += (hval<<1) + (hval<<4) + (hval<<7) + (hval<<8) + (hval<<24);
|
|
|
|
|
hval >>>= 0;
|
|
|
|
|
hval ^= token.charCodeAt(i2+i4);
|
|
|
|
|
hval += (hval<<1) + (hval<<4) + (hval<<7) + (hval<<8) + (hval<<24);
|
|
|
|
|
hval >>>= 0;
|
|
|
|
|
hval ^= token.charCodeAt(i1-1);
|
|
|
|
|
hval += (hval<<1) + (hval<<4) + (hval<<7) + (hval<<8) + (hval<<24);
|
|
|
|
|
hval >>>= 0;
|
2016-09-12 16:22:25 +02:00
|
|
|
|
hval &= 0x0FFF; // 12 bits
|
2015-02-24 00:31:29 +01:00
|
|
|
|
return hval.toString(36);
|
2014-06-24 00:42:43 +02:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
2014-08-12 18:19:54 +02:00
|
|
|
|
// Cosmetic filter family tree:
|
|
|
|
|
//
|
|
|
|
|
// Generic
|
|
|
|
|
// Low generic simple: class or id only
|
|
|
|
|
// Low generic complex: class or id + extra stuff after
|
|
|
|
|
// High generic:
|
|
|
|
|
// High-low generic: [alt="..."],[title="..."]
|
|
|
|
|
// High-medium generic: [href^="..."]
|
|
|
|
|
// High-high generic: everything else
|
|
|
|
|
// Specific
|
|
|
|
|
// Specfic hostname
|
2014-08-14 19:59:37 +02:00
|
|
|
|
// Specific entity
|
2014-08-12 18:19:54 +02:00
|
|
|
|
// Generic filters can only be enforced once the main document is loaded.
|
|
|
|
|
// Specific filers can be enforced before the main document is loaded.
|
|
|
|
|
|
2014-06-24 00:42:43 +02:00
|
|
|
|
var FilterContainer = function() {
|
2016-09-12 16:22:25 +02:00
|
|
|
|
this.noDomainHash = '-';
|
2014-08-21 16:56:36 +02:00
|
|
|
|
this.parser = new FilterParser();
|
2016-07-10 01:21:46 +02:00
|
|
|
|
this.selectorCachePruneDelay = 10 * 60 * 1000; // 15 minutes
|
|
|
|
|
this.selectorCacheAgeMax = 120 * 60 * 1000; // 120 minutes
|
|
|
|
|
this.selectorCacheCountMin = 25;
|
2016-08-08 15:53:35 +02:00
|
|
|
|
this.netSelectorCacheCountMax = netSelectorCacheHighWaterMark;
|
2014-12-26 21:26:44 +01:00
|
|
|
|
this.selectorCacheTimer = null;
|
2015-03-23 15:40:03 +01:00
|
|
|
|
this.reHasUnicode = /[^\x00-\x7F]/;
|
2016-09-12 16:22:25 +02:00
|
|
|
|
this.reClassOrIdSelector = /^[#.][\w-]+$/;
|
2016-10-30 20:19:58 +01:00
|
|
|
|
this.rePlainSelector = /^[#.][\w\\-]+/;
|
|
|
|
|
this.rePlainSelectorEscaped = /^[#.](?:\\[0-9A-Fa-f]+ |\\.|\w|-)+/;
|
2016-09-12 16:22:25 +02:00
|
|
|
|
this.rePlainSelectorEx = /^[^#.\[(]+([#.][\w-]+)/;
|
2016-10-30 20:19:58 +01:00
|
|
|
|
this.reEscapeSequence = /\\([0-9A-Fa-f]+ |.)/g;
|
2016-09-12 16:22:25 +02:00
|
|
|
|
this.reHighLow = /^[a-z]*\[(?:alt|title)="[^"]+"\]$/;
|
|
|
|
|
this.reHighMedium = /^\[href\^="https?:\/\/([^"]{8})[^"]*"\]$/;
|
|
|
|
|
this.reScriptSelector = /^script:(contains|inject)\((.+)\)$/;
|
2015-03-23 15:40:03 +01:00
|
|
|
|
this.punycode = punycode;
|
2014-07-16 02:32:33 +02:00
|
|
|
|
this.reset();
|
2014-06-24 00:42:43 +02:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
|
|
// Reset all, thus reducing to a minimum memory footprint of the context.
|
|
|
|
|
|
|
|
|
|
FilterContainer.prototype.reset = function() {
|
2014-08-21 16:56:36 +02:00
|
|
|
|
this.parser.reset();
|
2015-02-24 00:31:29 +01:00
|
|
|
|
this.µburi = µb.URI;
|
2014-07-20 21:00:26 +02:00
|
|
|
|
this.frozen = false;
|
2014-06-24 00:42:43 +02:00
|
|
|
|
this.acceptedCount = 0;
|
2016-03-17 18:56:21 +01:00
|
|
|
|
this.discardedCount = 0;
|
2016-09-12 16:22:25 +02:00
|
|
|
|
this.duplicateBuster = new Set();
|
2014-08-12 18:19:54 +02:00
|
|
|
|
|
2014-08-14 02:03:55 +02:00
|
|
|
|
this.selectorCache = {};
|
|
|
|
|
this.selectorCacheCount = 0;
|
2016-03-05 02:25:35 +01:00
|
|
|
|
if ( this.selectorCacheTimer !== null ) {
|
|
|
|
|
clearTimeout(this.selectorCacheTimer);
|
|
|
|
|
this.selectorCacheTimer = null;
|
|
|
|
|
}
|
2014-08-14 02:03:55 +02:00
|
|
|
|
|
2016-08-13 22:42:58 +02:00
|
|
|
|
// generic filters
|
|
|
|
|
this.hasGenericHide = false;
|
|
|
|
|
|
2014-08-12 18:19:54 +02:00
|
|
|
|
// [class], [id]
|
2016-09-12 16:22:25 +02:00
|
|
|
|
this.lowGenericHide = new Set();
|
|
|
|
|
this.lowGenericHideEx = new Map();
|
2016-08-13 22:42:58 +02:00
|
|
|
|
this.lowGenericHideCount = 0;
|
2014-08-12 18:19:54 +02:00
|
|
|
|
|
|
|
|
|
// [alt="..."], [title="..."]
|
|
|
|
|
this.highLowGenericHide = {};
|
|
|
|
|
this.highLowGenericHideCount = 0;
|
2014-10-17 21:44:19 +02:00
|
|
|
|
|
2014-08-12 18:19:54 +02:00
|
|
|
|
// a[href^="http..."]
|
|
|
|
|
this.highMediumGenericHide = {};
|
|
|
|
|
this.highMediumGenericHideCount = 0;
|
|
|
|
|
|
2016-06-29 04:01:15 +02:00
|
|
|
|
// high-high-simple selectors
|
|
|
|
|
this.highHighSimpleGenericHideArray = [];
|
|
|
|
|
this.highHighSimpleGenericHide = '';
|
|
|
|
|
this.highHighSimpleGenericHideCount = 0;
|
|
|
|
|
|
|
|
|
|
// high-high-complex selectors
|
|
|
|
|
this.highHighComplexGenericHideArray = [];
|
|
|
|
|
this.highHighComplexGenericHide = '';
|
|
|
|
|
this.highHighComplexGenericHideCount = 0;
|
2014-08-12 18:19:54 +02:00
|
|
|
|
|
2015-03-13 18:01:46 +01:00
|
|
|
|
// generic exception filters
|
|
|
|
|
this.genericDonthide = [];
|
|
|
|
|
|
2014-09-08 23:46:58 +02:00
|
|
|
|
// hostname, entity-based filters
|
2016-09-12 16:22:25 +02:00
|
|
|
|
this.specificFilters = new Map();
|
2015-09-27 16:13:31 +02:00
|
|
|
|
this.scriptTagFilters = {};
|
|
|
|
|
this.scriptTagFilterCount = 0;
|
2016-09-12 16:22:25 +02:00
|
|
|
|
this.userScripts = new Map();
|
|
|
|
|
this.userScriptCount = 0;
|
2014-06-24 00:42:43 +02:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
2016-08-13 22:42:58 +02:00
|
|
|
|
FilterContainer.prototype.freeze = function() {
|
2016-09-12 16:22:25 +02:00
|
|
|
|
this.duplicateBuster = new Set();
|
2016-08-13 22:42:58 +02:00
|
|
|
|
|
|
|
|
|
if ( this.highHighSimpleGenericHide !== '' ) {
|
|
|
|
|
this.highHighSimpleGenericHideArray.unshift(this.highHighSimpleGenericHide);
|
|
|
|
|
}
|
|
|
|
|
this.highHighSimpleGenericHide = this.highHighSimpleGenericHideArray.join(',\n');
|
|
|
|
|
this.highHighSimpleGenericHideArray = [];
|
|
|
|
|
|
|
|
|
|
if ( this.highHighComplexGenericHide !== '' ) {
|
|
|
|
|
this.highHighComplexGenericHideArray.unshift(this.highHighComplexGenericHide);
|
|
|
|
|
}
|
|
|
|
|
this.highHighComplexGenericHide = this.highHighComplexGenericHideArray.join(',\n');
|
|
|
|
|
this.highHighComplexGenericHideArray = [];
|
|
|
|
|
|
|
|
|
|
this.hasGenericHide = this.lowGenericHideCount !== 0 ||
|
|
|
|
|
this.highLowGenericHideCount !== 0 ||
|
|
|
|
|
this.highMediumGenericHideCount !== 0 ||
|
|
|
|
|
this.highHighSimpleGenericHideCount !== 0 ||
|
|
|
|
|
this.highHighComplexGenericHideCount !== 0;
|
|
|
|
|
|
|
|
|
|
this.parser.reset();
|
|
|
|
|
this.frozen = true;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
2015-04-07 03:26:05 +02:00
|
|
|
|
// https://github.com/chrisaljoudi/uBlock/issues/1004
|
2015-03-17 13:26:35 +01:00
|
|
|
|
// Detect and report invalid CSS selectors.
|
|
|
|
|
|
2016-06-29 23:07:33 +02:00
|
|
|
|
// Discard new ABP's `-abp-properties` directive until it is
|
|
|
|
|
// implemented (if ever). Unlikely, see:
|
|
|
|
|
// https://github.com/gorhill/uBlock/issues/1752
|
|
|
|
|
|
2015-09-08 14:45:22 +02:00
|
|
|
|
FilterContainer.prototype.isValidSelector = (function() {
|
|
|
|
|
var div = document.createElement('div');
|
2016-06-28 01:09:04 +02:00
|
|
|
|
var matchesProp = (function() {
|
|
|
|
|
if ( typeof div.matches === 'function' ) {
|
|
|
|
|
return 'matches';
|
|
|
|
|
}
|
|
|
|
|
if ( typeof div.mozMatchesSelector === 'function' ) {
|
|
|
|
|
return 'mozMatchesSelector';
|
|
|
|
|
}
|
|
|
|
|
if ( typeof div.webkitMatchesSelector === 'function' ) {
|
|
|
|
|
return 'webkitMatchesSelector';
|
|
|
|
|
}
|
|
|
|
|
return '';
|
|
|
|
|
})();
|
2015-09-08 14:45:22 +02:00
|
|
|
|
// Not all browsers support `Element.matches`:
|
|
|
|
|
// http://caniuse.com/#feat=matchesselector
|
2016-06-28 01:09:04 +02:00
|
|
|
|
if ( matchesProp === '' ) {
|
2015-09-08 14:45:22 +02:00
|
|
|
|
return function() {
|
|
|
|
|
return true;
|
|
|
|
|
};
|
|
|
|
|
}
|
2015-03-17 13:26:35 +01:00
|
|
|
|
|
2016-09-12 16:22:25 +02:00
|
|
|
|
var reHasSelector = /^(.+?):has\((.+?)\)$/,
|
2016-12-01 17:55:05 +01:00
|
|
|
|
reMatchesCSSSelector = /^(.+?):matches-css(?:-before|-after)?\((.+?)\)$/,
|
2016-09-12 16:22:25 +02:00
|
|
|
|
reXpathSelector = /^:xpath\((.+?)\)$/,
|
|
|
|
|
reStyleSelector = /^(.+?):style\((.+?)\)$/,
|
|
|
|
|
reStyleBad = /url\([^)]+\)/,
|
|
|
|
|
reScriptSelector = /^script:(contains|inject)\((.+)\)$/;
|
2016-06-28 01:09:04 +02:00
|
|
|
|
|
2016-09-01 21:54:01 +02:00
|
|
|
|
// Keep in mind:
|
|
|
|
|
// https://github.com/gorhill/uBlock/issues/693
|
|
|
|
|
// https://github.com/gorhill/uBlock/issues/1955
|
2016-06-29 23:07:33 +02:00
|
|
|
|
var isValidCSSSelector = function(s) {
|
2015-03-17 13:26:35 +01:00
|
|
|
|
try {
|
2016-09-01 21:54:01 +02:00
|
|
|
|
div[matchesProp](s + ', ' + s + ':not(#foo)');
|
2016-06-29 23:07:33 +02:00
|
|
|
|
} catch (ex) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return function(s) {
|
|
|
|
|
if ( isValidCSSSelector(s) && s.indexOf('[-abp-properties=') === -1 ) {
|
|
|
|
|
return true;
|
2015-03-17 13:26:35 +01:00
|
|
|
|
}
|
2015-12-22 22:32:09 +01:00
|
|
|
|
// We reach this point very rarely.
|
2016-06-28 01:09:04 +02:00
|
|
|
|
var matches;
|
|
|
|
|
|
|
|
|
|
// Future `:has`-based filter? If so, validate both parts of the whole
|
|
|
|
|
// selector.
|
|
|
|
|
matches = reHasSelector.exec(s);
|
|
|
|
|
if ( matches !== null ) {
|
2016-08-03 14:06:51 +02:00
|
|
|
|
return isValidCSSSelector(matches[1]) && isValidCSSSelector(matches[2]);
|
2016-06-28 01:09:04 +02:00
|
|
|
|
}
|
2016-08-03 15:20:55 +02:00
|
|
|
|
// Custom `:matches-css`-based filter?
|
|
|
|
|
matches = reMatchesCSSSelector.exec(s);
|
|
|
|
|
if ( matches !== null ) {
|
|
|
|
|
return isValidCSSSelector(matches[1]);
|
|
|
|
|
}
|
2016-06-28 01:09:04 +02:00
|
|
|
|
// Custom `:xpath`-based filter?
|
|
|
|
|
matches = reXpathSelector.exec(s);
|
|
|
|
|
if ( matches !== null ) {
|
|
|
|
|
try {
|
|
|
|
|
return document.createExpression(matches[1], null) instanceof XPathExpression;
|
|
|
|
|
} catch (e) {
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2016-06-29 23:07:33 +02:00
|
|
|
|
// `:style` selector?
|
|
|
|
|
matches = reStyleSelector.exec(s);
|
|
|
|
|
if ( matches !== null ) {
|
2016-07-18 21:43:03 +02:00
|
|
|
|
return isValidCSSSelector(matches[1]) && reStyleBad.test(matches[2]) === false;
|
2016-06-29 23:07:33 +02:00
|
|
|
|
}
|
2016-06-28 01:09:04 +02:00
|
|
|
|
// Special `script:` filter?
|
2016-09-12 16:22:25 +02:00
|
|
|
|
matches = reScriptSelector.exec(s);
|
|
|
|
|
if ( matches !== null ) {
|
|
|
|
|
if ( matches[1] === 'inject' ) {
|
2015-12-22 22:32:09 +01:00
|
|
|
|
return true;
|
|
|
|
|
}
|
2016-09-12 16:22:25 +02:00
|
|
|
|
return matches[2].startsWith('/') === false ||
|
|
|
|
|
matches[2].endsWith('/') === false ||
|
|
|
|
|
isBadRegex(matches[2].slice(1, -1)) === false;
|
2015-09-27 01:07:23 +02:00
|
|
|
|
}
|
2016-03-27 15:24:57 +02:00
|
|
|
|
µb.logger.writeOne('', 'error', 'Cosmetic filtering – invalid filter: ' + s);
|
2015-09-27 01:07:23 +02:00
|
|
|
|
return false;
|
2015-03-17 13:26:35 +01:00
|
|
|
|
};
|
2015-09-08 14:45:22 +02:00
|
|
|
|
})();
|
2015-03-17 13:26:35 +01:00
|
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
2016-10-30 20:19:58 +01:00
|
|
|
|
// https://github.com/gorhill/uBlock/issues/1668
|
|
|
|
|
// The key must be literal: unescape escaped CSS before extracting key.
|
|
|
|
|
// It's an uncommon case, so it's best to unescape only when needed.
|
|
|
|
|
|
|
|
|
|
FilterContainer.prototype.keyFromSelector = function(selector) {
|
|
|
|
|
var matches = this.rePlainSelector.exec(selector);
|
|
|
|
|
if ( matches === null ) { return; }
|
|
|
|
|
var key = matches[0];
|
|
|
|
|
if ( key.indexOf('\\') === -1 ) {
|
|
|
|
|
return key;
|
|
|
|
|
}
|
|
|
|
|
key = '';
|
|
|
|
|
matches = this.rePlainSelectorEscaped.exec(selector);
|
|
|
|
|
if ( matches === null ) { return; }
|
|
|
|
|
var escaped = matches[0],
|
|
|
|
|
beg = 0;
|
|
|
|
|
this.reEscapeSequence.lastIndex = 0;
|
|
|
|
|
for (;;) {
|
|
|
|
|
matches = this.reEscapeSequence.exec(escaped);
|
|
|
|
|
if ( matches === null ) {
|
|
|
|
|
return key + escaped.slice(beg);
|
|
|
|
|
}
|
|
|
|
|
key += escaped.slice(beg, matches.index);
|
|
|
|
|
beg = this.reEscapeSequence.lastIndex;
|
|
|
|
|
if ( matches[1].length === 1 ) {
|
|
|
|
|
key += matches[1];
|
|
|
|
|
} else {
|
|
|
|
|
key += String.fromCharCode(parseInt(matches[1], 16));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
2015-02-24 00:31:29 +01:00
|
|
|
|
FilterContainer.prototype.compile = function(s, out) {
|
2014-08-21 16:56:36 +02:00
|
|
|
|
var parsed = this.parser.parse(s);
|
2015-03-16 19:58:35 +01:00
|
|
|
|
if ( parsed.cosmetic === false ) {
|
2014-06-24 00:42:43 +02:00
|
|
|
|
return false;
|
|
|
|
|
}
|
2015-03-16 19:58:35 +01:00
|
|
|
|
if ( parsed.invalid ) {
|
2015-11-30 20:47:56 +01:00
|
|
|
|
//console.error("uBlock Origin> discarding invalid cosmetic filter '%s'", s);
|
2015-03-16 19:58:35 +01:00
|
|
|
|
return true;
|
|
|
|
|
}
|
2014-06-24 00:42:43 +02:00
|
|
|
|
|
2014-08-12 18:19:54 +02:00
|
|
|
|
var hostnames = parsed.hostnames;
|
|
|
|
|
var i = hostnames.length;
|
|
|
|
|
if ( i === 0 ) {
|
2015-02-24 00:31:29 +01:00
|
|
|
|
this.compileGenericSelector(parsed, out);
|
2015-02-24 05:25:14 +01:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-17 13:26:35 +01:00
|
|
|
|
// For hostname- or entity-based filters, class- or id-based selectors are
|
|
|
|
|
// still the most common, and can easily be tested using a plain regex.
|
|
|
|
|
if (
|
|
|
|
|
this.reClassOrIdSelector.test(parsed.suffix) === false &&
|
|
|
|
|
this.isValidSelector(parsed.suffix) === false
|
|
|
|
|
) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2015-04-07 03:26:05 +02:00
|
|
|
|
// https://github.com/chrisaljoudi/uBlock/issues/151
|
2015-02-24 05:25:14 +01:00
|
|
|
|
// Negated hostname means the filter applies to all non-negated hostnames
|
|
|
|
|
// of same filter OR globally if there is no non-negated hostnames.
|
|
|
|
|
var applyGlobally = true;
|
|
|
|
|
var hostname;
|
|
|
|
|
while ( i-- ) {
|
|
|
|
|
hostname = hostnames[i];
|
2015-12-15 16:40:40 +01:00
|
|
|
|
if ( hostname.startsWith('~') === false ) {
|
2015-02-24 05:25:14 +01:00
|
|
|
|
applyGlobally = false;
|
2014-08-12 18:19:54 +02:00
|
|
|
|
}
|
2016-09-12 16:22:25 +02:00
|
|
|
|
this.compileHostnameSelector(hostname, parsed, out);
|
2014-08-13 02:25:11 +02:00
|
|
|
|
}
|
2015-02-24 05:25:14 +01:00
|
|
|
|
if ( applyGlobally ) {
|
|
|
|
|
this.compileGenericSelector(parsed, out);
|
|
|
|
|
}
|
2015-02-24 00:31:29 +01:00
|
|
|
|
|
2014-08-12 18:19:54 +02:00
|
|
|
|
return true;
|
|
|
|
|
};
|
2014-06-24 00:42:43 +02:00
|
|
|
|
|
2014-08-12 18:19:54 +02:00
|
|
|
|
/******************************************************************************/
|
2014-06-24 00:42:43 +02:00
|
|
|
|
|
2015-02-24 00:31:29 +01:00
|
|
|
|
FilterContainer.prototype.compileGenericSelector = function(parsed, out) {
|
2016-09-12 16:22:25 +02:00
|
|
|
|
if ( parsed.unhide === 0 ) {
|
|
|
|
|
this.compileGenericHideSelector(parsed, out);
|
|
|
|
|
} else {
|
|
|
|
|
this.compileGenericUnhideSelector(parsed, out);
|
2015-03-13 17:26:54 +01:00
|
|
|
|
}
|
2016-09-12 16:22:25 +02:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/******************************************************************************/
|
2015-03-13 17:26:54 +01:00
|
|
|
|
|
2016-09-12 16:22:25 +02:00
|
|
|
|
FilterContainer.prototype.compileGenericHideSelector = function(parsed, out) {
|
|
|
|
|
var selector = parsed.suffix,
|
|
|
|
|
type = selector.charAt(0),
|
2016-10-30 20:19:58 +01:00
|
|
|
|
key, matches;
|
2015-02-24 00:31:29 +01:00
|
|
|
|
|
|
|
|
|
if ( type === '#' || type === '.' ) {
|
2016-10-30 20:19:58 +01:00
|
|
|
|
key = this.keyFromSelector(selector);
|
|
|
|
|
if ( key === undefined ) { return; }
|
2015-03-17 13:26:35 +01:00
|
|
|
|
// Single-CSS rule: no need to test for whether the selector
|
|
|
|
|
// is valid, the regex took care of this. Most generic selector falls
|
|
|
|
|
// into that category.
|
2016-10-30 20:19:58 +01:00
|
|
|
|
if ( key === selector ) {
|
|
|
|
|
out.push('c\vlg\v' + key);
|
2015-03-17 13:26:35 +01:00
|
|
|
|
return;
|
|
|
|
|
}
|
2016-10-30 20:19:58 +01:00
|
|
|
|
// Composite CSS rule.
|
2015-03-17 13:26:35 +01:00
|
|
|
|
if ( this.isValidSelector(selector) ) {
|
2016-10-30 20:19:58 +01:00
|
|
|
|
out.push('c\vlg+\v' + key + '\v' + selector);
|
2015-03-17 13:26:35 +01:00
|
|
|
|
}
|
2015-02-24 00:31:29 +01:00
|
|
|
|
return;
|
2014-08-12 18:19:54 +02:00
|
|
|
|
}
|
2015-02-24 00:31:29 +01:00
|
|
|
|
|
2015-11-19 15:36:15 +01:00
|
|
|
|
if ( this.isValidSelector(selector) !== true ) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-24 00:31:29 +01:00
|
|
|
|
// ["title"] and ["alt"] will go in high-low generic bin.
|
|
|
|
|
if ( this.reHighLow.test(selector) ) {
|
2015-11-19 15:36:15 +01:00
|
|
|
|
out.push('c\vhlg0\v' + selector);
|
2015-02-24 00:31:29 +01:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// [href^="..."] will go in high-medium generic bin.
|
|
|
|
|
matches = this.reHighMedium.exec(selector);
|
|
|
|
|
if ( matches && matches.length === 2 ) {
|
2016-09-12 16:22:25 +02:00
|
|
|
|
out.push('c\vhmg0\v' + matches[1] + '\v' + selector);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// script:contains(...)
|
|
|
|
|
// script:inject(...)
|
|
|
|
|
if ( this.reScriptSelector.test(selector) ) {
|
|
|
|
|
out.push('c\vjs\v0\v\v' + selector);
|
2015-02-24 00:31:29 +01:00
|
|
|
|
return;
|
2014-08-06 17:34:59 +02:00
|
|
|
|
}
|
2015-02-24 00:31:29 +01:00
|
|
|
|
|
2015-11-19 15:36:15 +01:00
|
|
|
|
// https://github.com/gorhill/uBlock/issues/909
|
|
|
|
|
// Anything which contains a plain id/class selector can be classified
|
|
|
|
|
// as a low generic cosmetic filter.
|
|
|
|
|
matches = this.rePlainSelectorEx.exec(selector);
|
|
|
|
|
if ( matches && matches.length === 2 ) {
|
2016-09-12 16:22:25 +02:00
|
|
|
|
out.push('c\vlg+\v' + matches[1] + '\v' + selector);
|
2015-11-19 15:36:15 +01:00
|
|
|
|
return;
|
2015-03-17 13:26:35 +01:00
|
|
|
|
}
|
2015-11-19 15:36:15 +01:00
|
|
|
|
|
2016-06-29 04:01:15 +02:00
|
|
|
|
// All else: high-high generics.
|
|
|
|
|
// Distinguish simple vs complex selectors.
|
|
|
|
|
if ( selector.indexOf(' ') === -1 ) {
|
|
|
|
|
out.push('c\vhhsg0\v' + selector);
|
|
|
|
|
} else {
|
|
|
|
|
out.push('c\vhhcg0\v' + selector);
|
|
|
|
|
}
|
2014-08-12 18:19:54 +02:00
|
|
|
|
};
|
2014-08-06 17:34:59 +02:00
|
|
|
|
|
2016-09-12 16:22:25 +02:00
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
|
|
FilterContainer.prototype.compileGenericUnhideSelector = function(parsed, out) {
|
|
|
|
|
var selector = parsed.suffix;
|
|
|
|
|
|
|
|
|
|
if ( this.isValidSelector(selector) !== true ) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// script:contains(...)
|
|
|
|
|
// script:inject(...)
|
|
|
|
|
if ( this.reScriptSelector.test(selector) ) {
|
|
|
|
|
out.push('c\vjs\v1\v\v' + selector);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// https://github.com/chrisaljoudi/uBlock/issues/497
|
|
|
|
|
// All generic exception filters are put in the same bucket: they are
|
|
|
|
|
// expected to be very rare.
|
|
|
|
|
out.push('c\vg1\v' + selector);
|
|
|
|
|
};
|
2015-02-24 00:31:29 +01:00
|
|
|
|
|
2014-08-12 18:19:54 +02:00
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
2015-02-24 00:31:29 +01:00
|
|
|
|
FilterContainer.prototype.compileHostnameSelector = function(hostname, parsed, out) {
|
2015-04-07 03:26:05 +02:00
|
|
|
|
// https://github.com/chrisaljoudi/uBlock/issues/145
|
2014-08-12 18:19:54 +02:00
|
|
|
|
var unhide = parsed.unhide;
|
2015-12-15 16:40:40 +01:00
|
|
|
|
if ( hostname.startsWith('~') ) {
|
2014-08-12 18:19:54 +02:00
|
|
|
|
hostname = hostname.slice(1);
|
|
|
|
|
unhide ^= 1;
|
2014-06-24 00:42:43 +02:00
|
|
|
|
}
|
2015-03-23 15:40:03 +01:00
|
|
|
|
|
|
|
|
|
// punycode if needed
|
|
|
|
|
if ( this.reHasUnicode.test(hostname) ) {
|
|
|
|
|
hostname = this.punycode.toASCII(hostname);
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-12 16:22:25 +02:00
|
|
|
|
var domain = this.µburi.domainFromHostname(hostname),
|
|
|
|
|
hash;
|
|
|
|
|
|
|
|
|
|
// script:contains(...)
|
|
|
|
|
// script:inject(...)
|
|
|
|
|
if ( this.reScriptSelector.test(parsed.suffix) ) {
|
|
|
|
|
hash = domain !== '' ? domain : this.noDomainHash;
|
|
|
|
|
if ( unhide ) {
|
|
|
|
|
hash = '!' + hash;
|
|
|
|
|
}
|
|
|
|
|
out.push('c\vjs\v' + hash + '\v' + hostname + '\v' + parsed.suffix);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2015-04-07 03:26:05 +02:00
|
|
|
|
// https://github.com/chrisaljoudi/uBlock/issues/188
|
2015-02-24 00:31:29 +01:00
|
|
|
|
// If not a real domain as per PSL, assign a synthetic one
|
2016-09-12 16:22:25 +02:00
|
|
|
|
if ( hostname.endsWith('.*') === false ) {
|
|
|
|
|
hash = domain !== '' ? makeHash(domain) : this.noDomainHash;
|
2014-08-12 18:19:54 +02:00
|
|
|
|
} else {
|
2016-09-12 16:22:25 +02:00
|
|
|
|
hash = makeHash(hostname);
|
|
|
|
|
}
|
|
|
|
|
if ( unhide ) {
|
|
|
|
|
hash = '!' + hash;
|
|
|
|
|
}
|
2014-08-12 18:19:54 +02:00
|
|
|
|
|
2016-09-12 16:22:25 +02:00
|
|
|
|
out.push('c\vh\v' + hash + '\v' + hostname + '\v' + parsed.suffix);
|
2014-08-14 19:59:37 +02:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
2016-08-13 22:42:58 +02:00
|
|
|
|
FilterContainer.prototype.fromCompiledContent = function(lineIter, skipGenericCosmetic, skipCosmetic) {
|
|
|
|
|
if ( skipCosmetic ) {
|
|
|
|
|
this.skipCompiledContent(lineIter);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if ( skipGenericCosmetic ) {
|
|
|
|
|
this.skipGenericCompiledContent(lineIter);
|
|
|
|
|
return;
|
2014-08-12 18:19:54 +02:00
|
|
|
|
}
|
|
|
|
|
|
2016-09-12 16:22:25 +02:00
|
|
|
|
var line, field0, field1, field2, field3, filter, bucket,
|
|
|
|
|
fieldIter = new µb.FieldIterator('\v');
|
2014-06-24 00:42:43 +02:00
|
|
|
|
|
2016-08-13 22:42:58 +02:00
|
|
|
|
while ( lineIter.eot() === false ) {
|
|
|
|
|
if ( lineIter.text.charCodeAt(lineIter.offset) !== 0x63 /* 'c' */ ) {
|
|
|
|
|
return;
|
2014-08-06 17:34:59 +02:00
|
|
|
|
}
|
2016-09-12 16:22:25 +02:00
|
|
|
|
line = lineIter.next();
|
2014-08-06 17:34:59 +02:00
|
|
|
|
|
2015-02-24 00:31:29 +01:00
|
|
|
|
this.acceptedCount += 1;
|
2016-09-12 16:22:25 +02:00
|
|
|
|
if ( this.duplicateBuster.has(line) ) {
|
2016-03-17 18:56:21 +01:00
|
|
|
|
this.discardedCount += 1;
|
2014-08-14 19:59:37 +02:00
|
|
|
|
continue;
|
|
|
|
|
}
|
2016-09-12 16:22:25 +02:00
|
|
|
|
this.duplicateBuster.add(line);
|
2015-02-24 00:31:29 +01:00
|
|
|
|
|
2016-09-12 16:22:25 +02:00
|
|
|
|
fieldIter.first(line);
|
|
|
|
|
field0 = fieldIter.next();
|
|
|
|
|
field1 = fieldIter.next();
|
2015-02-24 00:31:29 +01:00
|
|
|
|
|
2016-09-12 16:22:25 +02:00
|
|
|
|
// h [\v] hash [\v] example.com [\v] .promoted-tweet
|
|
|
|
|
// h [\v] hash [\v] example.* [\v] .promoted-tweet
|
|
|
|
|
if ( field0 === 'h' ) {
|
|
|
|
|
field2 = fieldIter.next();
|
|
|
|
|
field3 = fieldIter.next();
|
|
|
|
|
filter = new FilterHostname(field3, field2);
|
|
|
|
|
bucket = this.specificFilters.get(field1);
|
2015-02-24 00:31:29 +01:00
|
|
|
|
if ( bucket === undefined ) {
|
2016-09-12 16:22:25 +02:00
|
|
|
|
this.specificFilters.set(field1, filter);
|
2015-02-24 00:31:29 +01:00
|
|
|
|
} else if ( bucket instanceof FilterBucket ) {
|
|
|
|
|
bucket.add(filter);
|
|
|
|
|
} else {
|
2016-09-12 16:22:25 +02:00
|
|
|
|
this.specificFilters.set(field1, new FilterBucket(bucket, filter));
|
2015-02-24 00:31:29 +01:00
|
|
|
|
}
|
|
|
|
|
continue;
|
2014-08-14 19:59:37 +02:00
|
|
|
|
}
|
2014-07-04 22:47:34 +02:00
|
|
|
|
|
2016-09-12 16:22:25 +02:00
|
|
|
|
// lg [\v] .largeAd
|
|
|
|
|
if ( field0 === 'lg' ) {
|
|
|
|
|
bucket = this.lowGenericHideEx.get(field1);
|
2015-02-24 00:31:29 +01:00
|
|
|
|
if ( bucket === undefined ) {
|
2016-09-12 16:22:25 +02:00
|
|
|
|
this.lowGenericHide.add(field1);
|
|
|
|
|
} else if ( Array.isArray(bucket) ) {
|
|
|
|
|
bucket.push(field1);
|
2015-02-24 00:31:29 +01:00
|
|
|
|
} else {
|
2016-09-12 16:22:25 +02:00
|
|
|
|
this.lowGenericHideEx.set(field1, [ bucket, field1 ]);
|
2015-02-24 00:31:29 +01:00
|
|
|
|
}
|
2016-08-13 22:42:58 +02:00
|
|
|
|
this.lowGenericHideCount += 1;
|
2015-02-24 00:31:29 +01:00
|
|
|
|
continue;
|
|
|
|
|
}
|
2014-09-25 21:44:58 +02:00
|
|
|
|
|
2016-09-12 16:22:25 +02:00
|
|
|
|
// lg+ [\v] .Mpopup [\v] .Mpopup + #Mad > #MadZone
|
|
|
|
|
if ( field0 === 'lg+' ) {
|
|
|
|
|
field2 = fieldIter.next();
|
|
|
|
|
bucket = this.lowGenericHideEx.get(field1);
|
2015-02-24 00:31:29 +01:00
|
|
|
|
if ( bucket === undefined ) {
|
2016-09-12 16:22:25 +02:00
|
|
|
|
if ( this.lowGenericHide.has(field1) ) {
|
|
|
|
|
this.lowGenericHideEx.set(field1, [ field1, field2 ]);
|
|
|
|
|
} else {
|
|
|
|
|
this.lowGenericHideEx.set(field1, field2);
|
|
|
|
|
this.lowGenericHide.add(field1);
|
|
|
|
|
}
|
|
|
|
|
} else if ( Array.isArray(bucket) ) {
|
|
|
|
|
bucket.push(field2);
|
2015-02-24 00:31:29 +01:00
|
|
|
|
} else {
|
2016-09-12 16:22:25 +02:00
|
|
|
|
this.lowGenericHideEx.set(field1, [ bucket, field2 ]);
|
2015-02-24 00:31:29 +01:00
|
|
|
|
}
|
2016-09-12 16:22:25 +02:00
|
|
|
|
this.lowGenericHideCount += 1;
|
2015-02-24 00:31:29 +01:00
|
|
|
|
continue;
|
|
|
|
|
}
|
2014-09-25 21:44:58 +02:00
|
|
|
|
|
2016-09-12 16:22:25 +02:00
|
|
|
|
if ( field0 === 'hlg0' ) {
|
|
|
|
|
this.highLowGenericHide[field1] = true;
|
2015-02-24 00:31:29 +01:00
|
|
|
|
this.highLowGenericHideCount += 1;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2014-09-25 21:44:58 +02:00
|
|
|
|
|
2016-09-12 16:22:25 +02:00
|
|
|
|
if ( field0 === 'hmg0' ) {
|
|
|
|
|
field2 = fieldIter.next();
|
|
|
|
|
bucket = this.highMediumGenericHide[field1];
|
2015-09-11 23:59:25 +02:00
|
|
|
|
if ( bucket === undefined ) {
|
2016-09-12 16:22:25 +02:00
|
|
|
|
this.highMediumGenericHide[field1] = field2;
|
2015-09-11 23:59:25 +02:00
|
|
|
|
} else if ( Array.isArray(bucket) ) {
|
2016-09-12 16:22:25 +02:00
|
|
|
|
bucket.push(field2);
|
2015-02-24 00:31:29 +01:00
|
|
|
|
} else {
|
2016-09-12 16:22:25 +02:00
|
|
|
|
this.highMediumGenericHide[field1] = [bucket, field2];
|
2015-02-24 00:31:29 +01:00
|
|
|
|
}
|
|
|
|
|
this.highMediumGenericHideCount += 1;
|
2014-08-12 18:19:54 +02:00
|
|
|
|
continue;
|
|
|
|
|
}
|
2015-02-24 00:31:29 +01:00
|
|
|
|
|
2016-09-12 16:22:25 +02:00
|
|
|
|
if ( field0 === 'hhsg0' ) {
|
|
|
|
|
this.highHighSimpleGenericHideArray.push(field1);
|
2016-06-29 04:01:15 +02:00
|
|
|
|
this.highHighSimpleGenericHideCount += 1;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-12 16:22:25 +02:00
|
|
|
|
if ( field0 === 'hhcg0' ) {
|
|
|
|
|
this.highHighComplexGenericHideArray.push(field1);
|
2016-06-29 04:01:15 +02:00
|
|
|
|
this.highHighComplexGenericHideCount += 1;
|
2015-02-24 00:31:29 +01:00
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-12 16:22:25 +02:00
|
|
|
|
// js [\v] hash [\v] example.com [\v] script:contains(...)
|
|
|
|
|
// js [\v] hash [\v] example.com [\v] script:inject(...)
|
|
|
|
|
if ( field0 === 'js' ) {
|
|
|
|
|
field2 = fieldIter.next();
|
|
|
|
|
field3 = fieldIter.next();
|
|
|
|
|
this.createScriptFilter(field1, field2, field3);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2015-04-07 03:26:05 +02:00
|
|
|
|
// https://github.com/chrisaljoudi/uBlock/issues/497
|
2015-03-13 17:26:54 +01:00
|
|
|
|
// Generic exception filters: expected to be a rare occurrence.
|
2016-09-12 16:22:25 +02:00
|
|
|
|
if ( field0 === 'g1' ) {
|
|
|
|
|
this.genericDonthide.push(field1);
|
2016-08-13 22:42:58 +02:00
|
|
|
|
continue;
|
2015-03-13 17:26:54 +01:00
|
|
|
|
}
|
2016-08-13 22:42:58 +02:00
|
|
|
|
|
|
|
|
|
this.discardedCount += 1;
|
2014-06-24 00:42:43 +02:00
|
|
|
|
}
|
2015-02-24 00:31:29 +01:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/******************************************************************************/
|
2014-09-25 21:44:58 +02:00
|
|
|
|
|
2016-08-13 22:42:58 +02:00
|
|
|
|
FilterContainer.prototype.skipGenericCompiledContent = function(lineIter) {
|
2016-09-12 16:22:25 +02:00
|
|
|
|
var line, field0, field1, field2, field3, filter, bucket,
|
|
|
|
|
fieldIter = new µb.FieldIterator('\v');
|
2016-08-13 22:42:58 +02:00
|
|
|
|
|
|
|
|
|
while ( lineIter.eot() === false ) {
|
|
|
|
|
if ( lineIter.text.charCodeAt(lineIter.offset) !== 0x63 /* 'c' */ ) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2016-09-12 16:22:25 +02:00
|
|
|
|
line = lineIter.next();
|
2016-08-13 22:42:58 +02:00
|
|
|
|
|
|
|
|
|
this.acceptedCount += 1;
|
2016-09-12 16:22:25 +02:00
|
|
|
|
if ( this.duplicateBuster.has(line) ) {
|
2016-08-13 22:42:58 +02:00
|
|
|
|
this.discardedCount += 1;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-12 16:22:25 +02:00
|
|
|
|
fieldIter.first(line);
|
|
|
|
|
field0 = fieldIter.next();
|
|
|
|
|
field1 = fieldIter.next();
|
2016-08-13 22:42:58 +02:00
|
|
|
|
|
2016-09-12 16:22:25 +02:00
|
|
|
|
// h [\v] hash [\v] example.com [\v] .promoted-tweet
|
|
|
|
|
// h [\v] hash [\v] example.* [\v] .promoted-tweet
|
|
|
|
|
if ( field0 === 'h' ) {
|
|
|
|
|
field2 = fieldIter.next();
|
|
|
|
|
field3 = fieldIter.next();
|
|
|
|
|
this.duplicateBuster.add(line);
|
|
|
|
|
filter = new FilterHostname(field3, field2);
|
|
|
|
|
bucket = this.specificFilters.get(field1);
|
2016-08-13 22:42:58 +02:00
|
|
|
|
if ( bucket === undefined ) {
|
2016-09-12 16:22:25 +02:00
|
|
|
|
this.specificFilters.set(field1, filter);
|
2016-08-13 22:42:58 +02:00
|
|
|
|
} else if ( bucket instanceof FilterBucket ) {
|
|
|
|
|
bucket.add(filter);
|
|
|
|
|
} else {
|
2016-09-12 16:22:25 +02:00
|
|
|
|
this.specificFilters.set(field1, new FilterBucket(bucket, filter));
|
2016-08-13 22:42:58 +02:00
|
|
|
|
}
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-12 16:22:25 +02:00
|
|
|
|
// js [\v] hash [\v] example.com [\v] script:contains(...)
|
|
|
|
|
// js [\v] hash [\v] example.com [\v] script:inject(...)
|
|
|
|
|
if ( field0 === 'js' ) {
|
|
|
|
|
field2 = fieldIter.next();
|
|
|
|
|
field3 = fieldIter.next();
|
|
|
|
|
this.duplicateBuster.add(line);
|
|
|
|
|
this.createScriptFilter(field1, field2, field3);
|
2016-08-13 22:42:58 +02:00
|
|
|
|
continue;
|
|
|
|
|
}
|
2014-09-25 21:44:58 +02:00
|
|
|
|
|
2016-08-13 22:42:58 +02:00
|
|
|
|
// https://github.com/chrisaljoudi/uBlock/issues/497
|
|
|
|
|
// Generic exception filters: expected to be a rare occurrence.
|
2016-09-12 16:22:25 +02:00
|
|
|
|
if ( field0 === 'g1' ) {
|
|
|
|
|
this.duplicateBuster.add(line);
|
|
|
|
|
this.genericDonthide.push(field1);
|
2016-08-13 22:42:58 +02:00
|
|
|
|
continue;
|
2015-02-24 00:31:29 +01:00
|
|
|
|
}
|
2016-08-13 22:42:58 +02:00
|
|
|
|
|
|
|
|
|
this.discardedCount += 1;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
|
|
FilterContainer.prototype.skipCompiledContent = function(lineIter) {
|
2016-09-12 16:22:25 +02:00
|
|
|
|
var line, field0, field1, field2, field3,
|
|
|
|
|
fieldIter = new µb.FieldIterator('\v');
|
2016-08-13 22:42:58 +02:00
|
|
|
|
|
|
|
|
|
while ( lineIter.eot() === false ) {
|
|
|
|
|
if ( lineIter.text.charCodeAt(lineIter.offset) !== 0x63 /* 'c' */ ) {
|
|
|
|
|
return;
|
2015-02-24 00:31:29 +01:00
|
|
|
|
}
|
2016-09-12 16:22:25 +02:00
|
|
|
|
line = lineIter.next();
|
2016-08-13 22:42:58 +02:00
|
|
|
|
|
2016-03-17 18:56:21 +01:00
|
|
|
|
this.acceptedCount += 1;
|
2016-09-12 16:22:25 +02:00
|
|
|
|
if ( this.duplicateBuster.has(line) ) {
|
2016-08-13 22:42:58 +02:00
|
|
|
|
this.discardedCount += 1;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-12 16:22:25 +02:00
|
|
|
|
fieldIter.first(line);
|
|
|
|
|
field0 = fieldIter.next();
|
2016-08-13 22:42:58 +02:00
|
|
|
|
|
2016-09-12 16:22:25 +02:00
|
|
|
|
// js [\v] hash [\v] example.com [\v] script:contains(...)
|
|
|
|
|
// js [\v] hash [\v] example.com [\v] script:inject(...)
|
|
|
|
|
if ( field0 === 'js' ) {
|
|
|
|
|
this.duplicateBuster.add(line);
|
|
|
|
|
field1 = fieldIter.next();
|
|
|
|
|
field2 = fieldIter.next();
|
|
|
|
|
field3 = fieldIter.next();
|
|
|
|
|
this.createScriptFilter(field1, field2, field3);
|
2016-08-13 22:42:58 +02:00
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-17 18:56:21 +01:00
|
|
|
|
this.discardedCount += 1;
|
2015-02-24 00:31:29 +01:00
|
|
|
|
}
|
2014-06-24 00:42:43 +02:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
2016-09-12 16:22:25 +02:00
|
|
|
|
FilterContainer.prototype.createScriptFilter = function(hash, hostname, selector) {
|
|
|
|
|
if ( selector.startsWith('script:contains') ) {
|
|
|
|
|
return this.createScriptTagFilter(hash, hostname, selector);
|
2015-12-22 22:32:09 +01:00
|
|
|
|
}
|
2016-09-12 16:22:25 +02:00
|
|
|
|
if ( selector.startsWith('script:inject') ) {
|
|
|
|
|
return this.createUserScriptRule(hash, hostname, selector);
|
2015-12-22 22:32:09 +01:00
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
2016-09-12 16:22:25 +02:00
|
|
|
|
// 0123456789012345678901
|
|
|
|
|
// script:contains(token)
|
|
|
|
|
// ^ ^
|
|
|
|
|
// 16 -1
|
|
|
|
|
|
|
|
|
|
FilterContainer.prototype.createScriptTagFilter = function(hash, hostname, selector) {
|
|
|
|
|
var token = selector.slice(16, -1);
|
|
|
|
|
token = token.startsWith('/') && token.endsWith('/')
|
|
|
|
|
? token.slice(1, -1)
|
|
|
|
|
: token.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
|
|
|
|
2015-09-27 16:13:31 +02:00
|
|
|
|
if ( this.scriptTagFilters.hasOwnProperty(hostname) ) {
|
2016-09-12 16:22:25 +02:00
|
|
|
|
this.scriptTagFilters[hostname] += '|' + token;
|
2015-09-27 16:13:31 +02:00
|
|
|
|
} else {
|
2016-09-12 16:22:25 +02:00
|
|
|
|
this.scriptTagFilters[hostname] = token;
|
2015-09-27 16:13:31 +02:00
|
|
|
|
}
|
2016-09-12 16:22:25 +02:00
|
|
|
|
|
2015-09-27 16:13:31 +02:00
|
|
|
|
this.scriptTagFilterCount += 1;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
2016-09-24 20:36:08 +02:00
|
|
|
|
FilterContainer.prototype.retrieveScriptTagHostnames = function() {
|
|
|
|
|
return Object.keys(this.scriptTagFilters);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
2015-09-27 16:13:31 +02:00
|
|
|
|
FilterContainer.prototype.retrieveScriptTagRegex = function(domain, hostname) {
|
|
|
|
|
if ( this.scriptTagFilterCount === 0 ) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
var out = [], hn = hostname, pos;
|
2016-09-12 16:22:25 +02:00
|
|
|
|
|
|
|
|
|
// Hostname-based
|
2015-09-27 16:13:31 +02:00
|
|
|
|
for (;;) {
|
|
|
|
|
if ( this.scriptTagFilters.hasOwnProperty(hn) ) {
|
|
|
|
|
out.push(this.scriptTagFilters[hn]);
|
|
|
|
|
}
|
|
|
|
|
if ( hn === domain ) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
pos = hn.indexOf('.');
|
|
|
|
|
if ( pos === -1 ) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
hn = hn.slice(pos + 1);
|
|
|
|
|
}
|
2016-09-12 16:22:25 +02:00
|
|
|
|
|
|
|
|
|
// Entity-based
|
2015-09-27 16:13:31 +02:00
|
|
|
|
pos = domain.indexOf('.');
|
|
|
|
|
if ( pos !== -1 ) {
|
2016-09-12 16:22:25 +02:00
|
|
|
|
hn = domain.slice(0, pos) + '.*';
|
2015-09-27 16:13:31 +02:00
|
|
|
|
if ( this.scriptTagFilters.hasOwnProperty(hn) ) {
|
|
|
|
|
out.push(this.scriptTagFilters[hn]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if ( out.length !== 0 ) {
|
|
|
|
|
return out.join('|');
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
2016-09-12 16:22:25 +02:00
|
|
|
|
// userScripts{hash} => FilterHostname | FilterBucket
|
|
|
|
|
|
|
|
|
|
FilterContainer.prototype.createUserScriptRule = function(hash, hostname, selector) {
|
|
|
|
|
var filter = new FilterHostname(selector, hostname);
|
|
|
|
|
var bucket = this.userScripts.get(hash);
|
|
|
|
|
if ( bucket === undefined ) {
|
|
|
|
|
this.userScripts.set(hash, filter);
|
|
|
|
|
} else if ( bucket instanceof FilterBucket ) {
|
|
|
|
|
bucket.add(filter);
|
2015-12-22 22:32:09 +01:00
|
|
|
|
} else {
|
2016-09-12 16:22:25 +02:00
|
|
|
|
this.userScripts.set(hash, new FilterBucket(bucket, filter));
|
2015-12-22 22:32:09 +01:00
|
|
|
|
}
|
2016-09-12 16:22:25 +02:00
|
|
|
|
this.userScriptCount += 1;
|
2015-12-22 22:32:09 +01:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
2016-09-12 16:22:25 +02:00
|
|
|
|
// https://github.com/gorhill/uBlock/issues/1954
|
|
|
|
|
|
|
|
|
|
// 01234567890123456789
|
2016-11-08 21:53:08 +01:00
|
|
|
|
// script:inject(token[, arg[, ...]])
|
|
|
|
|
// ^ ^
|
|
|
|
|
// 14 -1
|
2016-09-12 16:22:25 +02:00
|
|
|
|
|
|
|
|
|
FilterContainer.prototype.retrieveUserScripts = function(domain, hostname) {
|
2016-09-26 19:45:55 +02:00
|
|
|
|
if ( this.userScriptCount === 0 ) { return; }
|
2016-11-03 16:20:47 +01:00
|
|
|
|
if ( µb.hiddenSettings.ignoreScriptInjectFilters === true ) { return; }
|
2016-09-12 16:22:25 +02:00
|
|
|
|
|
2015-12-22 22:32:09 +01:00
|
|
|
|
var reng = µb.redirectEngine;
|
2016-09-26 19:45:55 +02:00
|
|
|
|
if ( !reng ) { return; }
|
2016-09-12 16:22:25 +02:00
|
|
|
|
|
2015-12-22 22:32:09 +01:00
|
|
|
|
var out = [],
|
2016-09-26 19:45:55 +02:00
|
|
|
|
scripts = new Map(),
|
2016-09-12 16:22:25 +02:00
|
|
|
|
pos = domain.indexOf('.'),
|
2016-09-26 19:45:55 +02:00
|
|
|
|
entity = pos !== -1 ? domain.slice(0, pos) + '.*' : '';
|
2016-09-12 16:22:25 +02:00
|
|
|
|
|
|
|
|
|
// Implicit
|
|
|
|
|
var hn = hostname;
|
2015-12-22 22:32:09 +01:00
|
|
|
|
for (;;) {
|
2016-09-26 19:45:55 +02:00
|
|
|
|
this._lookupUserScript(scripts, hn + '.js', reng, out);
|
2016-09-12 16:22:25 +02:00
|
|
|
|
if ( hn === domain ) { break; }
|
2015-12-22 22:32:09 +01:00
|
|
|
|
pos = hn.indexOf('.');
|
2016-09-12 16:22:25 +02:00
|
|
|
|
if ( pos === -1 ) { break; }
|
2015-12-22 22:32:09 +01:00
|
|
|
|
hn = hn.slice(pos + 1);
|
|
|
|
|
}
|
2016-09-26 19:45:55 +02:00
|
|
|
|
if ( entity !== '' ) {
|
|
|
|
|
this._lookupUserScript(scripts, entity + '.js', reng, out);
|
|
|
|
|
}
|
2016-09-12 16:22:25 +02:00
|
|
|
|
|
|
|
|
|
// Explicit (hash is domain).
|
2016-09-26 19:45:55 +02:00
|
|
|
|
var selectors = [], bucket;
|
2016-09-12 16:22:25 +02:00
|
|
|
|
if ( (bucket = this.userScripts.get(domain)) ) {
|
|
|
|
|
bucket.retrieve(hostname, selectors);
|
|
|
|
|
}
|
|
|
|
|
if ( entity !== '' && (bucket = this.userScripts.get(entity)) ) {
|
2016-09-13 21:25:22 +02:00
|
|
|
|
bucket.retrieve(entity, selectors);
|
2016-09-12 16:22:25 +02:00
|
|
|
|
}
|
|
|
|
|
var i = selectors.length;
|
|
|
|
|
while ( i-- ) {
|
2016-11-08 21:53:08 +01:00
|
|
|
|
this._lookupUserScript(scripts, selectors[i].slice(14, -1).trim(), reng, out);
|
2016-09-12 16:22:25 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( out.length === 0 ) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Exceptions should be rare, so we check for exception only if there are
|
|
|
|
|
// scriptlets returned.
|
2016-09-26 19:45:55 +02:00
|
|
|
|
var exceptions = [], j, token;
|
2016-09-12 16:22:25 +02:00
|
|
|
|
if ( (bucket = this.userScripts.get('!' + domain)) ) {
|
|
|
|
|
bucket.retrieve(hostname, exceptions);
|
|
|
|
|
}
|
|
|
|
|
if ( entity !== '' && (bucket = this.userScripts.get('!' + entity)) ) {
|
|
|
|
|
bucket.retrieve(hostname, exceptions);
|
|
|
|
|
}
|
|
|
|
|
i = exceptions.length;
|
|
|
|
|
while ( i-- ) {
|
|
|
|
|
token = exceptions[i].slice(14, -1);
|
2016-09-26 19:45:55 +02:00
|
|
|
|
if ( (j = scripts.get(token)) !== undefined ) {
|
2016-09-12 16:22:25 +02:00
|
|
|
|
out[j] = '// User script "' + token + '" excepted.\n';
|
2015-12-22 22:32:09 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
2016-09-12 16:22:25 +02:00
|
|
|
|
|
2016-01-21 15:04:04 +01:00
|
|
|
|
return out.join('\n');
|
2015-12-22 22:32:09 +01:00
|
|
|
|
};
|
|
|
|
|
|
2016-11-08 21:53:08 +01:00
|
|
|
|
FilterContainer.prototype._lookupUserScript = function(dict, raw, reng, out) {
|
|
|
|
|
if ( dict.has(raw) ) { return; }
|
|
|
|
|
var token, args,
|
|
|
|
|
pos = raw.indexOf(',');
|
|
|
|
|
if ( pos === -1 ) {
|
|
|
|
|
token = raw;
|
|
|
|
|
} else {
|
|
|
|
|
token = raw.slice(0, pos).trim();
|
|
|
|
|
args = raw.slice(pos + 1).trim();
|
|
|
|
|
}
|
2016-09-26 19:45:55 +02:00
|
|
|
|
var content = reng.resourceContentFromName(token, 'application/javascript');
|
2016-11-08 21:53:08 +01:00
|
|
|
|
if ( !content ) { return; }
|
|
|
|
|
if ( args ) {
|
2016-11-09 15:47:44 +01:00
|
|
|
|
content = this._fillupUserScript(content, args);
|
|
|
|
|
if ( !content ) { return; }
|
2016-09-26 19:45:55 +02:00
|
|
|
|
}
|
2016-11-08 21:53:08 +01:00
|
|
|
|
dict.set(raw, out.length);
|
|
|
|
|
out.push(content);
|
2016-09-26 19:45:55 +02:00
|
|
|
|
};
|
|
|
|
|
|
2016-11-09 15:47:44 +01:00
|
|
|
|
// Fill template placeholders. Return falsy if:
|
|
|
|
|
// - At least one argument contains anything else than /\w/ and `.`
|
|
|
|
|
|
|
|
|
|
FilterContainer.prototype._fillupUserScript = function(content, args) {
|
|
|
|
|
var i = 1,
|
|
|
|
|
pos, arg;
|
|
|
|
|
while ( args !== '' ) {
|
|
|
|
|
pos = args.indexOf(',');
|
|
|
|
|
if ( pos === -1 ) { pos = args.length; }
|
2016-11-17 15:25:37 +01:00
|
|
|
|
arg = args.slice(0, pos).trim().replace(this._reEscapeScriptArg, '\\$&');
|
2016-11-09 15:47:44 +01:00
|
|
|
|
content = content.replace('{{' + i + '}}', arg);
|
|
|
|
|
args = args.slice(pos + 1).trim();
|
|
|
|
|
i++;
|
|
|
|
|
}
|
|
|
|
|
return content;
|
|
|
|
|
};
|
|
|
|
|
|
2016-11-17 15:25:37 +01:00
|
|
|
|
FilterContainer.prototype._reEscapeScriptArg = /[\\'"]/g;
|
2016-11-08 22:31:04 +01:00
|
|
|
|
|
2015-12-22 22:32:09 +01:00
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
2014-09-08 23:46:58 +02:00
|
|
|
|
FilterContainer.prototype.toSelfie = function() {
|
2016-09-12 16:22:25 +02:00
|
|
|
|
var selfieFromMap = function(map) {
|
|
|
|
|
var selfie = [],
|
|
|
|
|
entry, bucket, ff, f,
|
|
|
|
|
iterator = map.entries();
|
|
|
|
|
for (;;) {
|
|
|
|
|
entry = iterator.next();
|
|
|
|
|
if ( entry.done ) {
|
|
|
|
|
break;
|
2014-09-08 23:46:58 +02:00
|
|
|
|
}
|
2016-09-12 16:22:25 +02:00
|
|
|
|
selfie.push('k\t' + entry.value[0]);
|
|
|
|
|
bucket = entry.value[1];
|
2014-09-08 23:46:58 +02:00
|
|
|
|
selfie.push(bucket.fid + '\t' + bucket.toSelfie());
|
|
|
|
|
if ( bucket.fid !== '[]' ) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
ff = bucket.filters;
|
2016-09-12 16:22:25 +02:00
|
|
|
|
for ( var j = 0, nj = ff.length; j < nj; j++ ) {
|
|
|
|
|
f = ff[j];
|
2014-09-08 23:46:58 +02:00
|
|
|
|
selfie.push(f.fid + '\t' + f.toSelfie());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return selfie.join('\n');
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
acceptedCount: this.acceptedCount,
|
2016-03-17 18:56:21 +01:00
|
|
|
|
discardedCount: this.discardedCount,
|
2016-09-12 16:22:25 +02:00
|
|
|
|
specificFilters: selfieFromMap(this.specificFilters),
|
2016-08-13 22:42:58 +02:00
|
|
|
|
hasGenericHide: this.hasGenericHide,
|
2016-09-12 16:22:25 +02:00
|
|
|
|
lowGenericHide: µb.setToArray(this.lowGenericHide),
|
|
|
|
|
lowGenericHideEx: µb.mapToArray(this.lowGenericHideEx),
|
2016-08-13 22:42:58 +02:00
|
|
|
|
lowGenericHideCount: this.lowGenericHideCount,
|
2014-09-08 23:46:58 +02:00
|
|
|
|
highLowGenericHide: this.highLowGenericHide,
|
|
|
|
|
highLowGenericHideCount: this.highLowGenericHideCount,
|
|
|
|
|
highMediumGenericHide: this.highMediumGenericHide,
|
|
|
|
|
highMediumGenericHideCount: this.highMediumGenericHideCount,
|
2016-06-29 04:01:15 +02:00
|
|
|
|
highHighSimpleGenericHide: this.highHighSimpleGenericHide,
|
|
|
|
|
highHighSimpleGenericHideCount: this.highHighSimpleGenericHideCount,
|
|
|
|
|
highHighComplexGenericHide: this.highHighComplexGenericHide,
|
|
|
|
|
highHighComplexGenericHideCount: this.highHighComplexGenericHideCount,
|
2015-09-27 16:13:31 +02:00
|
|
|
|
genericDonthide: this.genericDonthide,
|
|
|
|
|
scriptTagFilters: this.scriptTagFilters,
|
2015-12-22 22:32:09 +01:00
|
|
|
|
scriptTagFilterCount: this.scriptTagFilterCount,
|
2016-09-12 16:22:25 +02:00
|
|
|
|
userScripts: selfieFromMap(this.userScripts),
|
|
|
|
|
userScriptCount: this.userScriptCount
|
2014-09-08 23:46:58 +02:00
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
|
|
FilterContainer.prototype.fromSelfie = function(selfie) {
|
|
|
|
|
var factories = {
|
|
|
|
|
'[]': FilterBucket,
|
|
|
|
|
'#': FilterPlain,
|
|
|
|
|
'#+': FilterPlainMore,
|
2016-09-12 16:22:25 +02:00
|
|
|
|
'h': FilterHostname
|
2014-09-08 23:46:58 +02:00
|
|
|
|
};
|
|
|
|
|
|
2016-09-12 16:22:25 +02:00
|
|
|
|
var mapFromSelfie = function(selfie) {
|
|
|
|
|
var map = new Map(),
|
|
|
|
|
key,
|
|
|
|
|
bucket = null,
|
|
|
|
|
rawText = selfie,
|
|
|
|
|
rawEnd = rawText.length,
|
|
|
|
|
lineBeg = 0, lineEnd,
|
|
|
|
|
line, pos, what, factory;
|
2014-09-08 23:46:58 +02:00
|
|
|
|
while ( lineBeg < rawEnd ) {
|
|
|
|
|
lineEnd = rawText.indexOf('\n', lineBeg);
|
|
|
|
|
if ( lineEnd < 0 ) {
|
|
|
|
|
lineEnd = rawEnd;
|
|
|
|
|
}
|
|
|
|
|
line = rawText.slice(lineBeg, lineEnd);
|
|
|
|
|
lineBeg = lineEnd + 1;
|
|
|
|
|
pos = line.indexOf('\t');
|
|
|
|
|
what = line.slice(0, pos);
|
|
|
|
|
if ( what === 'k' ) {
|
2016-09-12 16:22:25 +02:00
|
|
|
|
key = line.slice(pos + 1);
|
2014-09-08 23:46:58 +02:00
|
|
|
|
bucket = null;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
factory = factories[what];
|
|
|
|
|
if ( bucket === null ) {
|
2016-09-12 16:22:25 +02:00
|
|
|
|
bucket = factory.fromSelfie(line.slice(pos + 1));
|
|
|
|
|
map.set(key, bucket);
|
2014-09-08 23:46:58 +02:00
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
// When token key is reused, it can't be anything
|
|
|
|
|
// else than FilterBucket
|
|
|
|
|
bucket.add(factory.fromSelfie(line.slice(pos + 1)));
|
|
|
|
|
}
|
2016-09-12 16:22:25 +02:00
|
|
|
|
return map;
|
2014-09-08 23:46:58 +02:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
this.acceptedCount = selfie.acceptedCount;
|
2016-03-17 18:56:21 +01:00
|
|
|
|
this.discardedCount = selfie.discardedCount;
|
2016-09-12 16:22:25 +02:00
|
|
|
|
this.specificFilters = mapFromSelfie(selfie.specificFilters);
|
2016-08-13 22:42:58 +02:00
|
|
|
|
this.hasGenericHide = selfie.hasGenericHide;
|
2016-09-12 16:22:25 +02:00
|
|
|
|
this.lowGenericHide = µb.setFromArray(selfie.lowGenericHide);
|
|
|
|
|
this.lowGenericHideEx = µb.mapFromArray(selfie.lowGenericHideEx);
|
2016-08-13 22:42:58 +02:00
|
|
|
|
this.lowGenericHideCount = selfie.lowGenericHideCount;
|
2014-09-08 23:46:58 +02:00
|
|
|
|
this.highLowGenericHide = selfie.highLowGenericHide;
|
|
|
|
|
this.highLowGenericHideCount = selfie.highLowGenericHideCount;
|
|
|
|
|
this.highMediumGenericHide = selfie.highMediumGenericHide;
|
|
|
|
|
this.highMediumGenericHideCount = selfie.highMediumGenericHideCount;
|
2016-06-29 04:01:15 +02:00
|
|
|
|
this.highHighSimpleGenericHide = selfie.highHighSimpleGenericHide;
|
|
|
|
|
this.highHighSimpleGenericHideCount = selfie.highHighSimpleGenericHideCount;
|
|
|
|
|
this.highHighComplexGenericHide = selfie.highHighComplexGenericHide;
|
|
|
|
|
this.highHighComplexGenericHideCount = selfie.highHighComplexGenericHideCount;
|
2015-03-13 17:48:40 +01:00
|
|
|
|
this.genericDonthide = selfie.genericDonthide;
|
2015-09-27 16:13:31 +02:00
|
|
|
|
this.scriptTagFilters = selfie.scriptTagFilters;
|
|
|
|
|
this.scriptTagFilterCount = selfie.scriptTagFilterCount;
|
2016-09-12 16:22:25 +02:00
|
|
|
|
this.userScripts = mapFromSelfie(selfie.userScripts);
|
|
|
|
|
this.userScriptCount = selfie.userScriptCount;
|
2015-01-23 21:02:47 +01:00
|
|
|
|
this.frozen = true;
|
2014-09-08 23:46:58 +02:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
2014-12-26 21:26:44 +01:00
|
|
|
|
FilterContainer.prototype.triggerSelectorCachePruner = function() {
|
|
|
|
|
if ( this.selectorCacheTimer !== null ) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if ( this.selectorCacheCount <= this.selectorCacheCountMin ) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
// Of interest: http://fitzgeraldnick.com/weblog/40/
|
|
|
|
|
// http://googlecode.blogspot.ca/2009/07/gmail-for-mobile-html5-series-using.html
|
2015-05-17 19:02:56 +02:00
|
|
|
|
this.selectorCacheTimer = vAPI.setTimeout(
|
2014-12-26 21:26:44 +01:00
|
|
|
|
this.pruneSelectorCacheAsync.bind(this),
|
|
|
|
|
this.selectorCachePruneDelay
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
2014-08-14 19:59:37 +02:00
|
|
|
|
FilterContainer.prototype.addToSelectorCache = function(details) {
|
|
|
|
|
var hostname = details.hostname;
|
2014-08-14 02:03:55 +02:00
|
|
|
|
if ( typeof hostname !== 'string' || hostname === '' ) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2014-08-14 19:59:37 +02:00
|
|
|
|
var selectors = details.selectors;
|
|
|
|
|
if ( !selectors ) {
|
2014-08-14 02:03:55 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
var entry = this.selectorCache[hostname];
|
|
|
|
|
if ( entry === undefined ) {
|
2014-12-26 21:26:44 +01:00
|
|
|
|
entry = this.selectorCache[hostname] = SelectorCacheEntry.factory();
|
2014-08-14 02:03:55 +02:00
|
|
|
|
this.selectorCacheCount += 1;
|
2014-12-26 21:26:44 +01:00
|
|
|
|
this.triggerSelectorCachePruner();
|
2014-08-14 02:03:55 +02:00
|
|
|
|
}
|
2016-10-06 16:49:46 +02:00
|
|
|
|
entry.add(details);
|
2014-08-14 02:03:55 +02:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
2014-12-17 16:47:52 +01:00
|
|
|
|
FilterContainer.prototype.removeFromSelectorCache = function(targetHostname, type) {
|
2015-12-15 16:40:40 +01:00
|
|
|
|
var targetHostnameLength = targetHostname.length;
|
2014-12-17 16:47:52 +01:00
|
|
|
|
for ( var hostname in this.selectorCache ) {
|
|
|
|
|
if ( this.selectorCache.hasOwnProperty(hostname) === false ) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2015-01-06 14:01:15 +01:00
|
|
|
|
if ( targetHostname !== '*' ) {
|
2015-12-15 16:40:40 +01:00
|
|
|
|
if ( hostname.endsWith(targetHostname) === false ) {
|
2015-01-06 14:01:15 +01:00
|
|
|
|
continue;
|
|
|
|
|
}
|
2015-12-15 16:40:40 +01:00
|
|
|
|
if ( hostname.length !== targetHostnameLength &&
|
|
|
|
|
hostname.charAt(hostname.length - targetHostnameLength - 1) !== '.' ) {
|
2015-01-06 14:01:15 +01:00
|
|
|
|
continue;
|
|
|
|
|
}
|
2014-12-17 16:47:52 +01:00
|
|
|
|
}
|
|
|
|
|
this.selectorCache[hostname].remove(type);
|
2014-12-17 16:32:50 +01:00
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
2014-08-14 19:59:37 +02:00
|
|
|
|
FilterContainer.prototype.retrieveFromSelectorCache = function(hostname, type, out) {
|
2014-08-14 02:03:55 +02:00
|
|
|
|
var entry = this.selectorCache[hostname];
|
|
|
|
|
if ( entry === undefined ) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2014-08-14 19:59:37 +02:00
|
|
|
|
entry.retrieve(type, out);
|
2014-08-14 02:03:55 +02:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
2014-12-26 21:26:44 +01:00
|
|
|
|
FilterContainer.prototype.pruneSelectorCacheAsync = function() {
|
|
|
|
|
this.selectorCacheTimer = null;
|
|
|
|
|
if ( this.selectorCacheCount <= this.selectorCacheCountMin ) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2014-08-14 02:03:55 +02:00
|
|
|
|
var cache = this.selectorCache;
|
2014-12-26 21:26:44 +01:00
|
|
|
|
// Sorted from most-recently-used to least-recently-used, because
|
|
|
|
|
// we loop beginning at the end below.
|
|
|
|
|
// We can't avoid sorting because we have to keep a minimum number of
|
|
|
|
|
// entries, and these entries should always be the most-recently-used.
|
|
|
|
|
var hostnames = Object.keys(cache)
|
|
|
|
|
.sort(function(a, b) { return cache[b].lastAccessTime - cache[a].lastAccessTime; })
|
|
|
|
|
.slice(this.selectorCacheCountMin);
|
|
|
|
|
var obsolete = Date.now() - this.selectorCacheAgeMax;
|
|
|
|
|
var hostname, entry;
|
|
|
|
|
var i = hostnames.length;
|
2014-08-14 02:03:55 +02:00
|
|
|
|
while ( i-- ) {
|
2014-12-26 21:26:44 +01:00
|
|
|
|
hostname = hostnames[i];
|
|
|
|
|
entry = cache[hostname];
|
|
|
|
|
if ( entry.lastAccessTime > obsolete ) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
// console.debug('pruneSelectorCacheAsync: flushing "%s"', hostname);
|
|
|
|
|
entry.dispose();
|
|
|
|
|
delete cache[hostname];
|
2014-12-27 19:42:47 +01:00
|
|
|
|
this.selectorCacheCount -= 1;
|
2014-08-14 02:03:55 +02:00
|
|
|
|
}
|
2014-12-26 21:26:44 +01:00
|
|
|
|
this.triggerSelectorCachePruner();
|
2014-08-14 02:03:55 +02:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
2014-08-02 17:40:27 +02:00
|
|
|
|
FilterContainer.prototype.retrieveGenericSelectors = function(request) {
|
2014-12-19 20:06:55 +01:00
|
|
|
|
if ( this.acceptedCount === 0 ) {
|
2014-06-24 00:42:43 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if ( !request.selectors ) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//quickProfiler.start('FilterContainer.retrieve()');
|
|
|
|
|
|
|
|
|
|
var r = {
|
2015-03-13 22:05:28 +01:00
|
|
|
|
hide: []
|
2014-06-24 00:42:43 +02:00
|
|
|
|
};
|
|
|
|
|
|
2015-03-13 22:05:28 +01:00
|
|
|
|
if ( request.firstSurvey ) {
|
2014-08-12 18:19:54 +02:00
|
|
|
|
r.highGenerics = {
|
|
|
|
|
hideLow: this.highLowGenericHide,
|
|
|
|
|
hideLowCount: this.highLowGenericHideCount,
|
|
|
|
|
hideMedium: this.highMediumGenericHide,
|
|
|
|
|
hideMediumCount: this.highMediumGenericHideCount,
|
2016-06-29 04:01:15 +02:00
|
|
|
|
hideHighSimple: this.highHighSimpleGenericHide,
|
|
|
|
|
hideHighSimpleCount: this.highHighSimpleGenericHideCount,
|
|
|
|
|
hideHighComplex: this.highHighComplexGenericHide,
|
|
|
|
|
hideHighComplexCount: this.highHighComplexGenericHideCount
|
2014-08-12 18:19:54 +02:00
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-12 16:22:25 +02:00
|
|
|
|
var hideSelectors = r.hide,
|
|
|
|
|
selectors = request.selectors,
|
|
|
|
|
i = selectors.length,
|
|
|
|
|
selector, bucket;
|
2014-06-24 00:42:43 +02:00
|
|
|
|
while ( i-- ) {
|
2016-09-12 16:22:25 +02:00
|
|
|
|
selector = selectors[i];
|
|
|
|
|
if ( this.lowGenericHide.has(selector) === false ) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if ( (bucket = this.lowGenericHideEx.get(selector)) ) {
|
|
|
|
|
if ( Array.isArray(bucket) ) {
|
|
|
|
|
hideSelectors = hideSelectors.concat(bucket);
|
|
|
|
|
} else {
|
|
|
|
|
hideSelectors.push(bucket);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
hideSelectors.push(selector);
|
2014-06-24 00:42:43 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
2016-09-12 16:22:25 +02:00
|
|
|
|
r.hide = hideSelectors;
|
2014-06-24 00:42:43 +02:00
|
|
|
|
|
|
|
|
|
//quickProfiler.stop();
|
|
|
|
|
|
|
|
|
|
return r;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
2016-08-12 14:55:35 +02:00
|
|
|
|
FilterContainer.prototype.retrieveDomainSelectors = function(request, noCosmeticFiltering) {
|
2014-06-24 00:42:43 +02:00
|
|
|
|
if ( !request.locationURL ) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//quickProfiler.start('FilterContainer.retrieve()');
|
|
|
|
|
|
2016-08-12 14:55:35 +02:00
|
|
|
|
var hostname = this.µburi.hostnameFromURI(request.locationURL),
|
|
|
|
|
domain = this.µburi.domainFromHostname(hostname) || hostname,
|
|
|
|
|
pos = domain.indexOf('.'),
|
2016-09-12 16:22:25 +02:00
|
|
|
|
entity = pos === -1 ? '' : domain.slice(0, pos - domain.length) + '.*',
|
2016-08-12 14:55:35 +02:00
|
|
|
|
cacheEntry = this.selectorCache[hostname];
|
2014-08-14 19:59:37 +02:00
|
|
|
|
|
2015-04-07 03:26:05 +02:00
|
|
|
|
// https://github.com/chrisaljoudi/uBlock/issues/587
|
2015-01-23 21:02:47 +01:00
|
|
|
|
// r.ready will tell the content script the cosmetic filtering engine is
|
|
|
|
|
// up and ready.
|
|
|
|
|
|
2016-06-28 01:09:04 +02:00
|
|
|
|
// https://github.com/chrisaljoudi/uBlock/issues/497
|
|
|
|
|
// Generic exception filters are to be applied on all pages.
|
|
|
|
|
|
2014-06-24 00:42:43 +02:00
|
|
|
|
var r = {
|
2015-01-23 21:02:47 +01:00
|
|
|
|
ready: this.frozen,
|
2014-08-14 19:59:37 +02:00
|
|
|
|
domain: domain,
|
2016-09-12 16:22:25 +02:00
|
|
|
|
entity: entity,
|
2016-08-13 22:42:58 +02:00
|
|
|
|
noDOMSurveying: this.hasGenericHide === false,
|
2014-08-14 19:59:37 +02:00
|
|
|
|
cosmeticHide: [],
|
2016-08-12 14:55:35 +02:00
|
|
|
|
cosmeticDonthide: [],
|
2014-08-14 19:59:37 +02:00
|
|
|
|
netHide: [],
|
2016-09-12 16:22:25 +02:00
|
|
|
|
scripts: undefined
|
2014-06-24 00:42:43 +02:00
|
|
|
|
};
|
2014-06-24 01:23:36 +02:00
|
|
|
|
|
2016-08-12 14:55:35 +02:00
|
|
|
|
if ( !noCosmeticFiltering ) {
|
|
|
|
|
var hash, bucket;
|
2016-09-12 16:22:25 +02:00
|
|
|
|
|
|
|
|
|
// Generic exception cosmetic filters.
|
|
|
|
|
r.cosmeticDonthide = this.genericDonthide.slice();
|
|
|
|
|
|
|
|
|
|
// Specific cosmetic filters.
|
|
|
|
|
hash = makeHash(domain);
|
|
|
|
|
if ( (bucket = this.specificFilters.get(hash)) ) {
|
2016-08-12 14:55:35 +02:00
|
|
|
|
bucket.retrieve(hostname, r.cosmeticHide);
|
|
|
|
|
}
|
2016-09-12 16:22:25 +02:00
|
|
|
|
// Specific exception cosmetic filters.
|
|
|
|
|
if ( (bucket = this.specificFilters.get('!' + hash)) ) {
|
|
|
|
|
bucket.retrieve(hostname, r.cosmeticDonthide);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Specific entity-based cosmetic filters.
|
|
|
|
|
if ( entity !== '' ) {
|
|
|
|
|
// Specific entity-based cosmetic filters.
|
|
|
|
|
hash = makeHash(entity);
|
|
|
|
|
if ( (bucket = this.specificFilters.get(hash)) ) {
|
|
|
|
|
bucket.retrieve(entity, r.cosmeticHide);
|
|
|
|
|
}
|
|
|
|
|
// Specific entity-based exception cosmetic filters.
|
|
|
|
|
//if ( (bucket = this.specificFilters.get('!' + hash)) ) {
|
|
|
|
|
// bucket.retrieve(entity, r.cosmeticHide);
|
|
|
|
|
//}
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-12 14:55:35 +02:00
|
|
|
|
// https://github.com/chrisaljoudi/uBlock/issues/188
|
|
|
|
|
// Special bucket for those filters without a valid domain name as per PSL
|
2016-09-12 16:22:25 +02:00
|
|
|
|
if ( (bucket = this.specificFilters.get(this.noDomainHash)) ) {
|
2016-08-12 14:55:35 +02:00
|
|
|
|
bucket.retrieve(hostname, r.cosmeticHide);
|
|
|
|
|
}
|
2016-09-12 16:22:25 +02:00
|
|
|
|
if ( (bucket = this.specificFilters.get('!' + this.noDomainHash)) ) {
|
|
|
|
|
bucket.retrieve(hostname, r.cosmeticDonthide);
|
2016-08-12 14:55:35 +02:00
|
|
|
|
}
|
2015-02-24 00:31:29 +01:00
|
|
|
|
|
2016-08-12 14:55:35 +02:00
|
|
|
|
// cached cosmetic filters.
|
|
|
|
|
if ( cacheEntry ) {
|
|
|
|
|
cacheEntry.retrieve('cosmetic', r.cosmeticHide);
|
2016-08-13 22:42:58 +02:00
|
|
|
|
if ( r.noDOMSurveying === false ) {
|
|
|
|
|
r.noDOMSurveying = cacheEntry.cosmeticSurveyingMissCount > cosmeticSurveyingMissCountMax;
|
|
|
|
|
}
|
2016-08-12 14:55:35 +02:00
|
|
|
|
}
|
2014-08-27 19:50:18 +02:00
|
|
|
|
}
|
2014-06-24 00:42:43 +02:00
|
|
|
|
|
2016-09-12 16:22:25 +02:00
|
|
|
|
// Scriptlet injection.
|
|
|
|
|
r.scripts = this.retrieveUserScripts(domain, hostname);
|
|
|
|
|
|
2016-08-12 14:55:35 +02:00
|
|
|
|
// Collapsible blocked resources.
|
2016-07-10 01:21:46 +02:00
|
|
|
|
if ( cacheEntry ) {
|
|
|
|
|
cacheEntry.retrieve('net', r.netHide);
|
|
|
|
|
}
|
2014-08-14 02:03:55 +02:00
|
|
|
|
|
2014-06-24 00:42:43 +02:00
|
|
|
|
//quickProfiler.stop();
|
|
|
|
|
|
|
|
|
|
return r;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
|
|
FilterContainer.prototype.getFilterCount = function() {
|
2016-03-17 18:56:21 +01:00
|
|
|
|
return this.acceptedCount - this.discardedCount;
|
2014-06-24 00:42:43 +02:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
|
|
return new FilterContainer();
|
|
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
|
|
})();
|
|
|
|
|
|
|
|
|
|
/******************************************************************************/
|