Skip to content

Instantly share code, notes, and snippets.

@z-------------
Last active March 21, 2016 11:20
Show Gist options
  • Save z-------------/11287063 to your computer and use it in GitHub Desktop.
Save z-------------/11287063 to your computer and use it in GitHub Desktop.
A simple, localStorage-like way to interact with Chrome's Storage API.
var scs = {
set: function(key,value,type) {
var kvo = {};
kvo[key] = value;
var cs;
if (type == "local") {
cs = chrome.storage.local;
} else {
cs = chrome.storage.sync;
}
cs.set(kvo);
},
get: function(key,type) {
var retVal;
var cs;
if (type == "local") {
cs = chrome.storage.local;
} else {
cs = chrome.storage.sync;
}
cs.get(key,function(r){
retVal = r[key];
});
return retVal;
}
}
// scs.set("waffles",true)
// scs.get("waffles")
// --> true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment