Created
April 13, 2015 10:43
-
-
Save janbaykara/adb1afe593545f4d662f to your computer and use it in GitHub Desktop.
A little class for syncing and accessing chrome.sync() data functionally.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Class for simultaneously pushing/retrieving from foreign chrome.sync and local object. | |
var Storage = function() { | |
this.set = function(property,value,cb) { | |
this[property] = value | |
chrome.storage.sync.set( | |
{property: value}, | |
function sentToStorage(storage) { | |
console.log("Set new "+property+" = "+value) | |
if(typeof cb === 'function') cb() | |
} | |
) | |
return this[property] | |
} | |
this.update = function(property,cb) { | |
var that = this | |
chrome.storage.sync.get(property, function receivedPropertyFromStorage(storage) { | |
console.log("New "+property+" = "+storage[property]) | |
that[property] = storage[property] | |
if(typeof cb === 'function') cb(that[property]) | |
}) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment