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

Side by Side Diff: lib/elemHide.js

Issue 29470687: Issue 5344 - Element hiding emulation exceptions (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Created June 21, 2017, 6:50 p.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 | « no previous file | lib/filterClasses.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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-2017 eyeo GmbH 3 * Copyright (C) 2006-2017 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 implementation. 21 * @fileOverview Element hiding implementation.
22 */ 22 */
23 23
24 const {ElemHideException} = require("filterClasses"); 24 const {ElemHideExceptionBase} = require("filterClasses");
25 const {FilterNotifier} = require("filterNotifier"); 25 const {FilterNotifier} = require("filterNotifier");
26 26
27 /** 27 /**
28 * Lookup table, filters by their associated key 28 * Lookup table, filters by their associated key
29 * @type {Object} 29 * @type {Object}
30 */ 30 */
31 let filterByKey = []; 31 let filterByKey = [];
32 32
33 /** 33 /**
34 * Lookup table, keys of the filters by filter text 34 * Lookup table, keys of the filters by filter text
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 filters[key] = false; 116 filters[key] = false;
117 } 117 }
118 }, 118 },
119 119
120 /** 120 /**
121 * Add a new element hiding filter 121 * Add a new element hiding filter
122 * @param {ElemHideFilter} filter 122 * @param {ElemHideFilter} filter
123 */ 123 */
124 add(filter) 124 add(filter)
125 { 125 {
126 if (filter instanceof ElemHideException) 126 if (filter instanceof ElemHideExceptionBase)
127 { 127 {
128 if (filter.text in knownExceptions) 128 if (filter.text in knownExceptions)
129 return; 129 return;
130 130
131 let {selector} = filter; 131 let {selector} = filter;
132 if (!(selector in exceptions)) 132 if (!(selector in exceptions))
133 exceptions[selector] = []; 133 exceptions[selector] = [];
134 exceptions[selector].push(filter); 134 exceptions[selector].push(filter);
135 135
136 // If this is the first exception for a previously unconditionally 136 // If this is the first exception for a previously unconditionally
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 delete filters[key]; 189 delete filters[key];
190 } 190 }
191 }, 191 },
192 192
193 /** 193 /**
194 * Removes an element hiding filter 194 * Removes an element hiding filter
195 * @param {ElemHideFilter} filter 195 * @param {ElemHideFilter} filter
196 */ 196 */
197 remove(filter) 197 remove(filter)
198 { 198 {
199 if (filter instanceof ElemHideException) 199 if (filter instanceof ElemHideExceptionBase)
200 { 200 {
201 if (!(filter.text in knownExceptions)) 201 if (!(filter.text in knownExceptions))
202 return; 202 return;
203 203
204 let list = exceptions[filter.selector]; 204 let list = exceptions[filter.selector];
205 let index = list.indexOf(filter); 205 let index = list.indexOf(filter);
206 if (index >= 0) 206 if (index >= 0)
207 list.splice(index, 1); 207 list.splice(index, 1);
208 delete knownExceptions[filter.text]; 208 delete knownExceptions[filter.text];
209 } 209 }
210 else 210 else
211 { 211 {
212 if (!(filter.text in keyByFilter)) 212 if (!(filter.text in keyByFilter))
213 return; 213 return;
214 214
215 let key = keyByFilter[filter.text]; 215 let key = keyByFilter[filter.text];
216 delete filterByKey[key]; 216 delete filterByKey[key];
217 delete keyByFilter[filter.text]; 217 delete keyByFilter[filter.text];
218 this._removeFilterKey(key, filter); 218 this._removeFilterKey(key, filter);
219 } 219 }
220 220
221 FilterNotifier.emit("elemhideupdate"); 221 FilterNotifier.emit("elemhideupdate");
222 }, 222 },
223 223
224 /** 224 /**
225 * Checks whether an exception rule is registered for a filter on a particular 225 * Checks whether an exception rule is registered for a filter on a particular
226 * domain. 226 * domain.
227 * @param {Filter} filter 227 * @param {Filter} filter
228 * @param {string} docDomain 228 * @param {string} docDomain
229 * @return {ElemHideException} 229 * @return {ElemHideExceptionBase}
230 */ 230 */
231 getException(filter, docDomain) 231 getException(filter, docDomain)
232 { 232 {
233 if (!(filter.selector in exceptions)) 233 if (!(filter.selector in exceptions))
234 return null; 234 return null;
235 235
236 let list = exceptions[filter.selector]; 236 let list = exceptions[filter.selector];
237 for (let i = list.length - 1; i >= 0; i--) 237 for (let i = list.length - 1; i >= 0; i--)
238 { 238 {
239 if (list[i].isActiveOnDomain(docDomain)) 239 if (list[i].isActiveOnDomain(docDomain))
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
387 387
388 let nextDot = currentDomain.indexOf("."); 388 let nextDot = currentDomain.indexOf(".");
389 currentDomain = nextDot == -1 ? "" : currentDomain.substr(nextDot + 1); 389 currentDomain = nextDot == -1 ? "" : currentDomain.substr(nextDot + 1);
390 } 390 }
391 391
392 if (provideFilterKeys) 392 if (provideFilterKeys)
393 return [selectors, filterKeys]; 393 return [selectors, filterKeys];
394 return selectors; 394 return selectors;
395 } 395 }
396 }; 396 };
OLDNEW
« no previous file with comments | « no previous file | lib/filterClasses.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld