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-2016 Eyeo GmbH | 3 * Copyright (C) 2006-2016 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 /** @module filterComposer */ | 18 /** @module filterComposer */ |
19 | 19 |
20 "use strict"; | 20 "use strict"; |
21 | 21 |
22 let {defaultMatcher} = require("matcher"); | 22 const {defaultMatcher} = require("matcher"); |
23 let {RegExpFilter} = require("filterClasses"); | 23 const {RegExpFilter} = require("filterClasses"); |
24 let {FilterNotifier} = require("filterNotifier"); | 24 const {FilterNotifier} = require("filterNotifier"); |
25 let {Prefs} = require("prefs"); | 25 const {Prefs} = require("prefs"); |
26 let {extractHostFromFrame, stringifyURL, isThirdParty} = require("url"); | 26 const {extractHostFromFrame, stringifyURL, isThirdParty} = require("url"); |
27 let {getKey, checkWhitelisted} = require("whitelisting"); | 27 const {getKey, checkWhitelisted} = require("whitelisting"); |
28 let {port} = require("messaging"); | 28 const {port} = require("messaging"); |
29 | 29 |
30 let readyPages = new ext.PageMap(); | 30 let readyPages = new ext.PageMap(); |
31 | 31 |
32 /** | 32 /** |
33 * Checks whether the given page is ready to use the filter composer | 33 * Checks whether the given page is ready to use the filter composer |
34 * | 34 * |
35 * @param {Page} page | 35 * @param {Page} page |
36 * @return {boolean} | 36 * @return {boolean} |
37 */ | 37 */ |
38 exports.isPageReady = function(page) | 38 exports.isPageReady = page => |
39 { | 39 { |
40 return readyPages.has(page); | 40 return readyPages.has(page); |
41 }; | 41 }; |
42 | 42 |
43 function isValidString(s) { | 43 function isValidString(s) { |
44 return s && s.indexOf("\0") == -1; | 44 return s && s.indexOf("\0") == -1; |
45 } | 45 } |
46 | 46 |
47 function escapeChar(chr) | 47 function escapeChar(chr) |
48 { | 48 { |
(...skipping 10 matching lines...) Expand all Loading... |
59 } | 59 } |
60 | 60 |
61 let escapeCSS = | 61 let escapeCSS = |
62 /** | 62 /** |
63 * Escapes a token (e.g. tag, id, class or attribute) to be used in CSS selector
s. | 63 * Escapes a token (e.g. tag, id, class or attribute) to be used in CSS selector
s. |
64 * | 64 * |
65 * @param {string} s | 65 * @param {string} s |
66 * @return {string} | 66 * @return {string} |
67 * @static | 67 * @static |
68 */ | 68 */ |
69 exports.escapeCSS = function(s) | 69 exports.escapeCSS = s => |
70 { | 70 { |
71 return s.replace(/^[\d\-]|[^\w\-\u0080-\uFFFF]/g, escapeChar); | 71 return s.replace(/^[\d\-]|[^\w\-\u0080-\uFFFF]/g, escapeChar); |
72 }; | 72 }; |
73 | 73 |
74 let quoteCSS = | 74 let quoteCSS = |
75 /** | 75 /** |
76 * Quotes a string to be used as attribute value in CSS selectors. | 76 * Quotes a string to be used as attribute value in CSS selectors. |
77 * | 77 * |
78 * @param {string} value | 78 * @param {string} value |
79 * @return {string} | 79 * @return {string} |
80 * @static | 80 * @static |
81 */ | 81 */ |
82 exports.quoteCSS = function(value) | 82 exports.quoteCSS = value => |
83 { | 83 { |
84 return '"' + value.replace(/["\\\{\}\x00-\x1F\x7F]/g, escapeChar) + '"'; | 84 return '"' + value.replace(/["\\\{\}\x00-\x1F\x7F]/g, escapeChar) + '"'; |
85 }; | 85 }; |
86 | 86 |
87 function composeFilters(details) | 87 function composeFilters(details) |
88 { | 88 { |
89 let filters = []; | 89 let filters = []; |
90 let selectors = []; | 90 let selectors = []; |
91 | 91 |
92 let page = details.page; | 92 let page = details.page; |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 filters.push(docDomain.replace(/^www\./, "") + "##" + selector); | 149 filters.push(docDomain.replace(/^www\./, "") + "##" + selector); |
150 } | 150 } |
151 } | 151 } |
152 | 152 |
153 return {filters: filters, selectors: selectors}; | 153 return {filters: filters, selectors: selectors}; |
154 } | 154 } |
155 | 155 |
156 let contextMenuItem = { | 156 let contextMenuItem = { |
157 title: ext.i18n.getMessage("block_element"), | 157 title: ext.i18n.getMessage("block_element"), |
158 contexts: ["image", "video", "audio"], | 158 contexts: ["image", "video", "audio"], |
159 onclick: page => | 159 onclick(page) |
160 { | 160 { |
161 page.sendMessage({type: "composer.content.contextMenuClicked"}); | 161 page.sendMessage({type: "composer.content.contextMenuClicked"}); |
162 } | 162 } |
163 }; | 163 }; |
164 | 164 |
165 function updateContextMenu(page, filter) | 165 function updateContextMenu(page, filter) |
166 { | 166 { |
167 page.contextMenus.remove(contextMenuItem); | 167 page.contextMenus.remove(contextMenuItem); |
168 | 168 |
169 if (typeof filter == "undefined") | 169 if (typeof filter == "undefined") |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
234 baseURL: message.baseURL, | 234 baseURL: message.baseURL, |
235 page: sender.page, | 235 page: sender.page, |
236 frame: sender.frame | 236 frame: sender.frame |
237 }); | 237 }); |
238 }); | 238 }); |
239 | 239 |
240 ext.pages.onLoading.addListener(page => | 240 ext.pages.onLoading.addListener(page => |
241 { | 241 { |
242 page.sendMessage({type: "composer.content.finished"}); | 242 page.sendMessage({type: "composer.content.finished"}); |
243 }); | 243 }); |
OLD | NEW |