LEFT | RIGHT |
(no file at all) | |
| 1 /* |
| 2 * This file is part of Adblock Plus <http://adblockplus.org/>, |
| 3 * Copyright (C) 2006-2014 Eyeo GmbH |
| 4 * |
| 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 |
| 7 * published by the Free Software Foundation. |
| 8 * |
| 9 * Adblock Plus is distributed in the hope that it will be useful, |
| 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 * GNU General Public License for more details. |
| 13 * |
| 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/>. |
| 16 */ |
| 17 |
| 18 let {Filter, InvalidFilter, ElemHideBase} = require("filterClasses"); |
| 19 |
| 20 function parseFilter(text, ignore_headers) |
| 21 { |
| 22 text = Filter.normalize(text); |
| 23 if (!text) |
| 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 } |
| 33 |
| 34 let filter = Filter.fromText(text); |
| 35 |
| 36 if (filter instanceof InvalidFilter) |
| 37 throw filter.reason; |
| 38 |
| 39 if (filter instanceof ElemHideBase) |
| 40 { |
| 41 let style = document.createElement("style"); |
| 42 document.documentElement.appendChild(style); |
| 43 let sheet = style.sheet; |
| 44 document.documentElement.removeChild(style); |
| 45 |
| 46 try |
| 47 { |
| 48 document.querySelector(filter.selector); |
| 49 sheet.insertRule(filter.selector + "{}", 0); |
| 50 } |
| 51 catch (error) |
| 52 { |
| 53 throw ext.i18n.getMessage("invalid_css_selector", "'" + filter.selector +
"'"); |
| 54 } |
| 55 } |
| 56 |
| 57 return filter; |
| 58 } |
| 59 exports.parseFilter = parseFilter; |
| 60 |
| 61 function parseFilters(text, ignore_headers) |
| 62 { |
| 63 let lines = text.split("\n"); |
| 64 let filters = []; |
| 65 |
| 66 for (let i = 0; i < lines.length; i++) |
| 67 { |
| 68 let filter; |
| 69 try |
| 70 { |
| 71 filter = parseFilter(lines[i], ignore_headers); |
| 72 } |
| 73 catch (error) |
| 74 { |
| 75 throw ext.i18n.getMessage("line", (i + 1).toString()) + ": " + error; |
| 76 } |
| 77 |
| 78 if (filter) |
| 79 filters.push(filter); |
| 80 } |
| 81 |
| 82 return filters; |
| 83 } |
| 84 exports.parseFilters = parseFilters; |
LEFT | RIGHT |