Index: safari/ext/background.js |
=================================================================== |
--- a/safari/ext/background.js |
+++ b/safari/ext/background.js |
@@ -647,7 +647,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); |
Wladimir Palant
2015/03/12 23:05:37
Did you verify that this works on all Safari versi
Sebastian Noack
2015/03/12 23:35:29
I saw this one coming. I checked MDN and made the
|
+ }, |
+ 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]); |
+ } |
+ 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 */ |