| OLD | NEW |
| 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 388 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 399 createStyleSheet(getConditionalSelectors(knownSuffix, | 399 createStyleSheet(getConditionalSelectors(knownSuffix, |
| 400 false))); | 400 false))); |
| 401 } | 401 } |
| 402 } | 402 } |
| 403 | 403 |
| 404 return {code, selectors: includeSelectors ? selectors : null}; | 404 return {code, selectors: includeSelectors ? selectors : null}; |
| 405 } | 405 } |
| 406 }; | 406 }; |
| 407 | 407 |
| 408 /** | 408 /** |
| 409 * Yields rules from a style sheet returned by |
| 410 * <code>{@link createStyleSheet}</code>. |
| 411 * |
| 412 * @param {string} styleSheet A style sheet returned by |
| 413 * <code>{@link createStyleSheet}</code>. If the given style sheet is |
| 414 * <em>not</em> a value previously returned by a call to |
| 415 * <code>{@link createStyleSheet}</code>, the behavior is undefined. |
| 416 * @yields {string} A rule from the given style sheet. |
| 417 */ |
| 418 function* rulesFromStyleSheet(styleSheet) |
| 419 { |
| 420 let startIndex = 0; |
| 421 while (startIndex < styleSheet.length) |
| 422 { |
| 423 let ruleTerminatorIndex = styleSheet.indexOf("\n", startIndex); |
| 424 yield styleSheet.substring(startIndex, ruleTerminatorIndex); |
| 425 startIndex = ruleTerminatorIndex + 1; |
| 426 } |
| 427 } |
| 428 |
| 429 exports.rulesFromStyleSheet = rulesFromStyleSheet; |
| 430 |
| 431 /** |
| 409 * Splits a list of selectors into groups determined by the value of | 432 * Splits a list of selectors into groups determined by the value of |
| 410 * <code>{@link selectorGroupSize}</code>. | 433 * <code>{@link selectorGroupSize}</code>. |
| 411 * | 434 * |
| 412 * @param {Array.<string>} selectors | 435 * @param {Array.<string>} selectors |
| 413 * @yields {Array.<string>} | 436 * @yields {Array.<string>} |
| 414 */ | 437 */ |
| 415 function* splitSelectors(selectors) | 438 function* splitSelectors(selectors) |
| 416 { | 439 { |
| 417 // Chromium's Blink engine supports only up to 8,192 simple selectors, and | 440 // Chromium's Blink engine supports only up to 8,192 simple selectors, and |
| 418 // even fewer compound selectors, in a rule. The exact number of selectors | 441 // even fewer compound selectors, in a rule. The exact number of selectors |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 456 { | 479 { |
| 457 let styleSheet = ""; | 480 let styleSheet = ""; |
| 458 | 481 |
| 459 for (let selectorGroup of splitSelectors(selectors)) | 482 for (let selectorGroup of splitSelectors(selectors)) |
| 460 styleSheet += createRule(selectorGroup); | 483 styleSheet += createRule(selectorGroup); |
| 461 | 484 |
| 462 return styleSheet; | 485 return styleSheet; |
| 463 } | 486 } |
| 464 | 487 |
| 465 exports.createStyleSheet = createStyleSheet; | 488 exports.createStyleSheet = createStyleSheet; |
| OLD | NEW |