Index: safari/ext/background.js |
=================================================================== |
--- a/safari/ext/background.js |
+++ b/safari/ext/background.js |
@@ -656,7 +656,73 @@ |
/* Storage */ |
- ext.storage = safari.extension.settings; |
+ ext.storage = { |
+ get: function(keys, callback) |
+ { |
+ var items = {}; |
+ var settings = safari.extension.settings; |
+ |
+ for (var i = 0; i < keys.length; i++) |
+ { |
+ var key = keys[i]; |
+ if (key in settings) |
+ items[key] = settings[key]; |
+ } |
+ |
+ setTimeout(callback, 0, items); |
+ }, |
+ set: function(key, value, callback) |
+ { |
+ safari.extension.settings[key] = value; |
+ |
+ if (callback) |
+ setTimeout(callback, 0); |
+ }, |
+ remove: function(key, callback) |
+ { |
+ delete safari.extension.settings[key]; |
+ |
+ if (callback) |
+ setTimeout(callback, 0); |
+ }, |
+ onChanged: new ext._EventTarget(), |
+ |
+ // Preferences were previously encoded as JSON for compatibility |
+ // with localStorage, which has been used on Chrome. |
+ migratePrefs: function(prefs) |
+ { |
+ var settings = safari.extension.settings; |
+ |
+ for (var key in settings) |
+ { |
+ if (key in prefs) |
+ { |
+ try |
+ { |
+ settings["pref:" + key] = JSON.parse(settings[key]); |
kzar
2015/03/09 15:10:29
Nit: Again what about the constant?
Sebastian Noack
2015/03/09 15:21:37
It's not available here, and IMO not worth beeing
|
+ } |
+ catch (e) |
+ { |
+ } |
+ |
+ delete settings[key]; |
+ } |
+ } |
+ } |
+ }; |
+ |
+ safari.extension.settings.addEventListener("change", function(event) |
+ { |
+ var changes = {}; |
+ var change = changes[event.key] = {}; |
+ |
+ if (event.oldValue != null) |
+ change.oldValue = event.oldValue; |
+ if (event.newValue != null) |
+ change.newValue = event.newValue; |
+ |
+ ext.storage.onChanged._dispatch(changes); |
+ }); |
/* Options */ |