Left: | ||
Right: |
OLD | NEW |
---|---|
(Empty) | |
1 /* | |
2 * This file is part of Adblock Plus <https://adblockplus.org/>, | |
3 * Copyright (C) 2006-2015 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 * @fileOverview CSS property filtering implementation. | |
20 */ | |
21 | |
22 let {ElemHide: {getException}} = require("elemHide"); | |
kzar
2015/10/24 17:14:51
This results in a syntax error when building the s
Thomas Greiner
2015/11/25 11:20:00
Done. Since this is valid ES6 syntax, I'd consider
kzar
2015/11/25 13:12:26
Thanks, yea I agree that it looks like more of a p
| |
23 | |
24 /** | |
25 * Lookup table, filters by their associated key | |
26 * @type Object | |
27 */ | |
28 let filterByKey = Object.create(null); | |
29 | |
30 /** | |
31 * Lookup table, keys of the filters by filter text | |
32 * @type Object | |
33 */ | |
34 let keyByFilter = Object.create(null); | |
Wladimir Palant
2015/11/05 12:46:18
The two maps filterByKey and keyByFilter seem to b
Thomas Greiner
2015/11/25 11:20:00
You're absolutely right.
I'd love to use `Set` fo
| |
35 | |
36 /** | |
37 * CSS rules component | |
38 * @class | |
39 */ | |
40 let CSSRules = exports.CSSRules = | |
41 { | |
42 /** | |
43 * Removes all known filters | |
44 */ | |
45 clear: function() | |
46 { | |
47 filterByKey = Object.create(null); | |
48 keyByFilter = Object.create(null); | |
49 }, | |
50 | |
51 /** | |
52 * Add a new CSS property filter | |
53 * @param {CSSPropertyFilter} filter | |
54 */ | |
55 add: function(filter) | |
56 { | |
57 if (filter.text in keyByFilter) | |
58 return; | |
59 | |
60 let key; | |
61 do { | |
62 key = Math.random().toFixed(15).substr(5); | |
63 } while (key in filterByKey); | |
64 | |
65 filterByKey[key] = filter; | |
66 keyByFilter[filter.text] = key; | |
67 }, | |
68 | |
69 /** | |
70 * Removes a CSS property filter | |
71 * @param {CSSPropertyFilter} filter | |
72 */ | |
73 remove: function(filter) | |
74 { | |
75 if (!(filter.text in keyByFilter)) | |
76 return; | |
77 | |
78 let key = keyByFilter[filter.text]; | |
79 delete filterByKey[key]; | |
80 delete keyByFilter[filter.text]; | |
81 }, | |
82 | |
83 /** | |
84 * Returns a list of all rules active on a particular domain | |
85 * @param {String} domain | |
86 * @param {Boolean} specificOnly | |
kzar
2015/11/04 13:03:20
Aren't CSS property filters _always_ specific? We
Thomas Greiner
2015/11/25 11:20:00
Done.
| |
87 */ | |
88 getRulesForDomain: function(domain, specificOnly) | |
89 { | |
90 let result = []; | |
91 let keys = Object.getOwnPropertyNames(filterByKey); | |
92 for (let key of keys) | |
93 { | |
94 let filter = filterByKey[key]; | |
95 if (specificOnly && (!filter.domains || filter.domains[""])) | |
kzar
2015/11/02 19:33:45
Use filter.isGeneric() instead?
Wladimir Palant
2015/11/05 12:46:19
Actually, filters that are generic shouldn't even
kzar
2015/11/05 14:27:47
Yea, I noticed that later, see my above comment :p
| |
96 continue; | |
97 | |
98 if (filter.isActiveOnDomain(domain) && !getException(filter, domain)) | |
99 result.push(filter.selector); | |
kzar
2015/11/02 19:33:45
Mind just pushing `filter` instead of `filter.sele
Thomas Greiner
2015/11/25 11:20:00
Done. I must've overseen that those are required a
| |
100 } | |
Wladimir Palant
2015/11/05 12:46:18
Note: This loop is rather inefficient but that's o
| |
101 return result; | |
102 } | |
103 }; | |
OLD | NEW |