| LEFT | RIGHT |
| 1 /* | 1 /* |
| 2 * This file is part of Adblock Plus <http://adblockplus.org/>, | 2 * This file is part of Adblock Plus <http://adblockplus.org/>, |
| 3 * Copyright (C) 2006-2014 Eyeo GmbH | 3 * Copyright (C) 2006-2014 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 |
| 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 * GNU General Public License for more details. | 12 * GNU General Public License for more details. |
| 13 * | 13 * |
| 14 * You should have received a copy of the GNU General Public License | 14 * You should have received a copy of the GNU General Public License |
| 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. | 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
| 16 */ | 16 */ |
| 17 | 17 |
| 18 let {Filter, InvalidFilter, ElemHideBase} = require("filterClasses"); | 18 let {Filter, InvalidFilter, ElemHideBase} = require("filterClasses"); |
| 19 | 19 |
| 20 function parseFilter(text) | 20 function parseFilter(text, ignore_headers) |
| 21 { | 21 { |
| 22 text = Filter.normalize(text); | 22 text = Filter.normalize(text); |
| 23 if (!text) | 23 if (!text) |
| 24 return null; | 24 return null; |
| 25 |
| 26 if (text[0] == "[") |
| 27 { |
| 28 if (ignore_headers) |
| 29 return null; |
| 30 |
| 31 throw ext.i18n.getMessage("unexpected_filter_list_header"); |
| 32 } |
| 25 | 33 |
| 26 let filter = Filter.fromText(text); | 34 let filter = Filter.fromText(text); |
| 27 | 35 |
| 28 if (filter instanceof InvalidFilter) | 36 if (filter instanceof InvalidFilter) |
| 29 throw filter.reason; | 37 throw filter.reason; |
| 30 | 38 |
| 31 if (filter instanceof ElemHideBase) | 39 if (filter instanceof ElemHideBase) |
| 32 { | 40 { |
| 33 let style = document.createElement("style"); | 41 let style = document.createElement("style"); |
| 34 document.documentElement.appendChild(style); | 42 document.documentElement.appendChild(style); |
| 35 let sheet = style.sheet; | 43 let sheet = style.sheet; |
| 36 document.documentElement.removeChild(style); | 44 document.documentElement.removeChild(style); |
| 37 | 45 |
| 38 try | 46 try |
| 39 { | 47 { |
| 40 document.querySelector(filter.selector); | 48 document.querySelector(filter.selector); |
| 41 sheet.insertRule(filter.selector + "{}", 0); | 49 sheet.insertRule(filter.selector + "{}", 0); |
| 42 } | 50 } |
| 43 catch (error) | 51 catch (error) |
| 44 { | 52 { |
| 45 throw ext.i18n.getMessage("invalid_css_selector", "'" + filter.selector +
"'"); | 53 throw ext.i18n.getMessage("invalid_css_selector", "'" + filter.selector +
"'"); |
| 46 } | 54 } |
| 47 } | 55 } |
| 48 | 56 |
| 49 return filter; | 57 return filter; |
| 50 } | 58 } |
| 51 exports.parseFilter = parseFilter; | 59 exports.parseFilter = parseFilter; |
| 52 | 60 |
| 53 function parseFilters(text) | 61 function parseFilters(text, ignore_headers) |
| 54 { | 62 { |
| 55 let lines = text.split("\n"); | 63 let lines = text.split("\n"); |
| 56 let filters = []; | 64 let filters = []; |
| 57 | 65 |
| 58 for (let i = 0; i < lines.length; i++) | 66 for (let i = 0; i < lines.length; i++) |
| 59 { | 67 { |
| 60 let filter; | 68 let filter; |
| 61 try | 69 try |
| 62 { | 70 { |
| 63 filter = parseFilter(lines[i]); | 71 filter = parseFilter(lines[i], ignore_headers); |
| 64 } | 72 } |
| 65 catch (error) | 73 catch (error) |
| 66 { | 74 { |
| 67 throw ext.i18n.getMessage("line", (i + 1).toString()) + ": " + error; | 75 throw ext.i18n.getMessage("line", (i + 1).toString()) + ": " + error; |
| 68 } | 76 } |
| 69 | 77 |
| 70 if (filter) | 78 if (filter) |
| 71 filters.push(filter); | 79 filters.push(filter); |
| 72 } | 80 } |
| 73 | 81 |
| 74 return filters; | 82 return filters; |
| 75 } | 83 } |
| 76 exports.parseFilters = parseFilters; | 84 exports.parseFilters = parseFilters; |
| LEFT | RIGHT |