| 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 |
| 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 "use strict"; | 18 "use strict"; |
| 19 | 19 |
| 20 /** | 20 /** |
| 21 * @fileOverview Snippets implementation. | 21 * @fileOverview Snippets implementation. |
| 22 */ | 22 */ |
| 23 | 23 |
| 24 const {EventEmitter} = require("./events"); | 24 const {EventEmitter} = require("./events"); |
| 25 const {Filter} = require("./filterClasses"); | |
| 26 | 25 |
| 27 const singleCharacterEscapes = new Map([ | 26 const singleCharacterEscapes = new Map([ |
| 28 ["n", "\n"], ["r", "\r"], ["t", "\t"] | 27 ["n", "\n"], ["r", "\r"], ["t", "\t"] |
| 29 ]); | 28 ]); |
| 30 | 29 |
| 31 let filters = new Set(); | 30 let filters = new Set(); |
| 32 | 31 |
| 33 /** | 32 /** |
| 34 * Container for snippet filters | 33 * Container for snippet filters |
| 35 * @class | 34 * @class |
| (...skipping 13 matching lines...) Expand all Loading... |
| 49 }, | 48 }, |
| 50 | 49 |
| 51 /** | 50 /** |
| 52 * Add a new snippet filter | 51 * Add a new snippet filter |
| 53 * @param {SnippetFilter} filter | 52 * @param {SnippetFilter} filter |
| 54 */ | 53 */ |
| 55 add(filter) | 54 add(filter) |
| 56 { | 55 { |
| 57 let {size} = filters; | 56 let {size} = filters; |
| 58 | 57 |
| 59 filters.add(filter.text); | 58 filters.add(filter); |
| 60 | 59 |
| 61 if (size != filters.size) | 60 if (size != filters.size) |
| 62 this.emit("snippets.filterAdded", filter); | 61 this.emit("snippets.filterAdded", filter); |
| 63 }, | 62 }, |
| 64 | 63 |
| 65 /** | 64 /** |
| 66 * Removes a snippet filter | 65 * Removes a snippet filter |
| 67 * @param {SnippetFilter} filter | 66 * @param {SnippetFilter} filter |
| 68 */ | 67 */ |
| 69 remove(filter) | 68 remove(filter) |
| 70 { | 69 { |
| 71 let {size} = filters; | 70 let {size} = filters; |
| 72 | 71 |
| 73 filters.delete(filter.text); | 72 filters.delete(filter); |
| 74 | 73 |
| 75 if (size != filters.size) | 74 if (size != filters.size) |
| 76 this.emit("snippets.filterRemoved", filter); | 75 this.emit("snippets.filterRemoved", filter); |
| 77 }, | 76 }, |
| 78 | 77 |
| 79 /** | 78 /** |
| 80 * Returns a list of all snippet filters active on a particular domain | 79 * Returns a list of all snippet filters active on a particular domain |
| 81 * @param {string} domain | 80 * @param {string} domain |
| 82 * @return {Array.<SnippetFilter>} | 81 * @return {Array.<SnippetFilter>} |
| 83 */ | 82 */ |
| 84 getFiltersForDomain(domain) | 83 getFiltersForDomain(domain) |
| 85 { | 84 { |
| 86 let result = []; | 85 let result = []; |
| 87 for (let text of filters) | 86 for (let filter of filters) |
| 88 { | 87 { |
| 89 let filter = Filter.fromText(text); | |
| 90 if (filter.isActiveOnDomain(domain)) | 88 if (filter.isActiveOnDomain(domain)) |
| 91 result.push(filter); | 89 result.push(filter); |
| 92 } | 90 } |
| 93 return result; | 91 return result; |
| 94 } | 92 } |
| 95 }); | 93 }); |
| 96 | 94 |
| 97 exports.Snippets = Snippets; | 95 exports.Snippets = Snippets; |
| 98 | 96 |
| 99 /** | 97 /** |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 let value = imports[name]; | 202 let value = imports[name]; |
| 205 if (typeof value == "function") | 203 if (typeof value == "function") |
| 206 value(...args); | 204 value(...args); |
| 207 } | 205 } |
| 208 } | 206 } |
| 209 } | 207 } |
| 210 `; | 208 `; |
| 211 } | 209 } |
| 212 | 210 |
| 213 exports.compileScript = compileScript; | 211 exports.compileScript = compileScript; |
| OLD | NEW |