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 |
(...skipping 14 matching lines...) Expand all Loading... |
25 * returned function will take the corresponding | 25 * returned function will take the corresponding |
26 * values as arguments. | 26 * values as arguments. |
27 * @return The generated messaging function, optionally taking any values as | 27 * @return The generated messaging function, optionally taking any values as |
28 * specified by the paramKeys and finally an optional callback. | 28 * specified by the paramKeys and finally an optional callback. |
29 * (Although the value arguments are optional their index must be | 29 * (Although the value arguments are optional their index must be |
30 * maintained. E.g. if you omit the first value you must omit the | 30 * maintained. E.g. if you omit the first value you must omit the |
31 * second too.) | 31 * second too.) |
32 */ | 32 */ |
33 function wrapper(baseMessage /* , [paramKeys] */) | 33 function wrapper(baseMessage /* , [paramKeys] */) |
34 { | 34 { |
35 var paramKeys = []; | 35 let paramKeys = []; |
36 for (var i = 1; i < arguments.length; i++) | 36 for (let i = 1; i < arguments.length; i++) |
37 paramKeys.push(arguments[i]); | 37 paramKeys.push(arguments[i]); |
38 | 38 |
39 return function(/* [paramValues], callback */) | 39 return function(/* [paramValues], callback */) |
40 { | 40 { |
41 var message = Object.create(null); | 41 let message = Object.create(null); |
42 for (var key in baseMessage) | 42 for (let key in baseMessage) |
43 if (baseMessage.hasOwnProperty(key)) | 43 if (baseMessage.hasOwnProperty(key)) |
44 message[key] = baseMessage[key]; | 44 message[key] = baseMessage[key]; |
45 | 45 |
46 var paramValues = []; | 46 let paramValues = []; |
47 var callback; | 47 let callback; |
48 | 48 |
49 if (arguments.length > 0) | 49 if (arguments.length > 0) |
50 { | 50 { |
51 var lastArg = arguments[arguments.length - 1]; | 51 let lastArg = arguments[arguments.length - 1]; |
52 if (typeof lastArg == "function") | 52 if (typeof lastArg == "function") |
53 callback = lastArg; | 53 callback = lastArg; |
54 | 54 |
55 for (var i = 0; i < arguments.length - (callback ? 1 : 0); i++) | 55 for (let i = 0; i < arguments.length - (callback ? 1 : 0); i++) |
56 message[paramKeys[i]] = arguments[i]; | 56 message[paramKeys[i]] = arguments[i]; |
57 } | 57 } |
58 | 58 |
59 ext.backgroundPage.sendMessage(message, callback); | 59 ext.backgroundPage.sendMessage(message, callback); |
60 }; | 60 }; |
61 } | 61 } |
62 | 62 |
63 var getDocLink = wrapper({type: "app.get", what: "doclink"}, "link"); | 63 let getDocLink = wrapper({type: "app.get", what: "doclink"}, "link"); |
64 var getInfo = wrapper({type: "app.get"}, "what"); | 64 let getInfo = wrapper({type: "app.get"}, "what"); |
65 var getPref = wrapper({type: "prefs.get"}, "key"); | 65 let getPref = wrapper({type: "prefs.get"}, "key"); |
66 var togglePref = wrapper({type: "prefs.toggle"}, "key"); | 66 let togglePref = wrapper({type: "prefs.toggle"}, "key"); |
67 var getSubscriptions = wrapper({type: "subscriptions.get"}, | 67 let getSubscriptions = wrapper({type: "subscriptions.get"}, |
68 "downloadable", "special"); | 68 "downloadable", "special"); |
69 var removeSubscription = wrapper({type: "subscriptions.remove"}, "url"); | 69 let removeSubscription = wrapper({type: "subscriptions.remove"}, "url"); |
70 var addSubscription = wrapper({type: "subscriptions.add"}, | 70 let addSubscription = wrapper({type: "subscriptions.add"}, |
71 "url", "title", "homepage"); | 71 "url", "title", "homepage"); |
72 var toggleSubscription = wrapper({type: "subscriptions.toggle"}, | 72 let toggleSubscription = wrapper({type: "subscriptions.toggle"}, |
73 "url", "keepInstalled"); | 73 "url", "keepInstalled"); |
74 var updateSubscription = wrapper({type: "subscriptions.update"}, "url"); | 74 let updateSubscription = wrapper({type: "subscriptions.update"}, "url"); |
75 var importRawFilters = wrapper({type: "filters.importRaw"}, | 75 let importRawFilters = wrapper({type: "filters.importRaw"}, |
76 "text", "removeExisting"); | 76 "text", "removeExisting"); |
77 var addFilter = wrapper({type: "filters.add"}, "text"); | 77 let addFilter = wrapper({type: "filters.add"}, "text"); |
78 var getFilters = wrapper({type: "filters.get"}, "subscriptionUrl"); | 78 let getFilters = wrapper({type: "filters.get"}, "subscriptionUrl"); |
79 var removeFilter = wrapper({type: "filters.remove"}, "text"); | 79 let removeFilter = wrapper({type: "filters.remove"}, "text"); |
80 | 80 |
81 var i18n = ext.i18n; | 81 let whitelistedDomainRegexp = /^@@\|\|([^\/:]+)\^\$document$/; |
82 var whitelistedDomainRegexp = /^@@\|\|([^\/:]+)\^\$document$/; | 82 let delayedSubscriptionSelection = null; |
83 var delayedSubscriptionSelection = null; | |
84 | 83 |
85 var acceptableAdsUrl; | 84 let acceptableAdsUrl; |
86 | 85 |
87 // Loads options from localStorage and sets UI elements accordingly | 86 // Loads options from localStorage and sets UI elements accordingly |
88 function loadOptions() | 87 function loadOptions() |
89 { | 88 { |
90 // Set page title to i18n version of "Adblock Plus Options" | 89 // Set page title to i18n version of "Adblock Plus Options" |
91 document.title = i18n.getMessage("options"); | 90 document.title = i18n.getMessage("options"); |
92 | 91 |
93 // Set links | 92 // Set links |
94 getPref("subscriptions_exceptionsurl", function(url) | 93 getPref("subscriptions_exceptionsurl", url => |
95 { | 94 { |
96 acceptableAdsUrl = url; | 95 acceptableAdsUrl = url; |
97 $("#acceptableAdsLink").attr("href", acceptableAdsUrl); | 96 $("#acceptableAdsLink").attr("href", acceptableAdsUrl); |
98 }); | 97 }); |
99 getDocLink("acceptable_ads", function(url) | 98 getDocLink("acceptable_ads", url => |
100 { | 99 { |
101 $("#acceptableAdsDocs").attr("href", url); | 100 $("#acceptableAdsDocs").attr("href", url); |
102 }); | 101 }); |
103 getDocLink("filterdoc", function(url) | 102 getDocLink("filterdoc", url => |
104 { | 103 { |
105 setLinks("filter-must-follow-syntax", url); | 104 setLinks("filter-must-follow-syntax", url); |
106 }); | 105 }); |
107 getInfo("application", function(application) | 106 getInfo("application", application => |
108 { | 107 { |
109 getInfo("platform", function(platform) | 108 getInfo("platform", platform => |
110 { | 109 { |
111 if (platform == "chromium" && application != "opera") | 110 if (platform == "chromium" && application != "opera") |
112 application = "chrome"; | 111 application = "chrome"; |
113 | 112 |
114 getDocLink(application + "_support", function(url) | 113 getDocLink(application + "_support", url => |
115 { | 114 { |
116 setLinks("found-a-bug", url); | 115 setLinks("found-a-bug", url); |
117 }); | 116 }); |
118 }); | 117 }); |
119 }); | 118 }); |
120 | 119 |
121 // Add event listeners | 120 // Add event listeners |
122 $("#updateFilterLists").click(updateFilterLists); | 121 $("#updateFilterLists").click(updateFilterLists); |
123 $("#startSubscriptionSelection").click(startSubscriptionSelection); | 122 $("#startSubscriptionSelection").click(startSubscriptionSelection); |
124 $("#subscriptionSelector").change(updateSubscriptionSelection); | 123 $("#subscriptionSelector").change(updateSubscriptionSelection); |
(...skipping 11 matching lines...) Expand all Loading... |
136 $("button").button(); | 135 $("button").button(); |
137 $(".refreshButton").button("option", "icons", {primary: "ui-icon-refresh"}); | 136 $(".refreshButton").button("option", "icons", {primary: "ui-icon-refresh"}); |
138 $(".addButton").button("option", "icons", {primary: "ui-icon-plus"}); | 137 $(".addButton").button("option", "icons", {primary: "ui-icon-plus"}); |
139 $(".removeButton").button("option", "icons", {primary: "ui-icon-minus"}); | 138 $(".removeButton").button("option", "icons", {primary: "ui-icon-minus"}); |
140 | 139 |
141 // Popuplate option checkboxes | 140 // Popuplate option checkboxes |
142 initCheckbox("shouldShowBlockElementMenu"); | 141 initCheckbox("shouldShowBlockElementMenu"); |
143 initCheckbox("show_devtools_panel"); | 142 initCheckbox("show_devtools_panel"); |
144 initCheckbox("shouldShowNotifications", "notifications_ignoredcategories"); | 143 initCheckbox("shouldShowNotifications", "notifications_ignoredcategories"); |
145 | 144 |
146 getInfo("features", function(features) | 145 getInfo("features", features => |
147 { | 146 { |
148 if (!features.devToolsPanel) | 147 if (!features.devToolsPanel) |
149 document.getElementById("showDevtoolsPanelContainer").hidden = true; | 148 document.getElementById("showDevtoolsPanelContainer").hidden = true; |
150 }); | 149 }); |
151 getPref("notifications_showui", function(notifications_showui) | 150 getPref("notifications_showui", notifications_showui => |
152 { | 151 { |
153 if (!notifications_showui) | 152 if (!notifications_showui) |
154 document.getElementById("shouldShowNotificationsContainer").hidden = true; | 153 document.getElementById("shouldShowNotificationsContainer").hidden = true; |
155 }); | 154 }); |
156 | 155 |
157 // Register listeners in the background message responder | 156 // Register listeners in the background message responder |
158 ext.backgroundPage.sendMessage({ | 157 ext.backgroundPage.sendMessage({ |
159 type: "app.listen", | 158 type: "app.listen", |
160 filter: ["addSubscription", "focusSection"] | 159 filter: ["addSubscription", "focusSection"] |
161 }); | 160 }); |
(...skipping 18 matching lines...) Expand all Loading... |
180 // Load recommended subscriptions | 179 // Load recommended subscriptions |
181 loadRecommendations(); | 180 loadRecommendations(); |
182 | 181 |
183 // Show user's filters | 182 // Show user's filters |
184 reloadFilters(); | 183 reloadFilters(); |
185 } | 184 } |
186 $(loadOptions); | 185 $(loadOptions); |
187 | 186 |
188 function convertSpecialSubscription(subscription) | 187 function convertSpecialSubscription(subscription) |
189 { | 188 { |
190 getFilters(subscription.url, function(filters) | 189 getFilters(subscription.url, filters => |
191 { | 190 { |
192 for (var j = 0; j < filters.length; j++) | 191 for (let filter of filters) |
193 { | 192 { |
194 var filter = filters[j].text; | 193 if (whitelistedDomainRegexp.test(filter.text)) |
195 if (whitelistedDomainRegexp.test(filter)) | |
196 appendToListBox("excludedDomainsBox", RegExp.$1); | 194 appendToListBox("excludedDomainsBox", RegExp.$1); |
197 else | 195 else |
198 appendToListBox("userFiltersBox", filter); | 196 appendToListBox("userFiltersBox", filter.text); |
199 } | 197 } |
200 }); | 198 }); |
201 } | 199 } |
202 | 200 |
203 // Reloads the displayed subscriptions and filters | 201 // Reloads the displayed subscriptions and filters |
204 function reloadFilters() | 202 function reloadFilters() |
205 { | 203 { |
206 // Load user filter URLs | 204 // Load user filter URLs |
207 var container = document.getElementById("filterLists"); | 205 let container = document.getElementById("filterLists"); |
208 while (container.lastChild) | 206 while (container.lastChild) |
209 container.removeChild(container.lastChild); | 207 container.removeChild(container.lastChild); |
210 | 208 |
211 getSubscriptions(true, false, function(subscriptions) | 209 getSubscriptions(true, false, subscriptions => |
212 { | 210 { |
213 for (var i = 0; i < subscriptions.length; i++) | 211 for (let subscription of subscriptions) |
214 { | 212 { |
215 var subscription = subscriptions[i]; | |
216 if (subscription.url == acceptableAdsUrl) | 213 if (subscription.url == acceptableAdsUrl) |
217 $("#acceptableAds").prop("checked", !subscription.disabled); | 214 $("#acceptableAds").prop("checked", !subscription.disabled); |
218 else | 215 else |
219 addSubscriptionEntry(subscription); | 216 addSubscriptionEntry(subscription); |
220 } | 217 } |
221 }); | 218 }); |
222 | 219 |
223 // User-entered filters | 220 // User-entered filters |
224 getSubscriptions(false, true, function(subscriptions) | 221 getSubscriptions(false, true, subscriptions => |
225 { | 222 { |
226 document.getElementById("userFiltersBox").innerHTML = ""; | 223 document.getElementById("userFiltersBox").innerHTML = ""; |
227 document.getElementById("excludedDomainsBox").innerHTML = ""; | 224 document.getElementById("excludedDomainsBox").innerHTML = ""; |
228 | 225 |
229 for (var i = 0; i < subscriptions.length; i++) | 226 for (let subscription of subscriptions) |
230 convertSpecialSubscription(subscriptions[i]); | 227 convertSpecialSubscription(subscription); |
231 }); | 228 }); |
232 } | 229 } |
233 | 230 |
234 function initCheckbox(id, key) | 231 function initCheckbox(id, key) |
235 { | 232 { |
236 key = key || id; | 233 key = key || id; |
237 var checkbox = document.getElementById(id); | 234 let checkbox = document.getElementById(id); |
238 | 235 |
239 getPref(key, function(value) | 236 getPref(key, value => |
240 { | 237 { |
241 onPrefMessage(key, value); | 238 onPrefMessage(key, value); |
242 }); | 239 }); |
243 | 240 |
244 checkbox.addEventListener("click", function() | 241 checkbox.addEventListener("click", () => |
245 { | 242 { |
246 togglePref(key); | 243 togglePref(key); |
247 }, false); | 244 }, false); |
248 } | 245 } |
249 | 246 |
250 function loadRecommendations() | 247 function loadRecommendations() |
251 { | 248 { |
252 fetch("subscriptions.xml") | 249 fetch("subscriptions.xml") |
253 .then(function(response) | 250 .then(response => |
254 { | 251 { |
255 return response.text(); | 252 return response.text(); |
256 }) | 253 }) |
257 .then(function(text) | 254 .then(text => |
258 { | 255 { |
259 var selectedIndex = 0; | 256 let selectedIndex = 0; |
260 var selectedPrefix = null; | 257 let selectedPrefix = null; |
261 var matchCount = 0; | 258 let matchCount = 0; |
262 | 259 |
263 var list = document.getElementById("subscriptionSelector"); | 260 let list = document.getElementById("subscriptionSelector"); |
264 var doc = new DOMParser().parseFromString(text, "application/xml"); | 261 let doc = new DOMParser().parseFromString(text, "application/xml"); |
265 var elements = doc.documentElement.getElementsByTagName("subscription"); | 262 let elements = doc.documentElement.getElementsByTagName("subscription"); |
266 | 263 |
267 for (var i = 0; i < elements.length; i++) | 264 for (let i = 0; i < elements.length; i++) |
268 { | 265 { |
269 var element = elements[i]; | 266 let element = elements[i]; |
270 var option = new Option(); | 267 let option = new Option(); |
271 option.text = element.getAttribute("title") + " (" + | 268 option.text = element.getAttribute("title") + " (" + |
272 element.getAttribute("specialization") + ")"; | 269 element.getAttribute("specialization") + ")"; |
273 option._data = { | 270 option._data = { |
274 title: element.getAttribute("title"), | 271 title: element.getAttribute("title"), |
275 url: element.getAttribute("url"), | 272 url: element.getAttribute("url"), |
276 homepage: element.getAttribute("homepage") | 273 homepage: element.getAttribute("homepage") |
277 }; | 274 }; |
278 | 275 |
279 var prefix = element.getAttribute("prefixes"); | 276 let prefix = element.getAttribute("prefixes"); |
280 if (prefix) | 277 if (prefix) |
281 { | 278 { |
282 prefix = prefix.replace(/\W/g, "_"); | 279 prefix = prefix.replace(/\W/g, "_"); |
283 option.style.fontWeight = "bold"; | 280 option.style.fontWeight = "bold"; |
284 option.style.backgroundColor = "#E0FFE0"; | 281 option.style.backgroundColor = "#E0FFE0"; |
285 option.style.color = "#000000"; | 282 option.style.color = "#000000"; |
286 if (!selectedPrefix || selectedPrefix.length < prefix.length) | 283 if (!selectedPrefix || selectedPrefix.length < prefix.length) |
287 { | 284 { |
288 selectedIndex = i; | 285 selectedIndex = i; |
289 selectedPrefix = prefix; | 286 selectedPrefix = prefix; |
(...skipping 10 matching lines...) Expand all Loading... |
300 if (Math.random() * matchCount < 1) | 297 if (Math.random() * matchCount < 1) |
301 { | 298 { |
302 selectedIndex = i; | 299 selectedIndex = i; |
303 selectedPrefix = prefix; | 300 selectedPrefix = prefix; |
304 } | 301 } |
305 } | 302 } |
306 } | 303 } |
307 list.appendChild(option); | 304 list.appendChild(option); |
308 } | 305 } |
309 | 306 |
310 var option = new Option(); | 307 let option = new Option(); |
311 var label = i18n.getMessage("filters_addSubscriptionOther_label"); | 308 let label = i18n.getMessage("filters_addSubscriptionOther_label"); |
312 option.text = label + "\u2026"; | 309 option.text = label + "\u2026"; |
313 option._data = null; | 310 option._data = null; |
314 list.appendChild(option); | 311 list.appendChild(option); |
315 | 312 |
316 list.selectedIndex = selectedIndex; | 313 list.selectedIndex = selectedIndex; |
317 | 314 |
318 if (delayedSubscriptionSelection) | 315 if (delayedSubscriptionSelection) |
319 startSubscriptionSelection.apply(null, delayedSubscriptionSelection); | 316 startSubscriptionSelection.apply(null, delayedSubscriptionSelection); |
320 }); | 317 }); |
321 } | 318 } |
322 | 319 |
323 function startSubscriptionSelection(title, url) | 320 function startSubscriptionSelection(title, url) |
324 { | 321 { |
325 var list = document.getElementById("subscriptionSelector"); | 322 let list = document.getElementById("subscriptionSelector"); |
326 if (list.length == 0) | 323 if (list.length == 0) |
327 { | 324 { |
328 delayedSubscriptionSelection = [title, url]; | 325 delayedSubscriptionSelection = [title, url]; |
329 return; | 326 return; |
330 } | 327 } |
331 | 328 |
332 $("#tabs").tabs("select", 0); | 329 $("#tabs").tabs("select", 0); |
333 $("#addSubscriptionContainer").show(); | 330 $("#addSubscriptionContainer").show(); |
334 $("#addSubscriptionButton").hide(); | 331 $("#addSubscriptionButton").hide(); |
335 $("#subscriptionSelector").focus(); | 332 $("#subscriptionSelector").focus(); |
336 if (typeof url != "undefined") | 333 if (typeof url != "undefined") |
337 { | 334 { |
338 list.selectedIndex = list.length - 1; | 335 list.selectedIndex = list.length - 1; |
339 document.getElementById("customSubscriptionTitle").value = title; | 336 document.getElementById("customSubscriptionTitle").value = title; |
340 document.getElementById("customSubscriptionLocation").value = url; | 337 document.getElementById("customSubscriptionLocation").value = url; |
341 } | 338 } |
342 updateSubscriptionSelection(); | 339 updateSubscriptionSelection(); |
343 document.getElementById("addSubscriptionContainer").scrollIntoView(true); | 340 document.getElementById("addSubscriptionContainer").scrollIntoView(true); |
344 } | 341 } |
345 | 342 |
346 function updateSubscriptionSelection() | 343 function updateSubscriptionSelection() |
347 { | 344 { |
348 var list = document.getElementById("subscriptionSelector"); | 345 let list = document.getElementById("subscriptionSelector"); |
349 var data = list.options[list.selectedIndex]._data; | 346 let data = list.options[list.selectedIndex]._data; |
350 if (data) | 347 if (data) |
351 $("#customSubscriptionContainer").hide(); | 348 $("#customSubscriptionContainer").hide(); |
352 else | 349 else |
353 { | 350 { |
354 $("#customSubscriptionContainer").show(); | 351 $("#customSubscriptionContainer").show(); |
355 $("#customSubscriptionTitle").focus(); | 352 $("#customSubscriptionTitle").focus(); |
356 } | 353 } |
357 } | 354 } |
358 | 355 |
359 function addSubscriptionClicked() | 356 function addSubscriptionClicked() |
360 { | 357 { |
361 var list = document.getElementById("subscriptionSelector"); | 358 let list = document.getElementById("subscriptionSelector"); |
362 var data = list.options[list.selectedIndex]._data; | 359 let data = list.options[list.selectedIndex]._data; |
363 if (data) | 360 if (data) |
364 addSubscription(data.url, data.title, data.homepage); | 361 addSubscription(data.url, data.title, data.homepage); |
365 else | 362 else |
366 { | 363 { |
367 var url = document.getElementById("customSubscriptionLocation").value.trim()
; | 364 let url = document.getElementById("customSubscriptionLocation").value.trim()
; |
368 if (!/^https?:/i.test(url)) | 365 if (!/^https?:/i.test(url)) |
369 { | 366 { |
370 alert(i18n.getMessage("global_subscription_invalid_location")); | 367 alert(i18n.getMessage("global_subscription_invalid_location")); |
371 $("#customSubscriptionLocation").focus(); | 368 $("#customSubscriptionLocation").focus(); |
372 return; | 369 return; |
373 } | 370 } |
374 | 371 |
375 var title = document.getElementById("customSubscriptionTitle").value.trim(); | 372 let title = document.getElementById("customSubscriptionTitle").value.trim(); |
376 if (!title) | 373 if (!title) |
377 title = url; | 374 title = url; |
378 | 375 |
379 addSubscription(url, title, null); | 376 addSubscription(url, title, null); |
380 } | 377 } |
381 | 378 |
382 $("#addSubscriptionContainer").hide(); | 379 $("#addSubscriptionContainer").hide(); |
383 $("#customSubscriptionContainer").hide(); | 380 $("#customSubscriptionContainer").hide(); |
384 $("#addSubscriptionButton").show(); | 381 $("#addSubscriptionButton").show(); |
385 } | 382 } |
386 | 383 |
387 function toggleAcceptableAds() | 384 function toggleAcceptableAds() |
388 { | 385 { |
389 toggleSubscription(acceptableAdsUrl, true); | 386 toggleSubscription(acceptableAdsUrl, true); |
390 } | 387 } |
391 | 388 |
392 function findSubscriptionElement(subscription) | 389 function findSubscriptionElement(subscription) |
393 { | 390 { |
394 var children = document.getElementById("filterLists").childNodes; | 391 for (let child of document.getElementById("filterLists").childNodes) |
395 for (var i = 0; i < children.length; i++) | 392 if (child._subscription.url == subscription.url) |
396 if (children[i]._subscription.url == subscription.url) | 393 return child; |
397 return children[i]; | |
398 return null; | 394 return null; |
399 } | 395 } |
400 | 396 |
401 function updateSubscriptionInfo(element, subscription) | 397 function updateSubscriptionInfo(element, subscription) |
402 { | 398 { |
403 if (subscription) | 399 if (subscription) |
404 element._subscription = subscription; | 400 element._subscription = subscription; |
405 else | 401 else |
406 subscription = element._subscription; | 402 subscription = element._subscription; |
407 | 403 |
408 var title = element.getElementsByClassName("subscriptionTitle")[0]; | 404 let title = element.getElementsByClassName("subscriptionTitle")[0]; |
409 title.textContent = subscription.title; | 405 title.textContent = subscription.title; |
410 title.setAttribute("title", subscription.url); | 406 title.setAttribute("title", subscription.url); |
411 if (subscription.homepage) | 407 if (subscription.homepage) |
412 title.href = subscription.homepage; | 408 title.href = subscription.homepage; |
413 else | 409 else |
414 title.href = subscription.url; | 410 title.href = subscription.url; |
415 | 411 |
416 var enabled = element.getElementsByClassName("subscriptionEnabled")[0]; | 412 let enabled = element.getElementsByClassName("subscriptionEnabled")[0]; |
417 enabled.checked = !subscription.disabled; | 413 enabled.checked = !subscription.disabled; |
418 | 414 |
419 var lastUpdate = element.getElementsByClassName("subscriptionUpdate")[0]; | 415 let lastUpdate = element.getElementsByClassName("subscriptionUpdate")[0]; |
420 lastUpdate.classList.remove("error"); | 416 lastUpdate.classList.remove("error"); |
421 | 417 |
422 var downloadStatus = subscription.downloadStatus; | 418 let downloadStatus = subscription.downloadStatus; |
423 if (subscription.isDownloading) | 419 if (subscription.isDownloading) |
424 { | 420 { |
425 lastUpdate.textContent = i18n.getMessage("filters_subscription_lastDownload_
inProgress"); | 421 lastUpdate.textContent = i18n.getMessage("filters_subscription_lastDownload_
inProgress"); |
426 } | 422 } |
427 else if (downloadStatus && downloadStatus != "synchronize_ok") | 423 else if (downloadStatus && downloadStatus != "synchronize_ok") |
428 { | 424 { |
429 var map = | 425 let map = |
430 { | 426 { |
431 "synchronize_invalid_url": "filters_subscription_lastDownload_invalidURL"
, | 427 "synchronize_invalid_url": "filters_subscription_lastDownload_invalidURL"
, |
432 "synchronize_connection_error": "filters_subscription_lastDownload_connec
tionError", | 428 "synchronize_connection_error": "filters_subscription_lastDownload_connec
tionError", |
433 "synchronize_invalid_data": "filters_subscription_lastDownload_invalidDat
a", | 429 "synchronize_invalid_data": "filters_subscription_lastDownload_invalidDat
a", |
434 "synchronize_checksum_mismatch": "filters_subscription_lastDownload_check
sumMismatch" | 430 "synchronize_checksum_mismatch": "filters_subscription_lastDownload_check
sumMismatch" |
435 }; | 431 }; |
436 if (downloadStatus in map) | 432 if (downloadStatus in map) |
437 lastUpdate.textContent = i18n.getMessage(map[downloadStatus]); | 433 lastUpdate.textContent = i18n.getMessage(map[downloadStatus]); |
438 else | 434 else |
439 lastUpdate.textContent = downloadStatus; | 435 lastUpdate.textContent = downloadStatus; |
440 lastUpdate.classList.add("error"); | 436 lastUpdate.classList.add("error"); |
441 } | 437 } |
442 else if (subscription.lastDownload > 0) | 438 else if (subscription.lastDownload > 0) |
443 { | 439 { |
444 var timeDate = i18n_timeDateStrings(subscription.lastDownload * 1000); | 440 let timeDate = i18n_timeDateStrings(subscription.lastDownload * 1000); |
445 var messageID = (timeDate[1] ? "last_updated_at" : "last_updated_at_today"); | 441 let messageID = (timeDate[1] ? "last_updated_at" : "last_updated_at_today"); |
446 lastUpdate.textContent = i18n.getMessage(messageID, timeDate); | 442 lastUpdate.textContent = i18n.getMessage(messageID, timeDate); |
447 } | 443 } |
448 } | 444 } |
449 | 445 |
450 function onSubscriptionMessage(action, subscription) | 446 function onSubscriptionMessage(action, subscription) |
451 { | 447 { |
452 var element = findSubscriptionElement(subscription); | 448 let element = findSubscriptionElement(subscription); |
453 | 449 |
454 switch (action) | 450 switch (action) |
455 { | 451 { |
456 case "disabled": | 452 case "disabled": |
457 case "downloading": | 453 case "downloading": |
458 case "downloadStatus": | 454 case "downloadStatus": |
459 case "homepage": | 455 case "homepage": |
460 case "lastDownload": | 456 case "lastDownload": |
461 case "title": | 457 case "title": |
462 if (element) | 458 if (element) |
(...skipping 21 matching lines...) Expand all Loading... |
484 switch (key) | 480 switch (key) |
485 { | 481 { |
486 case "notifications_showui": | 482 case "notifications_showui": |
487 document.getElementById("shouldShowNotificationsContainer").hidden = !valu
e; | 483 document.getElementById("shouldShowNotificationsContainer").hidden = !valu
e; |
488 return; | 484 return; |
489 case "notifications_ignoredcategories": | 485 case "notifications_ignoredcategories": |
490 key = "shouldShowNotifications"; | 486 key = "shouldShowNotifications"; |
491 value = value.indexOf("*") == -1; | 487 value = value.indexOf("*") == -1; |
492 break; | 488 break; |
493 } | 489 } |
494 var checkbox = document.getElementById(key); | 490 let checkbox = document.getElementById(key); |
495 if (checkbox) | 491 if (checkbox) |
496 checkbox.checked = value; | 492 checkbox.checked = value; |
497 } | 493 } |
498 | 494 |
499 function onFilterMessage(action, filter) | 495 function onFilterMessage(action, filter) |
500 { | 496 { |
501 switch (action) | 497 switch (action) |
502 { | 498 { |
503 case "loaded": | 499 case "loaded": |
504 reloadFilters(); | 500 reloadFilters(); |
(...skipping 10 matching lines...) Expand all Loading... |
515 else | 511 else |
516 removeFromListBox("userFiltersBox", filter.text); | 512 removeFromListBox("userFiltersBox", filter.text); |
517 break; | 513 break; |
518 } | 514 } |
519 } | 515 } |
520 | 516 |
521 // Add a filter string to the list box. | 517 // Add a filter string to the list box. |
522 function appendToListBox(boxId, text) | 518 function appendToListBox(boxId, text) |
523 { | 519 { |
524 // Note: document.createElement("option") is unreliable in Opera | 520 // Note: document.createElement("option") is unreliable in Opera |
525 var elt = new Option(); | 521 let elt = new Option(); |
526 elt.text = text; | 522 elt.text = text; |
527 elt.value = text; | 523 elt.value = text; |
528 document.getElementById(boxId).appendChild(elt); | 524 document.getElementById(boxId).appendChild(elt); |
529 } | 525 } |
530 | 526 |
531 // Remove a filter string from a list box. | 527 // Remove a filter string from a list box. |
532 function removeFromListBox(boxId, text) | 528 function removeFromListBox(boxId, text) |
533 { | 529 { |
534 let list = document.getElementById(boxId); | 530 let list = document.getElementById(boxId); |
535 let selector = "option[value=" + CSS.escape(text) + "]"; | 531 let selector = "option[value=" + CSS.escape(text) + "]"; |
536 for (let option of list.querySelectorAll(selector)) | 532 for (let option of list.querySelectorAll(selector)) |
537 list.removeChild(option); | 533 list.removeChild(option); |
538 } | 534 } |
539 | 535 |
540 function addWhitelistDomain(event) | 536 function addWhitelistDomain(event) |
541 { | 537 { |
542 event.preventDefault(); | 538 event.preventDefault(); |
543 | 539 |
544 var domain = document.getElementById("newWhitelistDomain").value.replace(/\s/g
, ""); | 540 let domain = document.getElementById("newWhitelistDomain").value.replace(/\s/g
, ""); |
545 document.getElementById("newWhitelistDomain").value = ""; | 541 document.getElementById("newWhitelistDomain").value = ""; |
546 if (!domain) | 542 if (!domain) |
547 return; | 543 return; |
548 | 544 |
549 var filterText = "@@||" + domain + "^$document"; | 545 let filterText = "@@||" + domain + "^$document"; |
550 addFilter(filterText); | 546 addFilter(filterText); |
551 } | 547 } |
552 | 548 |
553 // Adds filter text that user typed to the selection box | 549 // Adds filter text that user typed to the selection box |
554 function addTypedFilter(event) | 550 function addTypedFilter(event) |
555 { | 551 { |
556 event.preventDefault(); | 552 event.preventDefault(); |
557 | 553 |
558 var element = document.getElementById("newFilter"); | 554 let element = document.getElementById("newFilter"); |
559 addFilter(element.value, function(errors) | 555 addFilter(element.value, errors => |
560 { | 556 { |
561 if (errors.length > 0) | 557 if (errors.length > 0) |
562 alert(errors.join("\n")); | 558 alert(errors.join("\n")); |
563 else | 559 else |
564 element.value = ""; | 560 element.value = ""; |
565 }); | 561 }); |
566 } | 562 } |
567 | 563 |
568 // Removes currently selected whitelisted domains | 564 // Removes currently selected whitelisted domains |
569 function removeSelectedExcludedDomain(event) | 565 function removeSelectedExcludedDomain(event) |
570 { | 566 { |
571 event.preventDefault(); | 567 event.preventDefault(); |
572 var excludedDomainsBox = document.getElementById("excludedDomainsBox"); | 568 let remove = []; |
573 var remove = []; | 569 for (let option of document.getElementById("excludedDomainsBox").options) |
574 for (var i = 0; i < excludedDomainsBox.length; i++) | 570 if (option.selected) |
575 if (excludedDomainsBox.options[i].selected) | 571 remove.push(option.value); |
576 remove.push(excludedDomainsBox.options[i].value); | |
577 if (!remove.length) | 572 if (!remove.length) |
578 return; | 573 return; |
579 | 574 |
580 for (var i = 0; i < remove.length; i++) | 575 for (let domain of remove) |
581 removeFilter("@@||" + remove[i] + "^$document"); | 576 removeFilter("@@||" + domain + "^$document"); |
582 } | 577 } |
583 | 578 |
584 // Removes all currently selected filters | 579 // Removes all currently selected filters |
585 function removeSelectedFilters(event) | 580 function removeSelectedFilters(event) |
586 { | 581 { |
587 event.preventDefault(); | 582 event.preventDefault(); |
588 for (let option of document.querySelectorAll("#userFiltersBox > option:checked
")) | 583 for (let option of document.querySelectorAll("#userFiltersBox > option:checked
")) |
589 removeFilter(option.value); | 584 removeFilter(option.value); |
590 } | 585 } |
591 | 586 |
(...skipping 15 matching lines...) Expand all Loading... |
607 { | 602 { |
608 rawFilters.style.display = "none"; | 603 rawFilters.style.display = "none"; |
609 } | 604 } |
610 | 605 |
611 document.getElementById("rawFiltersText").value = filters.join("\n"); | 606 document.getElementById("rawFiltersText").value = filters.join("\n"); |
612 } | 607 } |
613 | 608 |
614 // Imports filters in the raw text box | 609 // Imports filters in the raw text box |
615 function importRawFiltersText() | 610 function importRawFiltersText() |
616 { | 611 { |
617 var text = document.getElementById("rawFiltersText").value; | 612 let text = document.getElementById("rawFiltersText").value; |
618 | 613 |
619 importRawFilters(text, true, function(errors) | 614 importRawFilters(text, true, errors => |
620 { | 615 { |
621 if (errors.length > 0) | 616 if (errors.length > 0) |
622 alert(errors.join("\n")); | 617 alert(errors.join("\n")); |
623 else | 618 else |
624 $("#rawFilters").hide(); | 619 $("#rawFilters").hide(); |
625 }); | 620 }); |
626 } | 621 } |
627 | 622 |
628 // Called when user explicitly requests filter list updates | 623 // Called when user explicitly requests filter list updates |
629 function updateFilterLists() | 624 function updateFilterLists() |
630 { | 625 { |
631 // Without the URL parameter this will update all subscriptions | 626 // Without the URL parameter this will update all subscriptions |
632 updateSubscription(); | 627 updateSubscription(); |
633 } | 628 } |
634 | 629 |
635 // Adds a subscription entry to the UI. | 630 // Adds a subscription entry to the UI. |
636 function addSubscriptionEntry(subscription) | 631 function addSubscriptionEntry(subscription) |
637 { | 632 { |
638 var template = document.getElementById("subscriptionTemplate"); | 633 let template = document.getElementById("subscriptionTemplate"); |
639 var element = template.cloneNode(true); | 634 let element = template.cloneNode(true); |
640 element.removeAttribute("id"); | 635 element.removeAttribute("id"); |
641 element._subscription = subscription; | 636 element._subscription = subscription; |
642 | 637 |
643 var removeButton = element.getElementsByClassName("subscriptionRemoveButton")[
0]; | 638 let removeButton = element.getElementsByClassName("subscriptionRemoveButton")[
0]; |
644 removeButton.setAttribute("title", removeButton.textContent); | 639 removeButton.setAttribute("title", removeButton.textContent); |
645 removeButton.textContent = "\xD7"; | 640 removeButton.textContent = "\xD7"; |
646 removeButton.addEventListener("click", function() | 641 removeButton.addEventListener("click", () => |
647 { | 642 { |
648 if (!confirm(i18n.getMessage("global_remove_subscription_warning"))) | 643 if (!confirm(i18n.getMessage("global_remove_subscription_warning"))) |
649 return; | 644 return; |
650 | 645 |
651 removeSubscription(subscription.url); | 646 removeSubscription(subscription.url); |
652 }, false); | 647 }, false); |
653 | 648 |
654 getPref("additional_subscriptions", function(additionalSubscriptions) | 649 getPref("additional_subscriptions", additionalSubscriptions => |
655 { | 650 { |
656 if (additionalSubscriptions.indexOf(subscription.url) != -1) | 651 if (additionalSubscriptions.indexOf(subscription.url) != -1) |
657 removeButton.style.visibility = "hidden"; | 652 removeButton.style.visibility = "hidden"; |
658 }); | 653 }); |
659 | 654 |
660 var enabled = element.getElementsByClassName("subscriptionEnabled")[0]; | 655 let enabled = element.getElementsByClassName("subscriptionEnabled")[0]; |
661 enabled.addEventListener("click", function() | 656 enabled.addEventListener("click", () => |
662 { | 657 { |
663 subscription.disabled = !subscription.disabled; | 658 subscription.disabled = !subscription.disabled; |
664 toggleSubscription(subscription.url, true); | 659 toggleSubscription(subscription.url, true); |
665 }, false); | 660 }, false); |
666 | 661 |
667 updateSubscriptionInfo(element); | 662 updateSubscriptionInfo(element); |
668 | 663 |
669 document.getElementById("filterLists").appendChild(element); | 664 document.getElementById("filterLists").appendChild(element); |
670 } | 665 } |
671 | 666 |
672 function setLinks(id) | 667 function setLinks(id) |
673 { | 668 { |
674 var element = document.getElementById(id); | 669 let element = document.getElementById(id); |
675 if (!element) | 670 if (!element) |
676 return; | 671 return; |
677 | 672 |
678 var links = element.getElementsByTagName("a"); | 673 let links = element.getElementsByTagName("a"); |
679 for (var i = 0; i < links.length; i++) | 674 for (let i = 0; i < links.length; i++) |
680 { | 675 { |
681 if (typeof arguments[i + 1] == "string") | 676 if (typeof arguments[i + 1] == "string") |
682 { | 677 { |
683 links[i].href = arguments[i + 1]; | 678 links[i].href = arguments[i + 1]; |
684 links[i].setAttribute("target", "_blank"); | 679 links[i].setAttribute("target", "_blank"); |
685 } | 680 } |
686 else if (typeof arguments[i + 1] == "function") | 681 else if (typeof arguments[i + 1] == "function") |
687 { | 682 { |
688 links[i].href = "javascript:void(0);"; | 683 links[i].href = "javascript:void(0);"; |
689 links[i].addEventListener("click", arguments[i + 1], false); | 684 links[i].addEventListener("click", arguments[i + 1], false); |
690 } | 685 } |
691 } | 686 } |
692 } | 687 } |
693 | 688 |
694 ext.onMessage.addListener(function(message) | 689 ext.onMessage.addListener(message => |
695 { | 690 { |
696 switch (message.type) | 691 switch (message.type) |
697 { | 692 { |
698 case "app.respond": | 693 case "app.respond": |
699 switch (message.action) | 694 switch (message.action) |
700 { | 695 { |
701 case "addSubscription": | 696 case "addSubscription": |
702 var subscription = message.args[0]; | 697 let subscription = message.args[0]; |
703 startSubscriptionSelection(subscription.title, subscription.url); | 698 startSubscriptionSelection(subscription.title, subscription.url); |
704 break; | 699 break; |
705 case "focusSection": | 700 case "focusSection": |
706 var tabs = document.getElementsByClassName("ui-tabs-panel"); | 701 for (let tab of document.getElementsByClassName("ui-tabs-panel")) |
707 for (var i = 0; i < tabs.length; i++) | |
708 { | 702 { |
709 var found = tabs[i].querySelector( | 703 let found = tab.querySelector( |
710 "[data-section='" + message.args[0] + "']" | 704 "[data-section='" + message.args[0] + "']" |
711 ); | 705 ); |
712 if (!found) | 706 if (!found) |
713 continue; | 707 continue; |
714 | 708 |
715 var previous = document.getElementsByClassName("focused"); | 709 let previous = document.getElementsByClassName("focused"); |
716 if (previous.length > 0) | 710 if (previous.length > 0) |
717 previous[0].classList.remove("focused"); | 711 previous[0].classList.remove("focused"); |
718 | 712 |
719 var tab = $("[href='#" + tabs[i].id + "']"); | 713 let index = $("[href='#" + tab.id + "']").parent().index(); |
720 $("#tabs").tabs("select", tab.parent().index()); | 714 $("#tabs").tabs("select", index); |
721 found.classList.add("focused"); | 715 found.classList.add("focused"); |
722 } | 716 } |
723 break; | 717 break; |
724 } | 718 } |
725 break; | 719 break; |
726 case "filters.respond": | 720 case "filters.respond": |
727 onFilterMessage(message.action, message.args[0]); | 721 onFilterMessage(message.action, message.args[0]); |
728 break; | 722 break; |
729 case "prefs.respond": | 723 case "prefs.respond": |
730 onPrefMessage(message.action, message.args[0]); | 724 onPrefMessage(message.action, message.args[0]); |
731 break; | 725 break; |
732 case "subscriptions.respond": | 726 case "subscriptions.respond": |
733 onSubscriptionMessage(message.action, message.args[0]); | 727 onSubscriptionMessage(message.action, message.args[0]); |
734 break; | 728 break; |
735 } | 729 } |
736 }); | 730 }); |
OLD | NEW |