Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save MikeeI/1044feecf869be3744cc to your computer and use it in GitHub Desktop.
Save MikeeI/1044feecf869be3744cc 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