Left: | ||
Right: |
LEFT | RIGHT |
---|---|
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 "use strict"; | |
19 | |
18 /** | 20 /** |
19 * Creates a wrapping function used to conveniently send a type of message. | 21 * Creates a wrapping function used to conveniently send a type of message. |
20 * | 22 * |
21 * @param {Object} baseMessage The part of the message that's always sent | 23 * @param {Object} baseMessage The part of the message that's always sent |
22 * @param {..string} paramKeys Any message keys that have dynamic values. The | 24 * @param {..string} paramKeys Any message keys that have dynamic values. The |
23 * returned function will take the corresponding | 25 * returned function will take the corresponding |
24 * values as arguments. | 26 * values as arguments. |
25 * @return The generated messaging function, optionally taking any values as | 27 * @return The generated messaging function, optionally taking any values as |
26 * specified by the paramKeys and finally an optional callback. | 28 * specified by the paramKeys and finally an optional callback. |
27 * (Although the value arguments are optional their index must be | 29 * (Although the value arguments are optional their index must be |
(...skipping 19 matching lines...) Expand all Loading... | |
47 if (arguments.length > 0) | 49 if (arguments.length > 0) |
48 { | 50 { |
49 var lastArg = arguments[arguments.length - 1]; | 51 var lastArg = arguments[arguments.length - 1]; |
50 if (typeof lastArg == "function") | 52 if (typeof lastArg == "function") |
51 callback = lastArg; | 53 callback = lastArg; |
52 | 54 |
53 for (var i = 0; i < arguments.length - (callback ? 1 : 0); i++) | 55 for (var i = 0; i < arguments.length - (callback ? 1 : 0); i++) |
54 message[paramKeys[i]] = arguments[i]; | 56 message[paramKeys[i]] = arguments[i]; |
55 } | 57 } |
56 | 58 |
57 ext.backgroundPage.sendMessage(message, callback); | 59 ext.backgroundPage.sendMessage(message, callback); |
kzar
2016/04/03 10:55:06
(I considered having this function return a promis
| |
58 }; | 60 }; |
59 } | 61 } |
60 | 62 |
61 var getDocLink = wrapper({type: "app.get", what: "doclink"}, "link"); | 63 var getDocLink = wrapper({type: "app.get", what: "doclink"}, "link"); |
Sebastian Noack
2016/04/03 15:05:14
This is redundant with getDocLink() from common.js
kzar
2016/04/03 15:50:19
I don't think adblockplusui/common.js is included
Sebastian Noack
2016/04/03 17:18:03
Given that common.js is already used by the first
kzar
2016/04/05 11:10:14
I think I prefer to leave this as it is.
| |
62 var getInfo = wrapper({type: "app.get"}, "what"); | 64 var getInfo = wrapper({type: "app.get"}, "what"); |
63 var getPref = wrapper({type: "prefs.get"}, "key"); | 65 var getPref = wrapper({type: "prefs.get"}, "key"); |
64 var togglePref = wrapper({type: "prefs.toggle"}, "key"); | 66 var togglePref = wrapper({type: "prefs.toggle"}, "key"); |
65 var getSubscriptions = wrapper({type: "subscriptions.get"}, | 67 var getSubscriptions = wrapper({type: "subscriptions.get"}, |
66 "downloadable", "special"); | 68 "downloadable", "special"); |
67 var removeSubscription = wrapper({type: "subscriptions.remove"}, "url"); | 69 var removeSubscription = wrapper({type: "subscriptions.remove"}, "url"); |
68 var addSubscription = wrapper({type: "subscriptions.add"}, | 70 var addSubscription = wrapper({type: "subscriptions.add"}, |
69 "url", "title", "homepage"); | 71 "url", "title", "homepage"); |
70 var toggleSubscription = wrapper({type: "subscriptions.toggle"}, | 72 var toggleSubscription = wrapper({type: "subscriptions.toggle"}, |
71 "url", "keepInstalled"); | 73 "url", "keepInstalled"); |
72 var updateSubscription = wrapper({type: "subscriptions.update"}, "url"); | 74 var updateSubscription = wrapper({type: "subscriptions.update"}, "url"); |
73 var isSubscriptionDownloading = wrapper({type: "subscriptions.isDownloading"}, | 75 var importRawFilters = wrapper({type: "filters.importRaw"}, |
74 "url"); | 76 "text", "removeExisting"); |
75 var importRawFilters = wrapper({type: "filters.importRaw"}, "text"); | |
76 var addFilter = wrapper({type: "filters.add"}, "text"); | 77 var addFilter = wrapper({type: "filters.add"}, "text"); |
77 var getFilters = wrapper({type: "filters.get"}, "subscriptionUrl"); | 78 var getFilters = wrapper({type: "filters.get"}, "subscriptionUrl"); |
78 var removeFilter = wrapper({type: "filters.remove"}, "text"); | 79 var removeFilter = wrapper({type: "filters.remove"}, "text"); |
79 | 80 |
80 var i18n = ext.i18n; | 81 var i18n = ext.i18n; |
81 var whitelistedDomainRegexp = /^@@\|\|([^\/:]+)\^\$document$/; | 82 var whitelistedDomainRegexp = /^@@\|\|([^\/:]+)\^\$document$/; |
82 var delayedSubscriptionSelection = null; | 83 var delayedSubscriptionSelection = null; |
83 | 84 |
85 var acceptableAdsUrl; | |
86 | |
84 // Loads options and sets UI elements accordingly | 87 // Loads options and sets UI elements accordingly |
85 function loadOptions() | 88 function loadOptions() |
86 { | 89 { |
87 // Set page title to i18n version of "Adblock Plus Options" | 90 // Set page title to i18n version of "Adblock Plus Options" |
88 document.title = i18n.getMessage("options"); | 91 document.title = i18n.getMessage("options"); |
89 | 92 |
90 // Set links | 93 // Set links |
91 getPref("subscriptions_exceptionsurl", function (url) | 94 getPref("subscriptions_exceptionsurl", function(url) |
92 { | 95 { |
93 $("#acceptableAdsLink").attr("href", url); | 96 acceptableAdsUrl = url; |
94 }); | 97 $("#acceptableAdsLink").attr("href", acceptableAdsUrl); |
95 getDocLink("acceptable_ads", function (url) | 98 }); |
99 getDocLink("acceptable_ads", function(url) | |
96 { | 100 { |
97 $("#acceptableAdsDocs").attr("href", url); | 101 $("#acceptableAdsDocs").attr("href", url); |
98 }); | 102 }); |
99 getDocLink("filterdoc", function (url) | 103 getDocLink("filterdoc", function(url) |
100 { | 104 { |
101 setLinks("filter-must-follow-syntax", url); | 105 setLinks("filter-must-follow-syntax", url); |
102 }); | 106 }); |
103 getInfo("application", function (application) | 107 getInfo("application", function(application) |
104 { | 108 { |
105 getInfo("platform", function (platform) | 109 getInfo("platform", function(platform) |
106 { | 110 { |
107 if (platform == "chromium" && application != "opera") | 111 if (platform == "chromium" && application != "opera") |
108 application = "chrome"; | 112 application = "chrome"; |
109 | 113 |
110 getDocLink(application + "_support", function (url) | 114 getDocLink(application + "_support", function(url) |
111 { | 115 { |
112 setLinks("found-a-bug", url); | 116 setLinks("found-a-bug", url); |
113 }); | 117 }); |
114 }); | 118 }); |
115 }); | 119 }); |
116 | 120 |
117 // Add event listeners | 121 // Add event listeners |
118 $("#updateFilterLists").click(updateFilterLists); | 122 $("#updateFilterLists").click(updateFilterLists); |
119 $("#startSubscriptionSelection").click(startSubscriptionSelection); | 123 $("#startSubscriptionSelection").click(startSubscriptionSelection); |
120 $("#subscriptionSelector").change(updateSubscriptionSelection); | 124 $("#subscriptionSelector").change(updateSubscriptionSelection); |
(...skipping 17 matching lines...) Expand all Loading... | |
138 initCheckbox("shouldShowBlockElementMenu"); | 142 initCheckbox("shouldShowBlockElementMenu"); |
139 initCheckbox("show_devtools_panel"); | 143 initCheckbox("show_devtools_panel"); |
140 initCheckbox("shouldShowNotifications", { | 144 initCheckbox("shouldShowNotifications", { |
141 key: "notifications_ignoredcategories", | 145 key: "notifications_ignoredcategories", |
142 get: function(ignoredcategories) | 146 get: function(ignoredcategories) |
143 { | 147 { |
144 return ignoredcategories.indexOf("*") == -1; | 148 return ignoredcategories.indexOf("*") == -1; |
145 } | 149 } |
146 }); | 150 }); |
147 | 151 |
148 getInfo("platform", function (platform) | 152 getInfo("features", function(features) |
Sebastian Noack
2016/04/03 15:05:14
Please use app.get[features] like the new options
kzar
2016/04/03 15:50:19
Done.
| |
149 { | 153 { |
150 if (platform != "chromium") | 154 if (!features.devToolsPanel) |
151 document.getElementById("showDevtoolsPanelContainer").hidden = true; | 155 document.getElementById("showDevtoolsPanelContainer").hidden = true; |
152 }); | 156 }); |
153 getPref("notifications_showui", function (notifications_showui) | 157 getPref("notifications_showui", function(notifications_showui) |
154 { | 158 { |
155 if (!notifications_showui) | 159 if (!notifications_showui) |
156 document.getElementById("shouldShowNotificationsContainer").hidden = true; | 160 document.getElementById("shouldShowNotificationsContainer").hidden = true; |
157 }); | 161 }); |
158 | 162 |
159 // Register listeners in the background message responder | 163 // Register listeners in the background message responder |
160 ext.backgroundPage.sendMessage({ | 164 ext.backgroundPage.sendMessage({ |
161 type: "app.listen", | 165 type: "app.listen", |
162 filter: ["addSubscription"] | 166 filter: ["addSubscription", "focusSection"] |
163 }); | 167 }); |
164 ext.backgroundPage.sendMessage( | 168 ext.backgroundPage.sendMessage( |
165 { | 169 { |
166 type: "filters.listen", | 170 type: "filters.listen", |
167 filter: ["added", "loaded", "removed"] | 171 filter: ["added", "loaded", "removed"] |
168 }); | 172 }); |
169 ext.backgroundPage.sendMessage( | 173 ext.backgroundPage.sendMessage( |
170 { | 174 { |
171 type: "prefs.listen", | 175 type: "prefs.listen", |
172 filter: ["notifications_ignoredcategories", "notifications_showui", | 176 filter: ["notifications_ignoredcategories", "notifications_showui", |
173 "safari_contentblocker", "show_devtools_panel", | 177 "safari_contentblocker", "show_devtools_panel", |
174 "shouldShowBlockElementMenu"] | 178 "shouldShowBlockElementMenu"] |
175 }); | 179 }); |
176 ext.backgroundPage.sendMessage( | 180 ext.backgroundPage.sendMessage( |
177 { | 181 { |
178 type: "subscriptions.listen", | 182 type: "subscriptions.listen", |
179 filter: ["added", "disabled", "homepage", "lastDownload", "removed", | 183 filter: ["added", "disabled", "homepage", "lastDownload", "removed", |
180 "title"] | 184 "title", "downloadStatus", "downloading"] |
181 }); | 185 }); |
182 | 186 |
183 // Load recommended subscriptions | 187 // Load recommended subscriptions |
184 loadRecommendations(); | 188 loadRecommendations(); |
185 | 189 |
186 // Show user's filters | 190 // Show user's filters |
187 reloadFilters(); | 191 reloadFilters(); |
188 } | 192 } |
189 $(loadOptions); | 193 $(loadOptions); |
190 | 194 |
191 // Reloads the displayed subscriptions and filters | 195 // Reloads the displayed subscriptions and filters |
192 function reloadFilters() | 196 function reloadFilters() |
193 { | 197 { |
194 // Load user filter URLs | 198 // Load user filter URLs |
195 var container = document.getElementById("filterLists"); | 199 var container = document.getElementById("filterLists"); |
196 while (container.lastChild) | 200 while (container.lastChild) |
197 container.removeChild(container.lastChild); | 201 container.removeChild(container.lastChild); |
198 | 202 |
199 getPref("subscriptions_exceptionsurl", function (acceptableAdsUrl) | 203 getSubscriptions(true, false, function(subscriptions) |
200 { | 204 { |
201 getSubscriptions(true, false, function(subscriptions) | 205 for (var i = 0; i < subscriptions.length; i++) |
202 { | 206 { |
203 for (var i = 0; i < subscriptions.length; i++) | 207 var subscription = subscriptions[i]; |
204 { | 208 if (subscription.url == acceptableAdsUrl) |
205 var subscription = subscriptions[i]; | 209 $("#acceptableAds").prop("checked", !subscription.disabled); |
206 if (subscription.url == acceptableAdsUrl) | 210 else |
207 $("#acceptableAds").prop("checked", !subscription.disabled); | 211 addSubscriptionEntry(subscription); |
208 else | 212 } |
209 addSubscriptionEntry(subscription); | |
210 } | |
211 }); | |
212 }); | 213 }); |
213 | 214 |
214 // User-entered filters | 215 // User-entered filters |
215 getSubscriptions(false, true, function(subscriptions) | 216 getSubscriptions(false, true, function(subscriptions) |
216 { | 217 { |
217 clearListBox("userFiltersBox"); | 218 clearListBox("userFiltersBox"); |
218 clearListBox("excludedDomainsBox"); | 219 clearListBox("excludedDomainsBox"); |
219 | 220 |
220 for (var i = 0; i < subscriptions.length; i++) | 221 for (var i = 0; i < subscriptions.length; i++) |
221 getFilters(subscriptions[i].url, function(filters) | 222 getFilters(subscriptions[i].url, function(filters) |
222 { | 223 { |
223 for (var j = 0; j < filters.length; j++) | 224 for (var j = 0; j < filters.length; j++) |
224 { | 225 { |
225 var filter = filters[j].text; | 226 var filter = filters[j].text; |
226 if (whitelistedDomainRegexp.test(filter)) | 227 if (whitelistedDomainRegexp.test(filter)) |
227 appendToListBox("excludedDomainsBox", RegExp.$1); | 228 appendToListBox("excludedDomainsBox", RegExp.$1); |
228 else | 229 else |
229 appendToListBox("userFiltersBox", filter); | 230 appendToListBox("userFiltersBox", filter); |
230 } | 231 } |
231 }); | 232 }); |
232 }); | 233 }); |
233 } | 234 } |
234 | 235 |
235 function initCheckbox(id, descriptor) | 236 function initCheckbox(id, descriptor) |
236 { | 237 { |
237 var checkbox = document.getElementById(id); | 238 var checkbox = document.getElementById(id); |
238 var key = descriptor && descriptor.key || id; | 239 var key = descriptor && descriptor.key || id; |
239 getPref(key, function (value) | 240 getPref(key, function(value) |
240 { | 241 { |
241 if (descriptor && descriptor.get) | 242 if (descriptor && descriptor.get) |
242 checkbox.checked = descriptor.get(value); | 243 checkbox.checked = descriptor.get(value); |
243 else | 244 else |
244 checkbox.checked = value; | 245 checkbox.checked = value; |
245 }); | 246 }); |
246 | 247 |
247 checkbox.addEventListener("click", function() | 248 checkbox.addEventListener("click", function() |
248 { | 249 { |
249 if (descriptor && descriptor.toggle) | 250 if (descriptor && descriptor.toggle) |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
384 addSubscription(url, title, null); | 385 addSubscription(url, title, null); |
385 } | 386 } |
386 | 387 |
387 $("#addSubscriptionContainer").hide(); | 388 $("#addSubscriptionContainer").hide(); |
388 $("#customSubscriptionContainer").hide(); | 389 $("#customSubscriptionContainer").hide(); |
389 $("#addSubscriptionButton").show(); | 390 $("#addSubscriptionButton").show(); |
390 } | 391 } |
391 | 392 |
392 function toggleAcceptableAds() | 393 function toggleAcceptableAds() |
393 { | 394 { |
394 getPref("subscriptions_exceptionsurl", function (url) | 395 toggleSubscription(acceptableAdsUrl, true); |
395 { | |
396 toggleSubscription(url, true); | |
397 }); | |
398 } | 396 } |
399 | 397 |
400 function findSubscriptionElement(subscription) | 398 function findSubscriptionElement(subscription) |
401 { | 399 { |
402 var children = document.getElementById("filterLists").childNodes; | 400 var children = document.getElementById("filterLists").childNodes; |
403 for (var i = 0; i < children.length; i++) | 401 for (var i = 0; i < children.length; i++) |
404 if (children[i]._subscription.url == subscription.url) | 402 if (children[i]._subscription.url == subscription.url) |
405 return children[i]; | 403 return children[i]; |
406 return null; | 404 return null; |
407 } | 405 } |
(...skipping 12 matching lines...) Expand all Loading... | |
420 title.href = subscription.homepage; | 418 title.href = subscription.homepage; |
421 else | 419 else |
422 title.href = subscription.url; | 420 title.href = subscription.url; |
423 | 421 |
424 var enabled = element.getElementsByClassName("subscriptionEnabled")[0]; | 422 var enabled = element.getElementsByClassName("subscriptionEnabled")[0]; |
425 enabled.checked = !subscription.disabled; | 423 enabled.checked = !subscription.disabled; |
426 | 424 |
427 var lastUpdate = element.getElementsByClassName("subscriptionUpdate")[0]; | 425 var lastUpdate = element.getElementsByClassName("subscriptionUpdate")[0]; |
428 lastUpdate.classList.remove("error"); | 426 lastUpdate.classList.remove("error"); |
429 | 427 |
430 if (subscription.downloadStatus && | 428 var downloadStatus = subscription.downloadStatus; |
431 subscription.downloadStatus != "synchronize_ok") | 429 if (subscription.isDownloading) |
430 { | |
431 lastUpdate.textContent = i18n.getMessage("filters_subscription_lastDownload_ inProgress"); | |
432 } | |
433 else if (downloadStatus && downloadStatus != "synchronize_ok") | |
432 { | 434 { |
433 var map = | 435 var map = |
434 { | 436 { |
435 "synchronize_invalid_url": "filters_subscription_lastDownload_invalidURL" , | 437 "synchronize_invalid_url": "filters_subscription_lastDownload_invalidURL" , |
436 "synchronize_connection_error": "filters_subscription_lastDownload_connec tionError", | 438 "synchronize_connection_error": "filters_subscription_lastDownload_connec tionError", |
437 "synchronize_invalid_data": "filters_subscription_lastDownload_invalidDat a", | 439 "synchronize_invalid_data": "filters_subscription_lastDownload_invalidDat a", |
438 "synchronize_checksum_mismatch": "filters_subscription_lastDownload_check sumMismatch" | 440 "synchronize_checksum_mismatch": "filters_subscription_lastDownload_check sumMismatch" |
439 }; | 441 }; |
440 if (subscription.downloadStatus in map) | 442 if (downloadStatus in map) |
441 lastUpdate.textContent = i18n.getMessage(map[subscription.downloadStatus] ); | 443 lastUpdate.textContent = i18n.getMessage(map[downloadStatus]); |
442 else | 444 else |
443 lastUpdate.textContent = subscription.downloadStatus; | 445 lastUpdate.textContent = downloadStatus; |
444 lastUpdate.classList.add("error"); | 446 lastUpdate.classList.add("error"); |
445 } | 447 } |
446 else if (subscription.lastDownload > 0) | 448 else if (subscription.lastDownload > 0) |
447 { | 449 { |
448 var timeDate = i18n_timeDateStrings(subscription.lastDownload * 1000); | 450 var timeDate = i18n_timeDateStrings(subscription.lastDownload * 1000); |
449 var messageID = (timeDate[1] ? "last_updated_at" : "last_updated_at_today"); | 451 var messageID = (timeDate[1] ? "last_updated_at" : "last_updated_at_today"); |
450 lastUpdate.textContent = i18n.getMessage(messageID, timeDate); | 452 lastUpdate.textContent = i18n.getMessage(messageID, timeDate); |
451 } | 453 } |
452 } | 454 } |
453 | 455 |
454 function onSubscriptionMessage(action, subscription) | 456 function onSubscriptionMessage(action, subscription) |
455 { | 457 { |
458 var element = findSubscriptionElement(subscription); | |
459 | |
456 switch (action) | 460 switch (action) |
457 { | 461 { |
458 case "title": | |
459 case "disabled": | 462 case "disabled": |
463 case "downloading": | |
464 case "downloadStatus": | |
460 case "homepage": | 465 case "homepage": |
461 case "lastDownload": | 466 case "lastDownload": |
462 case "downloadStatus": | 467 case "title": |
463 var element = findSubscriptionElement(subscription); | |
464 if (element) | 468 if (element) |
465 updateSubscriptionInfo(element, subscription); | 469 updateSubscriptionInfo(element, subscription); |
466 break; | 470 break; |
467 case "added": | 471 case "added": |
468 getPref("subscriptions_exceptionsurl", function (acceptableAdsUrl) | 472 if (subscription.url == acceptableAdsUrl) |
469 { | 473 $("#acceptableAds").prop("checked", true); |
470 if (subscription.url == acceptableAdsUrl) | 474 else if (!element) |
471 $("#acceptableAds").prop("checked", true); | 475 addSubscriptionEntry(subscription); |
472 else if (!findSubscriptionElement(subscription)) | |
473 addSubscriptionEntry(subscription); | |
474 }); | |
475 break; | 476 break; |
476 case "removed": | 477 case "removed": |
477 getPref("subscriptions_exceptionsurl", function (acceptableAdsUrl) | 478 if (subscription.url == acceptableAdsUrl) |
478 { | 479 $("#acceptableAds").prop("checked", false); |
479 if (subscription.url == acceptableAdsUrl) | 480 else if (element) |
480 { | 481 element.parentNode.removeChild(element); |
481 $("#acceptableAds").prop("checked", false); | |
482 } | |
483 else | |
484 { | |
485 var element = findSubscriptionElement(subscription); | |
486 if (element) | |
487 element.parentNode.removeChild(element); | |
488 } | |
489 }); | |
490 break; | 482 break; |
491 } | 483 } |
492 } | 484 } |
493 | 485 |
494 function onPrefMessage(key, value) | 486 function onPrefMessage(key, value) |
495 { | 487 { |
496 if (key == "notifications_showui") | 488 switch (key) |
Sebastian Noack
2016/04/03 15:05:14
Nit: There will be soon a third case for safari_co
kzar
2016/04/03 15:50:19
Done.
| |
497 { | 489 { |
498 document.getElementById("shouldShowNotificationsContainer").hidden = !value; | 490 case "notifications_showui": |
499 return; | 491 document.getElementById("shouldShowNotificationsContainer").hidden = !valu e; |
500 } | 492 return; |
501 else if (key == "notifications_ignoredcategories") | 493 case "notifications_ignoredcategories": |
502 { | 494 key = "shouldShowNotifications"; |
503 key = "shouldShowNotifications"; | 495 value = value.indexOf("*") == -1; |
504 value = value.indexOf("*") == -1; | 496 break; |
505 } | 497 } |
506 | 498 |
507 var checkbox = document.getElementById(key); | 499 var checkbox = document.getElementById(key); |
508 if (checkbox) | 500 if (checkbox) |
509 checkbox.checked = value; | 501 checkbox.checked = value; |
510 } | 502 } |
511 | 503 |
512 function onFilterMessage(action, filter) | 504 function onFilterMessage(action, filter) |
513 { | 505 { |
514 switch (action) | 506 switch (action) |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
569 var filterText = "@@||" + domain + "^$document"; | 561 var filterText = "@@||" + domain + "^$document"; |
570 addFilter(filterText); | 562 addFilter(filterText); |
571 } | 563 } |
572 | 564 |
573 // Adds filter text that user typed to the selection box | 565 // Adds filter text that user typed to the selection box |
574 function addTypedFilter(event) | 566 function addTypedFilter(event) |
575 { | 567 { |
576 event.preventDefault(); | 568 event.preventDefault(); |
577 | 569 |
578 var element = document.getElementById("newFilter"); | 570 var element = document.getElementById("newFilter"); |
579 addFilter(element.value, function (errors) | 571 addFilter(element.value, function(errors) |
580 { | 572 { |
581 if (errors.length > 0) | 573 if (errors.length > 0) |
582 alert(errors.join("\n")); | 574 alert(errors.join("\n")); |
583 else | 575 else |
584 element.value = ""; | 576 element.value = ""; |
585 }); | 577 }); |
586 } | 578 } |
587 | 579 |
588 // Removes currently selected whitelisted domains | 580 // Removes currently selected whitelisted domains |
589 function removeSelectedExcludedDomain(event) | 581 function removeSelectedExcludedDomain(event) |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
631 text += userFiltersBox.options[i].value + "\n"; | 623 text += userFiltersBox.options[i].value + "\n"; |
632 document.getElementById("rawFiltersText").value = text; | 624 document.getElementById("rawFiltersText").value = text; |
633 } | 625 } |
634 } | 626 } |
635 | 627 |
636 // Imports filters in the raw text box | 628 // Imports filters in the raw text box |
637 function importRawFiltersText() | 629 function importRawFiltersText() |
638 { | 630 { |
639 var text = document.getElementById("rawFiltersText").value; | 631 var text = document.getElementById("rawFiltersText").value; |
640 | 632 |
641 importRawFilters(text, function (errors) | 633 importRawFilters(text, true, function(errors) |
642 { | 634 { |
643 if (errors.length > 0) | 635 if (errors.length > 0) |
644 alert(errors.join("\n")); | 636 alert(errors.join("\n")); |
645 else | 637 else |
646 $("#rawFilters").hide(); | 638 $("#rawFilters").hide(); |
647 }); | 639 }); |
648 } | 640 } |
649 | 641 |
650 // Called when user explicitly requests filter list updates | 642 // Called when user explicitly requests filter list updates |
651 function updateFilterLists() | 643 function updateFilterLists() |
652 { | 644 { |
653 // Without the URL parameter this will update all subscriptions | 645 // Without the URL parameter this will update all subscriptions |
654 updateSubscription(); | 646 updateSubscription(); |
655 | |
656 // Display a message for any subscriptions that are currently being downloaded | |
657 getSubscriptions(true, false, function(subscriptions) | |
658 { | |
659 var inProgressMessage = i18n.getMessage( | |
660 "filters_subscription_lastDownload_inProgress" | |
661 ); | |
662 | |
663 for (var i = 0; i < subscriptions.length; i += 1) | |
664 { | |
665 var element = findSubscriptionElement(subscriptions[i]); | |
666 if (element) | |
667 { | |
668 var label = element.getElementsByClassName("subscriptionUpdate")[0]; | |
669 isSubscriptionDownloading(subscriptions[i].url, function (isDownloading) | |
Sebastian Noack
2016/04/03 15:11:41
Nit: Redundant space after function statement.
kzar
2016/04/03 15:50:19
Done.
| |
670 { | |
671 if (isDownloading) | |
672 label.textContent = inProgressMessage; | |
Sebastian Noack
2016/04/03 15:27:40
This will always be the label of the last subscrip
kzar
2016/04/03 16:11:33
Oops, you're right. Done.
| |
673 }); | |
674 } | |
675 } | |
676 }); | |
677 } | 647 } |
678 | 648 |
679 // Adds a subscription entry to the UI. | 649 // Adds a subscription entry to the UI. |
680 function addSubscriptionEntry(subscription) | 650 function addSubscriptionEntry(subscription) |
681 { | 651 { |
682 var template = document.getElementById("subscriptionTemplate"); | 652 var template = document.getElementById("subscriptionTemplate"); |
683 var element = template.cloneNode(true); | 653 var element = template.cloneNode(true); |
684 element.removeAttribute("id"); | 654 element.removeAttribute("id"); |
685 element._subscription = subscription; | 655 element._subscription = subscription; |
686 | 656 |
687 var removeButton = element.getElementsByClassName("subscriptionRemoveButton")[ 0]; | 657 var removeButton = element.getElementsByClassName("subscriptionRemoveButton")[ 0]; |
688 removeButton.setAttribute("title", removeButton.textContent); | 658 removeButton.setAttribute("title", removeButton.textContent); |
689 removeButton.textContent = "\xD7"; | 659 removeButton.textContent = "\xD7"; |
690 removeButton.addEventListener("click", function() | 660 removeButton.addEventListener("click", function() |
691 { | 661 { |
692 if (!confirm(i18n.getMessage("global_remove_subscription_warning"))) | 662 if (!confirm(i18n.getMessage("global_remove_subscription_warning"))) |
693 return; | 663 return; |
694 | 664 |
695 removeSubscription(subscription.url); | 665 removeSubscription(subscription.url); |
696 }, false); | 666 }, false); |
697 | 667 |
698 getPref("additional_subscriptions", function (additionalSubscriptions) | 668 getPref("additional_subscriptions", function(additionalSubscriptions) |
699 { | 669 { |
700 if (additionalSubscriptions.indexOf(subscription.url) != -1) | 670 if (additionalSubscriptions.indexOf(subscription.url) != -1) |
701 removeButton.style.visibility = "hidden"; | 671 removeButton.style.visibility = "hidden"; |
702 }); | 672 }); |
703 | 673 |
704 var enabled = element.getElementsByClassName("subscriptionEnabled")[0]; | 674 var enabled = element.getElementsByClassName("subscriptionEnabled")[0]; |
705 enabled.addEventListener("click", function() | 675 enabled.addEventListener("click", function() |
706 { | 676 { |
707 subscription.disabled = !subscription.disabled; | 677 subscription.disabled = !subscription.disabled; |
708 toggleSubscription(subscription.url, true); | 678 toggleSubscription(subscription.url, true); |
(...skipping 24 matching lines...) Expand all Loading... | |
733 links[i].addEventListener("click", arguments[i + 1], false); | 703 links[i].addEventListener("click", arguments[i + 1], false); |
734 } | 704 } |
735 } | 705 } |
736 } | 706 } |
737 | 707 |
738 ext.onMessage.addListener(function(message) | 708 ext.onMessage.addListener(function(message) |
739 { | 709 { |
740 switch (message.type) | 710 switch (message.type) |
741 { | 711 { |
742 case "app.respond": | 712 case "app.respond": |
743 if (message.action == "addSubscription") | 713 switch (message.action) |
744 { | 714 { |
745 var subscription = message.args[0]; | 715 case "addSubscription": |
746 startSubscriptionSelection(subscription.title, subscription.url); | 716 var subscription = message.args[0]; |
747 } | 717 startSubscriptionSelection(subscription.title, subscription.url); |
748 break; | 718 break; |
749 case "focus-section": | 719 case "focusSection": |
Sebastian Noack
2016/04/03 15:05:14
This should be handled the same way app.respond[ad
kzar
2016/04/03 15:50:19
Done. (Not tested yet as leaving for airport short
| |
750 var tabs = document.getElementsByClassName("ui-tabs-panel"); | 720 var tabs = document.getElementsByClassName("ui-tabs-panel"); |
751 for (var i = 0; i < tabs.length; i++) | 721 for (var i = 0; i < tabs.length; i++) |
752 { | 722 { |
753 var found = tabs[i].querySelector( | 723 var found = tabs[i].querySelector( |
754 "[data-section='" + message.section + "']" | 724 "[data-section='" + message.args[0] + "']" |
755 ); | 725 ); |
756 if (!found) | 726 if (!found) |
757 continue; | 727 continue; |
758 | 728 |
759 var previous = document.getElementsByClassName("focused"); | 729 var previous = document.getElementsByClassName("focused"); |
760 if (previous.length > 0) | 730 if (previous.length > 0) |
761 previous[0].classList.remove("focused"); | 731 previous[0].classList.remove("focused"); |
762 | 732 |
763 var tab = $("[href='#" + tabs[i].id + "']"); | 733 var tab = $("[href='#" + tabs[i].id + "']"); |
764 $("#tabs").tabs("select", tab.parent().index()); | 734 $("#tabs").tabs("select", tab.parent().index()); |
765 found.classList.add("focused"); | 735 found.classList.add("focused"); |
736 } | |
737 break; | |
766 } | 738 } |
767 break; | 739 break; |
768 case "filters.respond": | 740 case "filters.respond": |
769 onFilterMessage(message.action, message.args[0]); | 741 onFilterMessage(message.action, message.args[0]); |
770 break; | 742 break; |
771 case "prefs.respond": | 743 case "prefs.respond": |
772 onPrefMessage(message.action, message.args[0]); | 744 onPrefMessage(message.action, message.args[0]); |
773 break; | 745 break; |
774 case "subscriptions.respond": | 746 case "subscriptions.respond": |
775 onSubscriptionMessage(message.action, message.args[0]); | 747 onSubscriptionMessage(message.action, message.args[0]); |
776 break; | 748 break; |
777 } | 749 } |
778 }); | 750 }); |
LEFT | RIGHT |