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

Delta Between Two Patch Sets: lib/elemHide.js

Issue 29349187: Issue 4167 - getSelectorsForDomain criteria + keys (Closed)
Left Patch Set: Addressed feedback Created Sept. 20, 2016, 6:32 p.m.
Right Patch Set: Improved comments Created Sept. 27, 2016, 1:52 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/elemHide.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-2016 Eyeo GmbH 3 * Copyright (C) 2006-2016 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 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 179
180 FilterNotifier.emit("elemhideupdate"); 180 FilterNotifier.emit("elemhideupdate");
181 }, 181 },
182 182
183 _removeFilterKey: function(key, filter) 183 _removeFilterKey: function(key, filter)
184 { 184 {
185 let filterKeys = filterKeysBySelector[filter.selector]; 185 let filterKeys = filterKeysBySelector[filter.selector];
186 if (filterKeys) 186 if (filterKeys)
187 { 187 {
188 let index = filterKeys.indexOf(key); 188 let index = filterKeys.indexOf(key);
189 if (index >= 0) 189 if (index >= 0)
kzar 2016/09/20 18:37:35 It kind of bugs me how we check index twice, also
190 { 190 {
191 if (filterKeys.length > 1) 191 if (filterKeys.length > 1)
192 { 192 {
193 filterKeys.splice(index, 1); 193 filterKeys.splice(index, 1);
194 if (index == 0) 194 if (index == 0)
195 unconditionalFilterKeys = null; 195 unconditionalFilterKeys = null;
196 } 196 }
197 else 197 else
198 { 198 {
199 delete filterKeysBySelector[filter.selector]; 199 delete filterKeysBySelector[filter.selector];
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 let selectors = this.getUnconditionalSelectors(); 321 let selectors = this.getUnconditionalSelectors();
322 unconditionalFilterKeys = []; 322 unconditionalFilterKeys = [];
323 for (let selector of selectors) 323 for (let selector of selectors)
324 unconditionalFilterKeys.push(filterKeysBySelector[selector][0]); 324 unconditionalFilterKeys.push(filterKeysBySelector[selector][0]);
325 } 325 }
326 return unconditionalFilterKeys.slice(); 326 return unconditionalFilterKeys.slice();
327 }, 327 },
328 328
329 329
330 /** 330 /**
331 * Constant used by getSelectorsForDomain's when matching all selectors. 331 * Constant used by getSelectorsForDomain to return all selectors applying to
332 * a particular hostname.
332 */ 333 */
333 ALL_MATCHING: 0, 334 ALL_MATCHING: 0,
334 335
335 /** 336 /**
336 * Constant used by getSelectorsForDomain's when not matching unconditional 337 * Constant used by getSelectorsForDomain to exclude selectors which apply to
337 * selectors. 338 * all websites without exception.
338 */ 339 */
339 NO_UNCONDITIONAL: 1, 340 NO_UNCONDITIONAL: 1,
340 341
341 /** 342 /**
342 * Constant used by getSelectorsForDomain's when only matching specific 343 * Constant used by getSelectorsForDomain to return only selectors for filters
343 * selectors. 344 * which specifically match the given host name.
344 */ 345 */
345 SPECIFIC_ONLY: 2, 346 SPECIFIC_ONLY: 2,
346 347
347 /** 348 /**
348 * Returns a list of all selectors active on a particular domain. Optionally 349 * Determines from the current filter list which selectors should be applied
349 * a list of corresponding filter keys for the selectors can be returned too. 350 * on a particular host name. Optionally returns the corresponding filter
350 * The optional criteria parameter restricts the results, and must have the 351 * keys.
351 * value of ALL_MATCHING, NO_UNCONDITIONAL or SPECIFIC_ONLY if provided. 352 * @param {String} domain
Wladimir Palant 2016/09/26 14:56:54 Nit: You are documenting return value and paramete
kzar 2016/09/27 12:40:22 Done.
352 */ 353 * @param {Number} [criteria]
353 getSelectorsForDomain: function(/**String*/ domain, 354 * One of the following: ElemHide.ALL_MATCHING, ElemHide.NO_UNCONDITIONAL or
354 /**Number*/ criteria, 355 * ElemHide.SPECIFIC_ONLY.
355 /**Boolean*/ provideFilterKeys) 356 * @param {Boolean} [provideFilterKeys]
357 * If true, the function will return a list of corresponding filter keys in
358 * addition to selectors.
359 * @returns {string[]|Array.<string[]>}
360 * List of selectors or an array with two elements (list of selectors and
361 * list of corresponding keys) if provideFilterKeys is true.
362 */
363 getSelectorsForDomain: function(domain, criteria, provideFilterKeys)
356 { 364 {
357 let filterKeys = []; 365 let filterKeys = [];
358 let selectors = []; 366 let selectors = [];
359 367
360 if (typeof criteria == "undefined") 368 if (typeof criteria == "undefined")
361 criteria = ElemHide.ALL_MATCHING; 369 criteria = ElemHide.ALL_MATCHING;
362 if (criteria < ElemHide.NO_UNCONDITIONAL) 370 if (criteria < ElemHide.NO_UNCONDITIONAL)
363 { 371 {
364 selectors = this.getUnconditionalSelectors(); 372 selectors = this.getUnconditionalSelectors();
365 if (provideFilterKeys) 373 if (provideFilterKeys)
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
399 let nextDot = currentDomain.indexOf("."); 407 let nextDot = currentDomain.indexOf(".");
400 currentDomain = nextDot == -1 ? "" : currentDomain.substr(nextDot + 1); 408 currentDomain = nextDot == -1 ? "" : currentDomain.substr(nextDot + 1);
401 } 409 }
402 410
403 if (provideFilterKeys) 411 if (provideFilterKeys)
404 return [selectors, filterKeys]; 412 return [selectors, filterKeys];
405 else 413 else
406 return selectors; 414 return selectors;
407 } 415 }
408 }; 416 };
LEFTRIGHT
« no previous file | test/elemHide.js » ('j') | Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Toggle Comments ('s')

Powered by Google App Engine
This is Rietveld