LEFT | RIGHT |
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 {ElemHide} = require("./elemHide"); | 24 const {ElemHide} = require("./elemHide"); |
25 const {filterIt, mapIt, flattenIt, regExpIt} = require("./coreUtils"); | 25 const {subdomains} = require("./common"); |
26 | 26 |
27 /** | 27 /** |
28 * Map of element hiding emulation filters by domain | 28 * Map of element hiding emulation filters by domain |
29 * @type {Map.<string,Set.<ElemHideEmulationFilter>>} | 29 * @type {Map.<string,Map.<ElemHideEmulationFilter,boolean>>} |
30 */ | 30 */ |
31 let filtersByDomain = new Map(); | 31 let filtersByDomain = new Map(); |
32 | 32 |
33 /** | 33 /** |
34 * Set containing known element hiding emulation filters | 34 * Set containing known element hiding emulation filters |
35 * @type {Set.<ElemHideEmulation>} | 35 * @type {Set.<ElemHideEmulation>} |
36 */ | 36 */ |
37 let knownFilters = new Set(); | 37 let knownFilters = new Set(); |
38 | 38 |
| 39 /** |
| 40 * Yields the domains associated with a filter, along with whether the filter |
| 41 * should be included on the domain and the set of filters associated with the |
| 42 * domain |
| 43 * @param {ElemHideEmulationFilter} filter |
| 44 * @yields {Array.<string,boolean,?Set.<ElemHideEmulationFilter>>} |
| 45 */ |
39 function* filterDomains(filter) | 46 function* filterDomains(filter) |
40 { | 47 { |
41 yield* mapIt(filterIt(filter.domains || [], ([domain]) => domain != ""), | 48 for (let [domain, include] of filter.domains || []) |
42 ([domain, include]) => [domain, include, | 49 { |
43 filtersByDomain.get(domain)]); | 50 if (domain != "") |
| 51 yield [domain, include, filtersByDomain.get(domain)]; |
| 52 } |
44 } | 53 } |
45 | 54 |
| 55 /** |
| 56 * Yields the filters for a domain and its subdomains, along with whether the |
| 57 * filter should be included on its corresponding domain |
| 58 * @param {string} domain |
| 59 * @yields {Array.<ElemHideEmulationFilter,boolean>} |
| 60 */ |
46 function* filtersForDomain(domain) | 61 function* filtersForDomain(domain) |
47 { | 62 { |
48 yield* filtersByDomain.get(domain) || []; | 63 yield* filtersByDomain.get(domain) || []; |
49 | 64 |
50 let subdomainIt = | 65 for (let subdomain of subdomains(domain)) |
51 mapIt(regExpIt(/([^|]*)\|/g, domain.replace(/([^.]+\.)/g, "$'|")), | 66 yield* filtersByDomain.get(subdomain) || []; |
52 ([, subdomain]) => filtersByDomain.get(subdomain) || []); | |
53 yield* flattenIt(subdomainIt); | |
54 } | 67 } |
55 | 68 |
56 /** | 69 /** |
57 * Container for element hiding emulation filters | 70 * Container for element hiding emulation filters |
58 * @class | 71 * @class |
59 */ | 72 */ |
60 let ElemHideEmulation = { | 73 let ElemHideEmulation = { |
61 /** | 74 /** |
62 * Removes all known filters | 75 * Removes all known filters |
63 */ | 76 */ |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 !ElemHide.getException(filter, domain)) | 142 !ElemHide.getException(filter, domain)) |
130 { | 143 { |
131 result.push(filter); | 144 result.push(filter); |
132 } | 145 } |
133 } | 146 } |
134 | 147 |
135 return result; | 148 return result; |
136 } | 149 } |
137 }; | 150 }; |
138 exports.ElemHideEmulation = ElemHideEmulation; | 151 exports.ElemHideEmulation = ElemHideEmulation; |
LEFT | RIGHT |