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

Side by Side Diff: lib/elemHide.js

Issue 29892563: Issue 6989 - Optimize CSS rule generation (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Created Sept. 26, 2018, 2:05 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 | no next file » | 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-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 258 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 // calculate the sizes of the selectors and divide them up accordingly, but 269 // calculate the sizes of the selectors and divide them up accordingly, but
270 // this approach is more efficient and has worked well in practice. In theory 270 // this approach is more efficient and has worked well in practice. In theory
271 // this could still lead to some selectors not working on Chromium, but it is 271 // this could still lead to some selectors not working on Chromium, but it is
272 // highly unlikely. 272 // highly unlikely.
273 // See issue #6298 and https://crbug.com/804179 273 // See issue #6298 and https://crbug.com/804179
274 for (let i = 0; i < selectors.length; i += selectorGroupSize) 274 for (let i = 0; i < selectors.length; i += selectorGroupSize)
275 yield selectors.slice(i, i + selectorGroupSize); 275 yield selectors.slice(i, i + selectorGroupSize);
276 } 276 }
277 277
278 /** 278 /**
279 * Creates element hiding CSS rules for a given list of selectors. Each rule 279 * Creates an element hiding CSS rule for a given list of selectors.
280 * contains no more than the maximum number of selectors as determined by the
281 * value of <code>{@link selectorGroupSize}</code>.
282 * 280 *
283 * @param {Array.<string>} selectors 281 * @param {Array.<string>} selectors
284 * @yields {string} 282 * @returns {string}
285 */ 283 */
286 function* createRules(selectors) 284 function createRule(selectors)
287 { 285 {
288 for (let selectorGroup of splitSelectors(selectors)) 286 let rule = "";
289 yield selectorGroup.join(", ") + " {display: none !important;}"; 287
288 for (let i = 0; i < selectors.length - 1; i++)
Manish Jethani 2018/09/26 15:29:56 I tried a few things here: 1. Used `for...of` a
hub 2018/09/26 16:49:11 Acknowledged.
289 rule += selectors[i] + ", ";
290
291 rule += selectors[selectors.length - 1] + " {display: none !important;}\n";
292
293 return rule;
290 } 294 }
291 295
292 /** 296 /**
293 * Creates an element hiding CSS style sheet from a given list of selectors. 297 * Creates an element hiding CSS style sheet from a given list of selectors.
294 * @param {Array.<string>} selectors 298 * @param {Array.<string>} selectors
295 * @returns {string} 299 * @returns {string}
296 */ 300 */
297 function createStyleSheet(selectors) 301 function createStyleSheet(selectors)
298 { 302 {
299 let styleSheet = ""; 303 let styleSheet = "";
300 304
301 for (let rule of createRules(selectors)) 305 for (let selectorGroup of splitSelectors(selectors))
302 styleSheet += rule + "\n"; 306 styleSheet += createRule(selectorGroup);
303 307
304 return styleSheet; 308 return styleSheet;
305 } 309 }
306 310
307 exports.createStyleSheet = createStyleSheet; 311 exports.createStyleSheet = createStyleSheet;
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld