| Left: | ||
| Right: |
| 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 459 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 470 // calculate the sizes of the selectors and divide them up accordingly, but | 470 // calculate the sizes of the selectors and divide them up accordingly, but |
| 471 // this approach is more efficient and has worked well in practice. In theory | 471 // this approach is more efficient and has worked well in practice. In theory |
| 472 // this could still lead to some selectors not working on Chromium, but it is | 472 // this could still lead to some selectors not working on Chromium, but it is |
| 473 // highly unlikely. | 473 // highly unlikely. |
| 474 // See issue #6298 and https://crbug.com/804179 | 474 // See issue #6298 and https://crbug.com/804179 |
| 475 for (let i = 0; i < selectors.length; i += selectorGroupSize) | 475 for (let i = 0; i < selectors.length; i += selectorGroupSize) |
| 476 yield selectors.slice(i, i + selectorGroupSize); | 476 yield selectors.slice(i, i + selectorGroupSize); |
| 477 } | 477 } |
| 478 | 478 |
| 479 /** | 479 /** |
| 480 * Escape curly braces to prevent CSS rule injection. | |
|
Manish Jethani
2019/02/13 12:27:25
s/Escape/Escapes/
hub
2019/02/13 16:33:32
Done.
| |
| 481 * | |
| 482 * @param {string} selector | |
| 483 * @return {string} | |
|
Manish Jethani
2019/02/13 12:27:25
s/@return/@returns/
hub
2019/02/13 16:33:31
Done.
| |
| 484 */ | |
| 485 function escapedSelector(selector) | |
|
hub
2019/02/12 23:55:49
while we expect a string, if `selector` is undefin
Manish Jethani
2019/02/13 12:27:25
If it's always going to be a string in practice th
Manish Jethani
2019/02/13 12:27:25
Let's rename to `escapeSelector`
hub
2019/02/13 16:33:32
Done.
| |
| 486 { | |
| 487 return selector.replace("{", "\\7B ").replace("}", "\\7D "); | |
| 488 } | |
| 489 | |
| 490 /** | |
| 480 * Creates an element hiding CSS rule for a given list of selectors. | 491 * Creates an element hiding CSS rule for a given list of selectors. |
| 481 * | 492 * |
| 482 * @param {Array.<string>} selectors | 493 * @param {Array.<string>} selectors |
| 483 * @returns {string} | 494 * @returns {string} |
| 484 */ | 495 */ |
| 485 function createRule(selectors) | 496 function createRule(selectors) |
| 486 { | 497 { |
| 487 let rule = ""; | 498 let rule = ""; |
| 488 | 499 |
| 489 for (let i = 0; i < selectors.length - 1; i++) | 500 for (let i = 0; i < selectors.length - 1; i++) |
| 490 rule += selectors[i] + ", "; | 501 rule += escapedSelector(selectors[i]) + ", "; |
| 491 | 502 |
| 492 rule += selectors[selectors.length - 1] + " {display: none !important;}\n"; | 503 rule += escapedSelector(selectors[selectors.length - 1]) + |
| 504 " {display: none !important;}\n"; | |
|
Manish Jethani
2019/02/13 12:27:25
Nit: The double quote here should be in the same c
hub
2019/02/13 16:33:32
Done.
| |
| 493 | 505 |
| 494 return rule; | 506 return rule; |
| 495 } | 507 } |
| 496 | 508 |
| 497 /** | 509 /** |
| 498 * Creates an element hiding CSS style sheet from a given list of selectors. | 510 * Creates an element hiding CSS style sheet from a given list of selectors. |
| 499 * @param {Array.<string>} selectors | 511 * @param {Array.<string>} selectors |
| 500 * @returns {string} | 512 * @returns {string} |
| 501 */ | 513 */ |
| 502 function createStyleSheet(selectors) | 514 function createStyleSheet(selectors) |
| 503 { | 515 { |
| 504 let styleSheet = ""; | 516 let styleSheet = ""; |
| 505 | 517 |
| 506 for (let selectorGroup of splitSelectors(selectors)) | 518 for (let selectorGroup of splitSelectors(selectors)) |
| 507 styleSheet += createRule(selectorGroup); | 519 styleSheet += createRule(selectorGroup); |
| 508 | 520 |
| 509 return styleSheet; | 521 return styleSheet; |
| 510 } | 522 } |
| 511 | 523 |
| 512 exports.createStyleSheet = createStyleSheet; | 524 exports.createStyleSheet = createStyleSheet; |
| OLD | NEW |