Index: options.js |
diff --git a/options.js b/options.js |
index 3055baa441154856edac4c5b9f556150d27fbb6c..0b560c91c23c6eba5c051736e326c483b0e1d7be 100644 |
--- a/options.js |
+++ b/options.js |
@@ -84,7 +84,7 @@ var delayedSubscriptionSelection = null; |
var acceptableAdsUrl; |
-// Loads options and sets UI elements accordingly |
+// Loads options from localStorage and sets UI elements accordingly |
function loadOptions() |
{ |
// Set page title to i18n version of "Adblock Plus Options" |
@@ -141,18 +141,23 @@ function loadOptions() |
// Popuplate option checkboxes |
initCheckbox("shouldShowBlockElementMenu"); |
initCheckbox("show_devtools_panel"); |
- initCheckbox("shouldShowNotifications", { |
- key: "notifications_ignoredcategories", |
- get: function(ignoredcategories) |
- { |
- return ignoredcategories.indexOf("*") == -1; |
- } |
- }); |
+ initCheckbox("shouldShowNotifications", "notifications_ignoredcategories"); |
+ initCheckbox("safariContentBlocker"); |
getInfo("features", function(features) |
{ |
if (!features.devToolsPanel) |
document.getElementById("showDevtoolsPanelContainer").hidden = true; |
+ |
+ // Only show the option for Safari content blocking API if the user is |
+ // running Safari and both the legacy and content blocking APIs are |
+ // available. |
+ document.getElementById("safariContentBlockerContainer").hidden = !( |
+ features.safariContentBlocker && |
+ typeof safari != "undefined" && |
+ "canLoad" in safari.self.tab && |
+ "onbeforeload" in Element.prototype |
+ ); |
}); |
getPref("notifications_showui", function(notifications_showui) |
{ |
@@ -174,7 +179,7 @@ function loadOptions() |
{ |
type: "prefs.listen", |
filter: ["notifications_ignoredcategories", "notifications_showui", |
- "safari_contentblocker", "show_devtools_panel", |
+ "safariContentBlocker", "show_devtools_panel", |
"shouldShowBlockElementMenu"] |
}); |
ext.backgroundPage.sendMessage( |
@@ -238,22 +243,18 @@ function reloadFilters() |
}); |
} |
-function initCheckbox(id, descriptor) |
+function initCheckbox(id, key) |
{ |
+ key = key || id; |
Sebastian Noack
2016/05/18 11:16:32
Note that when we retrieve the checkbox later in o
kzar
2016/05/18 11:32:07
Actually onPrefMessage already handles that, chang
Sebastian Noack
2016/05/18 11:36:45
Hm, seems that logic could be simplified altogethe
|
var checkbox = document.getElementById(id); |
- var key = descriptor && descriptor.key || id; |
+ |
getPref(key, function(value) |
{ |
- if (descriptor && descriptor.get) |
- checkbox.checked = descriptor.get(value); |
- else |
- checkbox.checked = value; |
+ onPrefMessage(key, value); |
}); |
checkbox.addEventListener("click", function() |
{ |
- if (descriptor && descriptor.toggle) |
- checkbox.checked = descriptor.toggle(); |
togglePref(key); |
}, false); |
} |
@@ -501,8 +502,21 @@ function onPrefMessage(key, value) |
key = "shouldShowNotifications"; |
value = value.indexOf("*") == -1; |
break; |
+ case "safariContentBlocker": |
+ var restartMessage = document.getElementById("restart-safari"); |
+ restartMessage.hidden = true; |
+ // When the user has chosen to use the legacy APIs but Safari has disabled |
+ // them we need to show a "Please restart Safari" message. |
+ if (!value) |
+ { |
+ ext.backgroundPage.sendMessage({type: "safari.contentBlockingActive"}, |
+ function (contentBlockingActive) |
Sebastian Noack
2016/05/18 11:16:32
Nit: Redundant space before arguments list.
kzar
2016/05/18 11:32:07
Done.
|
+ { |
+ if (contentBlockingActive) |
+ restartMessage.hidden = false; |
+ }); |
+ } |
} |
- |
var checkbox = document.getElementById(key); |
if (checkbox) |
checkbox.checked = value; |