41 lines
919 B
JavaScript
41 lines
919 B
JavaScript
define(function (require) {
|
|
var EventObject = require("./EventObject.js");
|
|
var extension = require("./extensionPort.js");
|
|
|
|
var Storage = function () {
|
|
var __ = this;
|
|
var st = {};
|
|
|
|
EventObject.apply(this, Array.prototype.slice.call(arguments));
|
|
|
|
this.get = function (key) {
|
|
return st[key] || "";
|
|
};
|
|
this.put = function (key, value) {
|
|
if (typeof (value) !== 'string') {
|
|
value = JSON.stringify(value);
|
|
}
|
|
st[key] = value + '';
|
|
extension.sendMessage({ action: "setStorage", detail: { key: value } });
|
|
};
|
|
this.remove = function (key) {
|
|
delete st[key];
|
|
};
|
|
this.obj=function(key) {
|
|
var value = __.get(key);
|
|
if (!value)
|
|
return null;
|
|
|
|
return JSON.parse(value);
|
|
}
|
|
|
|
extension.sendMessage({ action: "getStorage" }, function (m) {
|
|
st = m.detail;
|
|
});
|
|
};
|
|
Storage.prototype = Object.create(EventObject);
|
|
Storage.constructor = Storage;
|
|
|
|
return new Storage();
|
|
});
|