OLD | NEW |
1 /* | 1 /* |
2 * This file is part of Adblock Plus <https://adblockplus.org/>, | 2 * This file is part of Adblock Plus <https://adblockplus.org/>, |
3 * Copyright (C) 2006-present eyeo GmbH | 3 * Copyright (C) 2006-present eyeo GmbH |
4 * | 4 * |
5 * Adblock Plus is free software: you can redistribute it and/or modify | 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 | 6 * it under the terms of the GNU General Public License version 3 as |
7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
8 * | 8 * |
9 * Adblock Plus is distributed in the hope that it will be useful, | 9 * Adblock Plus is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 * GNU General Public License for more details. | 12 * GNU General Public License for more details. |
13 * | 13 * |
14 * You should have received a copy of the GNU General Public License | 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/>. | 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
16 */ | 16 */ |
17 | 17 |
18 "use strict"; | 18 "use strict"; |
19 | 19 |
20 /** | 20 /** |
21 * @fileOverview Element hiding emulation implementation. | 21 * @fileOverview Element hiding emulation implementation. |
22 */ | 22 */ |
23 | 23 |
24 const {ElemHideExceptions} = require("./elemHideExceptions"); | 24 const {ElemHideExceptions} = require("./elemHideExceptions"); |
25 const {Filter} = require("./filterClasses"); | |
26 | 25 |
27 let filters = new Set(); | 26 let filters = new Set(); |
28 | 27 |
29 /** | 28 /** |
30 * Container for element hiding emulation filters | 29 * Container for element hiding emulation filters |
31 * @class | 30 * @class |
32 */ | 31 */ |
33 let ElemHideEmulation = { | 32 let ElemHideEmulation = { |
34 /** | 33 /** |
35 * Removes all known filters | 34 * Removes all known filters |
36 */ | 35 */ |
37 clear() | 36 clear() |
38 { | 37 { |
39 filters.clear(); | 38 filters.clear(); |
40 }, | 39 }, |
41 | 40 |
42 /** | 41 /** |
43 * Add a new element hiding emulation filter | 42 * Add a new element hiding emulation filter |
44 * @param {ElemHideEmulationFilter} filter | 43 * @param {ElemHideEmulationFilter} filter |
45 */ | 44 */ |
46 add(filter) | 45 add(filter) |
47 { | 46 { |
48 filters.add(filter.text); | 47 filters.add(filter); |
49 }, | 48 }, |
50 | 49 |
51 /** | 50 /** |
52 * Removes an element hiding emulation filter | 51 * Removes an element hiding emulation filter |
53 * @param {ElemHideEmulationFilter} filter | 52 * @param {ElemHideEmulationFilter} filter |
54 */ | 53 */ |
55 remove(filter) | 54 remove(filter) |
56 { | 55 { |
57 filters.delete(filter.text); | 56 filters.delete(filter); |
58 }, | 57 }, |
59 | 58 |
60 /** | 59 /** |
61 * Returns a list of all rules active on a particular domain | 60 * Returns a list of all rules active on a particular domain |
62 * @param {string} domain | 61 * @param {string} domain |
63 * @return {ElemHideEmulationFilter[]} | 62 * @return {ElemHideEmulationFilter[]} |
64 */ | 63 */ |
65 getRulesForDomain(domain) | 64 getRulesForDomain(domain) |
66 { | 65 { |
67 let result = []; | 66 let result = []; |
68 for (let text of filters.values()) | 67 for (let filter of filters) |
69 { | 68 { |
70 let filter = Filter.fromText(text); | |
71 if (filter.isActiveOnDomain(domain) && | 69 if (filter.isActiveOnDomain(domain) && |
72 !ElemHideExceptions.getException(filter.selector, domain)) | 70 !ElemHideExceptions.getException(filter.selector, domain)) |
73 { | 71 { |
74 result.push(filter); | 72 result.push(filter); |
75 } | 73 } |
76 } | 74 } |
77 return result; | 75 return result; |
78 } | 76 } |
79 }; | 77 }; |
80 exports.ElemHideEmulation = ElemHideEmulation; | 78 exports.ElemHideEmulation = ElemHideEmulation; |
OLD | NEW |