Index: safari/ext/background.js |
=================================================================== |
--- a/safari/ext/background.js |
+++ b/safari/ext/background.js |
@@ -670,7 +670,67 @@ |
/* 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(mapFunc) |
+ { |
+ var settings = safari.extension.settings; |
+ |
+ for (var key in settings) |
+ { |
+ var item = mapFunc(key, settings[key]); |
+ if (item) |
Wladimir Palant
2015/03/16 12:20:26
Add |&& item.key != key| here? I think we will kee
Sebastian Noack
2015/03/16 12:54:34
Done.
|
+ { |
+ delete settings[key]; |
+ settings[item.key] = item.value; |
+ } |
+ } |
+ } |
+ }; |
+ |
+ 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 */ |