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 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
351 * @property {Array.<string>} selectors List of selectors. | 351 * @property {Array.<string>} selectors List of selectors. |
352 */ | 352 */ |
353 | 353 |
354 /** | 354 /** |
355 * Generates a style sheet for a given domain based on the current set of | 355 * Generates a style sheet for a given domain based on the current set of |
356 * filters. | 356 * filters. |
357 * | 357 * |
358 * @param {string} domain The domain. | 358 * @param {string} domain The domain. |
359 * @param {boolean} [specificOnly=false] Whether selectors from generic | 359 * @param {boolean} [specificOnly=false] Whether selectors from generic |
360 * filters should be included. | 360 * filters should be included. |
| 361 * @param {boolean} [includeSelectors=false] Whether the return value should |
| 362 * include a separate list of selectors. |
361 * | 363 * |
362 * @returns {ElemHideStyleSheet} An object containing the CSS code and the | 364 * @returns {ElemHideStyleSheet} An object containing the CSS code and the |
363 * list of selectors. | 365 * list of selectors. |
364 */ | 366 */ |
365 generateStyleSheetForDomain(domain, specificOnly = false) | 367 generateStyleSheetForDomain(domain, specificOnly = false, |
| 368 includeSelectors = false) |
366 { | 369 { |
367 let code = null; | 370 let code = null; |
368 let selectors = null; | 371 let selectors = null; |
369 | 372 |
370 if (domain[domain.length - 1] == ".") | 373 if (domain[domain.length - 1] == ".") |
371 domain = domain.replace(/\.+$/, ""); | 374 domain = domain.replace(/\.+$/, ""); |
372 | 375 |
373 domain = domain.toLowerCase(); | 376 domain = domain.toLowerCase(); |
374 | 377 |
375 if (specificOnly) | 378 if (specificOnly) |
376 { | 379 { |
377 selectors = getConditionalSelectors(domain, true); | 380 selectors = getConditionalSelectors(domain, true); |
378 code = createStyleSheet(selectors); | 381 code = createStyleSheet(selectors); |
379 } | 382 } |
380 else | 383 else |
381 { | 384 { |
382 let knownSuffix = getKnownSuffix(domain); | 385 let knownSuffix = getKnownSuffix(domain); |
383 | 386 |
384 selectors = getConditionalSelectors(knownSuffix, false); | 387 if (includeSelectors) |
385 code = knownSuffix == "" ? getCommonStyleSheet() : | 388 { |
386 (getDefaultStyleSheet() + createStyleSheet(selectors)); | 389 selectors = getConditionalSelectors(knownSuffix, false); |
| 390 code = knownSuffix == "" ? getCommonStyleSheet() : |
| 391 (getDefaultStyleSheet() + createStyleSheet(selectors)); |
387 | 392 |
388 selectors = getUnconditionalSelectors().concat(selectors); | 393 selectors = getUnconditionalSelectors().concat(selectors); |
| 394 } |
| 395 else |
| 396 { |
| 397 code = knownSuffix == "" ? getCommonStyleSheet() : |
| 398 (getDefaultStyleSheet() + |
| 399 createStyleSheet(getConditionalSelectors(knownSuffix, |
| 400 false))); |
| 401 } |
389 } | 402 } |
390 | 403 |
391 return {code, selectors}; | 404 return {code, selectors: includeSelectors ? selectors : null}; |
392 } | 405 } |
393 }; | 406 }; |
394 | 407 |
395 /** | 408 /** |
396 * Splits a list of selectors into groups determined by the value of | 409 * Splits a list of selectors into groups determined by the value of |
397 * <code>{@link selectorGroupSize}</code>. | 410 * <code>{@link selectorGroupSize}</code>. |
398 * | 411 * |
399 * @param {Array.<string>} selectors | 412 * @param {Array.<string>} selectors |
400 * @yields {Array.<string>} | 413 * @yields {Array.<string>} |
401 */ | 414 */ |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
443 { | 456 { |
444 let styleSheet = ""; | 457 let styleSheet = ""; |
445 | 458 |
446 for (let selectorGroup of splitSelectors(selectors)) | 459 for (let selectorGroup of splitSelectors(selectors)) |
447 styleSheet += createRule(selectorGroup); | 460 styleSheet += createRule(selectorGroup); |
448 | 461 |
449 return styleSheet; | 462 return styleSheet; |
450 } | 463 } |
451 | 464 |
452 exports.createStyleSheet = createStyleSheet; | 465 exports.createStyleSheet = createStyleSheet; |
OLD | NEW |