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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 var addFilter = wrapper({type: "filters.add"}, "text"); | 77 var addFilter = wrapper({type: "filters.add"}, "text"); |
78 var getFilters = wrapper({type: "filters.get"}, "subscriptionUrl"); | 78 var getFilters = wrapper({type: "filters.get"}, "subscriptionUrl"); |
79 var removeFilter = wrapper({type: "filters.remove"}, "text"); | 79 var removeFilter = wrapper({type: "filters.remove"}, "text"); |
80 | 80 |
81 var i18n = ext.i18n; | 81 var i18n = ext.i18n; |
82 var whitelistedDomainRegexp = /^@@\|\|([^\/:]+)\^\$document$/; | 82 var whitelistedDomainRegexp = /^@@\|\|([^\/:]+)\^\$document$/; |
83 var delayedSubscriptionSelection = null; | 83 var delayedSubscriptionSelection = null; |
84 | 84 |
85 var acceptableAdsUrl; | 85 var acceptableAdsUrl; |
86 | 86 |
87 // Loads options and sets UI elements accordingly | 87 // Loads options from localStorage and sets UI elements accordingly |
88 function loadOptions() | 88 function loadOptions() |
89 { | 89 { |
90 // Set page title to i18n version of "Adblock Plus Options" | 90 // Set page title to i18n version of "Adblock Plus Options" |
91 document.title = i18n.getMessage("options"); | 91 document.title = i18n.getMessage("options"); |
92 | 92 |
93 // Set links | 93 // Set links |
94 getPref("subscriptions_exceptionsurl", function(url) | 94 getPref("subscriptions_exceptionsurl", function(url) |
95 { | 95 { |
96 acceptableAdsUrl = url; | 96 acceptableAdsUrl = url; |
97 $("#acceptableAdsLink").attr("href", acceptableAdsUrl); | 97 $("#acceptableAdsLink").attr("href", acceptableAdsUrl); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 // Popuplate option checkboxes | 141 // Popuplate option checkboxes |
142 initCheckbox("shouldShowBlockElementMenu"); | 142 initCheckbox("shouldShowBlockElementMenu"); |
143 initCheckbox("show_devtools_panel"); | 143 initCheckbox("show_devtools_panel"); |
144 initCheckbox("shouldShowNotifications", { | 144 initCheckbox("shouldShowNotifications", { |
145 key: "notifications_ignoredcategories", | 145 key: "notifications_ignoredcategories", |
146 get: function(ignoredcategories) | 146 get: function(ignoredcategories) |
147 { | 147 { |
148 return ignoredcategories.indexOf("*") == -1; | 148 return ignoredcategories.indexOf("*") == -1; |
149 } | 149 } |
150 }); | 150 }); |
| 151 initCheckbox("safariContentBlocker", {onChange: function(checkbox) |
| 152 { |
| 153 var restartMessage = document.getElementById("restart-safari"); |
| 154 restartMessage.hidden = true; |
| 155 |
| 156 // When the user has chosen to use the legacy APIs but Safari has disabled |
| 157 // them we need to show a "Please restart Safari" message. |
| 158 if (!checkbox.checked) |
| 159 { |
| 160 ext.backgroundPage.sendMessage({type: "safari.contentBlockingActive"}, |
| 161 function (contentBlockingActive) |
| 162 { |
| 163 if (contentBlockingActive) |
| 164 restartMessage.hidden = false; |
| 165 }); |
| 166 } |
| 167 }}); |
151 | 168 |
152 getInfo("features", function(features) | 169 getInfo("features", function(features) |
153 { | 170 { |
154 if (!features.devToolsPanel) | 171 if (!features.devToolsPanel) |
155 document.getElementById("showDevtoolsPanelContainer").hidden = true; | 172 document.getElementById("showDevtoolsPanelContainer").hidden = true; |
| 173 |
| 174 // Only show the option for Safari content blocking API if the user is |
| 175 // running Safari and both the legacy and content blocking APIs are |
| 176 // available. |
| 177 document.getElementById("safariContentBlockerContainer").hidden = !( |
| 178 features.safariContentBlocker && |
| 179 typeof safari != "undefined" && |
| 180 "canLoad" in safari.self.tab && |
| 181 "onbeforeload" in Element.prototype |
| 182 ); |
156 }); | 183 }); |
157 getPref("notifications_showui", function(notifications_showui) | 184 getPref("notifications_showui", function(notifications_showui) |
158 { | 185 { |
159 if (!notifications_showui) | 186 if (!notifications_showui) |
160 document.getElementById("shouldShowNotificationsContainer").hidden = true; | 187 document.getElementById("shouldShowNotificationsContainer").hidden = true; |
161 }); | 188 }); |
162 | 189 |
163 // Register listeners in the background message responder | 190 // Register listeners in the background message responder |
164 ext.backgroundPage.sendMessage({ | 191 ext.backgroundPage.sendMessage({ |
165 type: "app.listen", | 192 type: "app.listen", |
166 filter: ["addSubscription", "focusSection"] | 193 filter: ["addSubscription", "focusSection"] |
167 }); | 194 }); |
168 ext.backgroundPage.sendMessage( | 195 ext.backgroundPage.sendMessage( |
169 { | 196 { |
170 type: "filters.listen", | 197 type: "filters.listen", |
171 filter: ["added", "loaded", "removed"] | 198 filter: ["added", "loaded", "removed"] |
172 }); | 199 }); |
173 ext.backgroundPage.sendMessage( | 200 ext.backgroundPage.sendMessage( |
174 { | 201 { |
175 type: "prefs.listen", | 202 type: "prefs.listen", |
176 filter: ["notifications_ignoredcategories", "notifications_showui", | 203 filter: ["notifications_ignoredcategories", "notifications_showui", |
177 "safari_contentblocker", "show_devtools_panel", | 204 "safariContentBlocker", "show_devtools_panel", |
178 "shouldShowBlockElementMenu"] | 205 "shouldShowBlockElementMenu"] |
179 }); | 206 }); |
180 ext.backgroundPage.sendMessage( | 207 ext.backgroundPage.sendMessage( |
181 { | 208 { |
182 type: "subscriptions.listen", | 209 type: "subscriptions.listen", |
183 filter: ["added", "disabled", "homepage", "lastDownload", "removed", | 210 filter: ["added", "disabled", "homepage", "lastDownload", "removed", |
184 "title", "downloadStatus", "downloading"] | 211 "title", "downloadStatus", "downloading"] |
185 }); | 212 }); |
186 | 213 |
187 // Load recommended subscriptions | 214 // Load recommended subscriptions |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
235 | 262 |
236 for (var i = 0; i < subscriptions.length; i++) | 263 for (var i = 0; i < subscriptions.length; i++) |
237 convertSpecialSubscription(subscriptions[i]); | 264 convertSpecialSubscription(subscriptions[i]); |
238 }); | 265 }); |
239 } | 266 } |
240 | 267 |
241 function initCheckbox(id, descriptor) | 268 function initCheckbox(id, descriptor) |
242 { | 269 { |
243 var checkbox = document.getElementById(id); | 270 var checkbox = document.getElementById(id); |
244 var key = descriptor && descriptor.key || id; | 271 var key = descriptor && descriptor.key || id; |
| 272 var onChange; |
| 273 if (descriptor && descriptor.onChange) |
| 274 onChange = descriptor.onChange.bind(undefined, checkbox); |
245 getPref(key, function(value) | 275 getPref(key, function(value) |
246 { | 276 { |
247 if (descriptor && descriptor.get) | 277 if (descriptor && descriptor.get) |
248 checkbox.checked = descriptor.get(value); | 278 checkbox.checked = descriptor.get(value); |
249 else | 279 else |
250 checkbox.checked = value; | 280 checkbox.checked = value; |
| 281 |
| 282 if (onChange) |
| 283 onChange(); |
251 }); | 284 }); |
252 | 285 |
253 checkbox.addEventListener("click", function() | 286 checkbox.addEventListener("click", function() |
254 { | 287 { |
255 if (descriptor && descriptor.toggle) | |
256 checkbox.checked = descriptor.toggle(); | |
257 togglePref(key); | 288 togglePref(key); |
258 }, false); | 289 }, false); |
| 290 |
| 291 if (onChange) |
| 292 checkbox.addEventListener("change", onChange); |
259 } | 293 } |
260 | 294 |
261 function loadRecommendations() | 295 function loadRecommendations() |
262 { | 296 { |
263 fetch("subscriptions.xml") | 297 fetch("subscriptions.xml") |
264 .then(function(response) | 298 .then(function(response) |
265 { | 299 { |
266 return response.text(); | 300 return response.text(); |
267 }) | 301 }) |
268 .then(function(text) | 302 .then(function(text) |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
498 document.getElementById("shouldShowNotificationsContainer").hidden = !valu
e; | 532 document.getElementById("shouldShowNotificationsContainer").hidden = !valu
e; |
499 return; | 533 return; |
500 case "notifications_ignoredcategories": | 534 case "notifications_ignoredcategories": |
501 key = "shouldShowNotifications"; | 535 key = "shouldShowNotifications"; |
502 value = value.indexOf("*") == -1; | 536 value = value.indexOf("*") == -1; |
503 break; | 537 break; |
504 } | 538 } |
505 | 539 |
506 var checkbox = document.getElementById(key); | 540 var checkbox = document.getElementById(key); |
507 if (checkbox) | 541 if (checkbox) |
| 542 { |
508 checkbox.checked = value; | 543 checkbox.checked = value; |
| 544 // Apparently modifying the checked attribute for a checkbox does not |
| 545 // dispatch the change event automatically... |
| 546 checkbox.dispatchEvent(new Event("change")); |
| 547 } |
509 } | 548 } |
510 | 549 |
511 function onFilterMessage(action, filter) | 550 function onFilterMessage(action, filter) |
512 { | 551 { |
513 switch (action) | 552 switch (action) |
514 { | 553 { |
515 case "loaded": | 554 case "loaded": |
516 reloadFilters(); | 555 reloadFilters(); |
517 break; | 556 break; |
518 case "added": | 557 case "added": |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
748 onFilterMessage(message.action, message.args[0]); | 787 onFilterMessage(message.action, message.args[0]); |
749 break; | 788 break; |
750 case "prefs.respond": | 789 case "prefs.respond": |
751 onPrefMessage(message.action, message.args[0]); | 790 onPrefMessage(message.action, message.args[0]); |
752 break; | 791 break; |
753 case "subscriptions.respond": | 792 case "subscriptions.respond": |
754 onSubscriptionMessage(message.action, message.args[0]); | 793 onSubscriptionMessage(message.action, message.args[0]); |
755 break; | 794 break; |
756 } | 795 } |
757 }); | 796 }); |
OLD | NEW |