Index: chrome/ext/background.js |
=================================================================== |
--- a/chrome/ext/background.js |
+++ b/chrome/ext/background.js |
@@ -477,8 +477,54 @@ |
/* Storage */ |
- ext.storage = localStorage; |
+ ext.storage = { |
+ get: function(keys, callback) |
+ { |
+ chrome.storage.local.get(keys, callback); |
+ }, |
+ set: function(key, value, callback) |
+ { |
+ let items = {}; |
+ items[key] = value; |
+ chrome.storage.local.set(items, callback); |
+ }, |
+ remove: function(key, callback) |
+ { |
+ chrome.storage.local.remove(key, callback); |
+ }, |
+ onChanged: chrome.storage.onChanged, |
+ // Migrate localStorage to chrome.storage.local, |
+ // ignoring unkown and inavlid preferences. |
+ migratePrefs: function(prefs) |
+ { |
+ var items = {}; |
+ |
+ for (let key in localStorage) |
+ { |
+ var value = localStorage[key]; |
+ |
+ if (key in prefs) |
+ { |
+ try |
+ { |
+ items["pref:" + key] = JSON.parse(value); |
kzar
2015/03/09 15:10:29
Nit: Shouldn't this make use of the const keyPrefi
Sebastian Noack
2015/03/09 15:21:37
It's not available here, and IMO not worth beeing
kzar
2015/03/09 15:24:28
Fair enough, yea I agree it doesn't really matter.
|
+ } |
+ catch (e) |
+ { |
+ } |
+ } |
+ else if (key == "currentVersion") |
+ { |
+ items[key] = value; |
+ } |
+ } |
+ |
+ chrome.storage.local.set(items, function() { |
+ localStorage.clear(); |
+ }); |
+ } |
+ }; |
/* Options */ |