Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: assets/js/FilterClasses.jsm

Issue 6590816134889472: Noissue - Removed unused assets (Closed)
Patch Set: Created Oct. 14, 2014, 9:51 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « assets/js/ElemHide.jsm ('k') | assets/js/FilterListener.jsm » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * This file is part of Adblock Plus <http://adblockplus.org/>,
3 * Copyright (C) 2006-2014 Eyeo GmbH
4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation.
8 *
9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18
19 //
20 // This file has been generated automatically from Adblock Plus source code
21 //
22
23 (function (_patchFunc2) {
24 function Filter(text) {
25 this.text = text;
26 this.subscriptions = [];
27 }
28 Filter.prototype = {
29 text: null,
30 subscriptions: null,
31 serialize: function (buffer) {
32 buffer.push("[Filter]");
33 buffer.push("text=" + this.text);
34 }
35 ,
36 toString: function () {
37 return this.text;
38 }
39
40 };
41 Filter.knownFilters = {
42 __proto__: null
43 };
44 Filter.elemhideRegExp = /^([^\/\*\|\@"!]*?)#(?:([\w\-]+|\*)((?:\([\w\-]+(?:[$^ *]?=[^\(\)"]*)?\))*)|#([^{}]+))$/;
45 Filter.regexpRegExp = /^(@@)?\/.*\/(?:\$~?[\w\-]+(?:=[^,\s]+)?(?:,~?[\w\-]+(?: =[^,\s]+)?)*)?$/;
46 Filter.optionsRegExp = /\$(~?[\w\-]+(?:=[^,\s]+)?(?:,~?[\w\-]+(?:=[^,\s]+)?)*) $/;
47 Filter.fromText = (function (text) {
48 if (text in Filter.knownFilters)
49 return Filter.knownFilters[text];
50 if (!/\S/.test(text))
51 return null;
52 var ret;
53 if (Filter.elemhideRegExp.test(text))
54 ret = ElemHideFilter.fromText(text, RegExp["$1"], RegExp["$2"], RegExp["$3 "], RegExp["$4"]);
55 else
56 if (text[0] == "!")
57 ret = new CommentFilter(text);
58 else
59 ret = RegExpFilter.fromText(text);
60 Filter.knownFilters[ret.text] = ret;
61 return ret;
62 }
63 );
64 Filter.fromObject = (function (obj) {
65 var ret = Filter.fromText(obj.text);
66 if (ret instanceof ActiveFilter) {
67 if ("disabled" in obj)
68 ret._disabled = (obj.disabled == "true");
69 if ("hitCount" in obj)
70 ret._hitCount = parseInt(obj.hitCount) || 0;
71 if ("lastHit" in obj)
72 ret._lastHit = parseInt(obj.lastHit) || 0;
73 }
74 return ret;
75 }
76 );
77 Filter.normalize = (function (text) {
78 if (!text)
79 return text;
80 text = text.replace(/[^\S ]/g, "");
81 if (/^\s*!/.test(text)) {
82 return text.replace(/^\s+/, "").replace(/\s+$/, "");
83 }
84 else
85 if (Filter.elemhideRegExp.test(text)) {
86 /^(.*?)(#+)(.*)$/.test(text);
87 var domain = RegExp["$1"];
88 var separator = RegExp["$2"];
89 var selector = RegExp["$3"];
90 return domain.replace(/\s/g, "") + separator + selector.replace(/^\s+/, "").replace(/\s+$/, "");
91 }
92 else
93 return text.replace(/\s/g, "");
94 }
95 );
96 function InvalidFilter(text, reason) {
97 Filter.call(this, text);
98 this.reason = reason;
99 }
100 InvalidFilter.prototype = {
101 __proto__: Filter.prototype,
102 reason: null,
103 serialize: function (buffer) {}
104 };
105 function CommentFilter(text) {
106 Filter.call(this, text);
107 }
108 CommentFilter.prototype = {
109 __proto__: Filter.prototype,
110 serialize: function (buffer) {}
111 };
112 function ActiveFilter(text, domains) {
113 Filter.call(this, text);
114 if (domains) {
115 this.domainSource = domains;
116 this.__defineGetter__("domains", this._getDomains);
117 }
118 }
119 ActiveFilter.prototype = {
120 __proto__: Filter.prototype,
121 _disabled: false,
122 _hitCount: 0,
123 _lastHit: 0,
124 get disabled() {
125 return this._disabled;
126 },
127 set disabled(value) {
128 if (value != this._disabled) {
129 var oldValue = this._disabled;
130 this._disabled = value;
131 FilterNotifier.triggerListeners("filter.disabled", this, value, oldValue );
132 }
133 return this._disabled;
134 }
135 ,
136 get hitCount() {
137 return this._hitCount;
138 },
139 set hitCount(value) {
140 if (value != this._hitCount) {
141 var oldValue = this._hitCount;
142 this._hitCount = value;
143 FilterNotifier.triggerListeners("filter.hitCount", this, value, oldValue );
144 }
145 return this._hitCount;
146 }
147 ,
148 get lastHit() {
149 return this._lastHit;
150 },
151 set lastHit(value) {
152 if (value != this._lastHit) {
153 var oldValue = this._lastHit;
154 this._lastHit = value;
155 FilterNotifier.triggerListeners("filter.lastHit", this, value, oldValue) ;
156 }
157 return this._lastHit;
158 }
159 ,
160 domainSource: null,
161 domainSeparator: null,
162 domains: null,
163 _getDomains: function () {
164 this._generateDomains();
165 return this.domains;
166 }
167 ,
168 _generateDomains: function () {
169 var domains = this.domainSource.split(this.domainSeparator);
170 delete this.domainSource;
171 delete this.domains;
172 if (domains.length == 1 && domains[0][0] != "~") {
173 this.domains = {
174 __proto__: null,
175 "": false
176 };
177 this.domains[domains[0]] = true;
178 }
179 else {
180 var hasIncludes = false;
181 for (var i = 0;
182 i < domains.length; i++) {
183 var domain = domains[i];
184 if (domain == "")
185 continue;
186 var include;
187 if (domain[0] == "~") {
188 include = false;
189 domain = domain.substr(1);
190 }
191 else {
192 include = true;
193 hasIncludes = true;
194 }
195 if (!this.domains)
196 this.domains = {
197 __proto__: null
198 };
199 this.domains[domain] = include;
200 }
201 this.domains[""] = !hasIncludes;
202 }
203 }
204 ,
205 isActiveOnDomain: function (docDomain) {
206 if (!this.domains)
207 return true;
208 if (!docDomain)
209 return this.domains[""];
210 docDomain = docDomain.replace(/\.+$/, "").toUpperCase();
211 while (true) {
212 if (docDomain in this.domains)
213 return this.domains[docDomain];
214 var nextDot = docDomain.indexOf(".");
215 if (nextDot < 0)
216 break;
217 docDomain = docDomain.substr(nextDot + 1);
218 }
219 return this.domains[""];
220 }
221 ,
222 isActiveOnlyOnDomain: function (docDomain) {
223 if (!docDomain || !this.domains || this.domains[""])
224 return false;
225 docDomain = docDomain.replace(/\.+$/, "").toUpperCase();
226 for (var domain in this.domains)
227 if (this.domains[domain] && domain != docDomain && (domain.length <= doc Domain.length || domain.indexOf("." + docDomain) != domain.length - docDomain.le ngth - 1))
228 return false;
229 return true;
230 }
231 ,
232 serialize: function (buffer) {
233 if (this._disabled || this._hitCount || this._lastHit) {
234 Filter.prototype.serialize.call(this, buffer);
235 if (this._disabled)
236 buffer.push("disabled=true");
237 if (this._hitCount)
238 buffer.push("hitCount=" + this._hitCount);
239 if (this._lastHit)
240 buffer.push("lastHit=" + this._lastHit);
241 }
242 }
243
244 };
245 function RegExpFilter(text, regexpSource, contentType, matchCase, domains, thi rdParty) {
246 ActiveFilter.call(this, text, domains);
247 if (contentType != null)
248 this.contentType = contentType;
249 if (matchCase)
250 this.matchCase = matchCase;
251 if (thirdParty != null)
252 this.thirdParty = thirdParty;
253 if (regexpSource.length >= 2 && regexpSource[0] == "/" && regexpSource[regex pSource.length - 1] == "/") {
254 this.regexp = new RegExp(regexpSource.substr(1, regexpSource.length - 2), this.matchCase ? "" : "i");
255 }
256 else {
257 this.regexpSource = regexpSource;
258 this.__defineGetter__("regexp", this._generateRegExp);
259 }
260 }
261 RegExpFilter.prototype = {
262 __proto__: ActiveFilter.prototype,
263 domainSeparator: "|",
264 regexpSource: null,
265 regexp: null,
266 contentType: 2147483647,
267 matchCase: false,
268 thirdParty: null,
269 _generateRegExp: function () {
270 var source = this.regexpSource.replace(/\*+/g, "*");
271 if (source[0] == "*")
272 source = source.substr(1);
273 var pos = source.length - 1;
274 if (pos >= 0 && source[pos] == "*")
275 source = source.substr(0, pos);
276 source = source.replace(/\^\|$/, "^").replace(/\W/g, "\\$&").replace(/\\\* /g, ".*").replace(/\\\^/g, "(?:[\\x00-\\x24\\x26-\\x2C\\x2F\\x3A-\\x40\\x5B-\\x5 E\\x60\\x7B-\\x80]|$)").replace(/^\\\|\\\|/, "^[\\w\\-]+:\\/+(?!\\/)(?:[^.\\/]+\ \.)*?").replace(/^\\\|/, "^").replace(/\\\|$/, "$");
277 var regexp = new RegExp(source, this.matchCase ? "" : "i");
278 delete this.regexp;
279 delete this.regexpSource;
280 return (this.regexp = regexp);
281 }
282 ,
283 matches: function (location, contentType, docDomain, thirdParty) {
284 if (this.regexp.test(location) && (RegExpFilter.typeMap[contentType] & thi s.contentType) != 0 && (this.thirdParty == null || this.thirdParty == thirdParty ) && this.isActiveOnDomain(docDomain)) {
285 return true;
286 }
287 return false;
288 }
289
290 };
291 RegExpFilter.fromText = (function (text) {
292 var blocking = true;
293 var origText = text;
294 if (text.indexOf("@@") == 0) {
295 blocking = false;
296 text = text.substr(2);
297 }
298 var contentType = null;
299 var matchCase = null;
300 var domains = null;
301 var siteKeys = null;
302 var thirdParty = null;
303 var collapse = null;
304 var options;
305 if (Filter.optionsRegExp.test(text)) {
306 options = RegExp["$1"].toUpperCase().split(",");
307 text = RegExp.leftContext;
308 for (var _loopIndex0 = 0;
309 _loopIndex0 < options.length; ++ _loopIndex0) {
310 var option = options[_loopIndex0];
311 var value = null;
312 var separatorIndex = option.indexOf("=");
313 if (separatorIndex >= 0) {
314 value = option.substr(separatorIndex + 1);
315 option = option.substr(0, separatorIndex);
316 }
317 option = option.replace(/-/, "_");
318 if (option in RegExpFilter.typeMap) {
319 if (contentType == null)
320 contentType = 0;
321 contentType |= RegExpFilter.typeMap[option];
322 }
323 else
324 if (option[0] == "~" && option.substr(1) in RegExpFilter.typeMap) {
325 if (contentType == null)
326 contentType = RegExpFilter.prototype.contentType;
327 contentType &= ~RegExpFilter.typeMap[option.substr(1)];
328 }
329 else
330 if (option == "MATCH_CASE")
331 matchCase = true;
332 else
333 if (option == "DOMAIN" && typeof value != "undefined")
334 domains = value;
335 else
336 if (option == "THIRD_PARTY")
337 thirdParty = true;
338 else
339 if (option == "~THIRD_PARTY")
340 thirdParty = false;
341 else
342 if (option == "COLLAPSE")
343 collapse = true;
344 else
345 if (option == "~COLLAPSE")
346 collapse = false;
347 else
348 if (option == "SITEKEY" && typeof value != "undefined")
349 siteKeys = value.split(/\|/);
350 }
351 }
352 if (!blocking && (contentType == null || (contentType & RegExpFilter.typeMap .DOCUMENT)) && (!options || options.indexOf("DOCUMENT") < 0) && !/^\|?[\w\-]+:/. test(text)) {
353 if (contentType == null)
354 contentType = RegExpFilter.prototype.contentType;
355 contentType &= ~RegExpFilter.typeMap.DOCUMENT;
356 }
357 if (!blocking && siteKeys)
358 contentType = RegExpFilter.typeMap.DOCUMENT;
359 try {
360 if (blocking)
361 return new BlockingFilter(origText, text, contentType, matchCase, domain s, thirdParty, collapse);
362 else
363 return new WhitelistFilter(origText, text, contentType, matchCase, domai ns, thirdParty, siteKeys);
364 }
365 catch (e){
366 return new InvalidFilter(text, e);
367 }
368 }
369 );
370 RegExpFilter.typeMap = {
371 OTHER: 1,
372 SCRIPT: 2,
373 IMAGE: 4,
374 STYLESHEET: 8,
375 OBJECT: 16,
376 SUBDOCUMENT: 32,
377 DOCUMENT: 64,
378 XBL: 1,
379 PING: 1,
380 XMLHTTPREQUEST: 2048,
381 OBJECT_SUBREQUEST: 4096,
382 DTD: 1,
383 MEDIA: 16384,
384 FONT: 32768,
385 BACKGROUND: 4,
386 POPUP: 268435456,
387 DONOTTRACK: 536870912,
388 ELEMHIDE: 1073741824
389 };
390 RegExpFilter.prototype.contentType &= ~(RegExpFilter.typeMap.ELEMHIDE | RegExp Filter.typeMap.DONOTTRACK | RegExpFilter.typeMap.POPUP);
391 function BlockingFilter(text, regexpSource, contentType, matchCase, domains, t hirdParty, collapse) {
392 RegExpFilter.call(this, text, regexpSource, contentType, matchCase, domains, thirdParty);
393 this.collapse = collapse;
394 }
395 BlockingFilter.prototype = {
396 __proto__: RegExpFilter.prototype,
397 collapse: null
398 };
399 function WhitelistFilter(text, regexpSource, contentType, matchCase, domains, thirdParty, siteKeys) {
400 RegExpFilter.call(this, text, regexpSource, contentType, matchCase, domains, thirdParty);
401 if (siteKeys != null)
402 this.siteKeys = siteKeys;
403 }
404 WhitelistFilter.prototype = {
405 __proto__: RegExpFilter.prototype,
406 siteKeys: null
407 };
408 function ElemHideFilter(text, domains, selector) {
409 ActiveFilter.call(this, text, domains ? domains.toUpperCase() : null);
410 if (domains)
411 this.selectorDomain = domains.replace(/,~[^,]+/g, "").replace(/^~[^,]+,?/, "").toLowerCase();
412 this.selector = selector;
413 }
414 ElemHideFilter.prototype = {
415 __proto__: ActiveFilter.prototype,
416 domainSeparator: ",",
417 selectorDomain: null,
418 selector: null
419 };
420 ElemHideFilter.fromText = (function (text, domain, tagName, attrRules, selecto r) {
421 if (!selector) {
422 if (tagName == "*")
423 tagName = "";
424 var id = null;
425 var additional = "";
426 if (attrRules) {
427 attrRules = attrRules.match(/\([\w\-]+(?:[$^*]?=[^\(\)"]*)?\)/g);
428 for (var _loopIndex1 = 0;
429 _loopIndex1 < attrRules.length; ++ _loopIndex1) {
430 var rule = attrRules[_loopIndex1];
431 rule = rule.substr(1, rule.length - 2);
432 var separatorPos = rule.indexOf("=");
433 if (separatorPos > 0) {
434 rule = rule.replace(/=/, "=\"") + "\"";
435 additional += "[" + rule + "]";
436 }
437 else {
438 if (id)
439 return new InvalidFilter(text, Utils.getString("filter_elemhide_du plicate_id"));
440 else
441 id = rule;
442 }
443 }
444 }
445 if (id)
446 selector = tagName + "." + id + additional + "," + tagName + "#" + id + additional;
447 else
448 if (tagName || additional)
449 selector = tagName + additional;
450 else
451 return new InvalidFilter(text, Utils.getString("filter_elemhide_nocrit eria"));
452 }
453 return new ElemHideFilter(text, domain, selector);
454 }
455 );
456 if (typeof _patchFunc2 != "undefined")
457 eval("(" + _patchFunc2.toString() + ")()");
458 window.Filter = Filter;
459 window.InvalidFilter = InvalidFilter;
460 window.CommentFilter = CommentFilter;
461 window.ActiveFilter = ActiveFilter;
462 window.RegExpFilter = RegExpFilter;
463 window.BlockingFilter = BlockingFilter;
464 window.WhitelistFilter = WhitelistFilter;
465 window.ElemHideFilter = ElemHideFilter;
466 }
467 )(window.FilterClassesPatch);
OLDNEW
« no previous file with comments | « assets/js/ElemHide.jsm ('k') | assets/js/FilterListener.jsm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld