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

Delta Between Two Patch Sets: lib/elemHide.js

Issue 29757591: Issue 6562 - Remove filter keys from the element hiding code (Closed)
Left Patch Set: Only note excluded filters and only if the domain isn't "" Created May 2, 2018, 4:21 p.m.
Right Patch Set: == instead of === Created May 4, 2018, 12:05 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « no previous file | test/filterListener.js » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 153
154 // Whitelisting filters 154 // Whitelisting filters
155 if (filter instanceof ElemHideException) 155 if (filter instanceof ElemHideException)
156 { 156 {
157 let list = exceptions.get(filter.selector); 157 let list = exceptions.get(filter.selector);
158 let index = list.indexOf(filter); 158 let index = list.indexOf(filter);
159 if (index >= 0) 159 if (index >= 0)
160 list.splice(index, 1); 160 list.splice(index, 1);
161 } 161 }
162 // Unconditially applied element hiding filters 162 // Unconditially applied element hiding filters
163 else if (filterBySelector.get(filter.selector) === filter) 163 else if (filterBySelector.get(filter.selector) == filter)
164 { 164 {
165 filterBySelector.delete(filter.selector); 165 filterBySelector.delete(filter.selector);
166 unconditionalSelectors = null; 166 unconditionalSelectors = null;
167 } 167 }
168 // Conditionally applied element hiding filters 168 // Conditionally applied element hiding filters
169 else 169 else
170 { 170 {
171 let domains = filter.domains || defaultDomains; 171 let domains = filter.domains || defaultDomains;
172 for (let domain of domains.keys()) 172 for (let domain of domains.keys())
173 { 173 {
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 getSelectorsForDomain(domain, criteria) 245 getSelectorsForDomain(domain, criteria)
246 { 246 {
247 let selectors = []; 247 let selectors = [];
248 248
249 if (typeof criteria == "undefined") 249 if (typeof criteria == "undefined")
250 criteria = ElemHide.ALL_MATCHING; 250 criteria = ElemHide.ALL_MATCHING;
251 if (criteria < ElemHide.NO_UNCONDITIONAL) 251 if (criteria < ElemHide.NO_UNCONDITIONAL)
252 selectors = this.getUnconditionalSelectors(); 252 selectors = this.getUnconditionalSelectors();
253 253
254 let specificOnly = (criteria >= ElemHide.SPECIFIC_ONLY); 254 let specificOnly = (criteria >= ElemHide.SPECIFIC_ONLY);
255 let excludedFilters = new Set(); 255 let excluded = new Set();
256 let currentDomain = domain ? domain.toUpperCase() : ""; 256 let currentDomain = domain ? domain.toUpperCase() : "";
257
258 // This code is a performance hot-spot, which is why we've made certain
259 // micro-optimisations. Please be careful before making changes.
257 while (true) 260 while (true)
258 { 261 {
259 if (specificOnly && currentDomain == "") 262 if (specificOnly && currentDomain == "")
260 break; 263 break;
261 264
262 let filters = filtersByDomain.get(currentDomain); 265 let filters = filtersByDomain.get(currentDomain);
263 if (filters) 266 if (filters)
264 { 267 {
265 for (let [filter, isIncluded] of filters) 268 for (let [filter, isIncluded] of filters)
266 { 269 {
267 if (excludedFilters.has(filter)) 270 if (!isIncluded)
268 continue;
269
270 if (isIncluded)
271 { 271 {
272 if (!this.getException(filter, domain)) 272 excluded.add(filter);
273 selectors.push(filter.selector);
274 } 273 }
275 else if (currentDomain != "") 274 else if ((excluded.size == 0 || !excluded.has(filter)) &&
275 !this.getException(filter, domain))
276 { 276 {
277 excludedFilters.add(filter); 277 selectors.push(filter.selector);
278 } 278 }
279 } 279 }
280 } 280 }
281 281
282 if (currentDomain == "") 282 if (currentDomain == "")
283 break; 283 break;
284 284
285 let nextDot = currentDomain.indexOf("."); 285 let nextDot = currentDomain.indexOf(".");
286 currentDomain = nextDot == -1 ? "" : currentDomain.substr(nextDot + 1); 286 currentDomain = nextDot == -1 ? "" : currentDomain.substr(nextDot + 1);
287 } 287 }
288 288
289 return selectors; 289 return selectors;
290 } 290 }
291 }; 291 };
LEFTRIGHT

Powered by Google App Engine
This is Rietveld