2016-04-22 12:44:23 +00:00
|
|
|
function localStorageInterface(){}
|
2016-05-03 20:28:47 +00:00
|
|
|
localStorageInterface.prototype={dataset:[],dataset_keys:[],set:function(a,b,d){b=b.toString();var c=this.dataset.indexOf(a);if(-1==c)return!1;-1==this.dataset_keys[c].indexOf(b)&&(this.dataset_keys[c].push(b),localStorage.setItem(a,JSON.stringify(this.dataset_keys[c])));localStorage.setItem(a+"_"+b,JSON.stringify(d));return!0},get:function(a,b){b=b.toString();return-1==this.dataset.indexOf(a)?!1:JSON.parse(localStorage.getItem(a+"_"+b))},del:function(a,b){b=b.toString();var d=this.dataset.indexOf(a);
|
|
|
|
if(-1==d)return!1;var c=this.dataset_keys[d].indexOf(b);if(-1==c)return!1;localStorage.removeItem(a+"_"+b);this.dataset_keys[d].splice(c,1);localStorage.setItem(a,JSON.stringify(this.dataset_keys[d]));return!0},createDataset:function(a){if("string"!=typeof a)return!1;if(-1<this.dataset.indexOf(a))return!0;var b=localStorage.getItem(a);null!=b?(this.dataset.push(a),this.dataset_keys.push(JSON.parse(b))):(this.dataset.push(a),this.dataset_keys.push([]),localStorage.setItem(a,JSON.stringify([])));return!0},
|
|
|
|
keys:function(a){a=this.dataset.indexOf(a);return-1==a?!1:this.dataset_keys[a]},"export":function(a){var b=this.dataset.indexOf(a);if(-1==b)return!1;for(var d={},c=0;c<this.dataset_keys[b].length;c++)d[this.dataset_keys[b][c]]=this.get(a,this.dataset_keys[b][c]);return d},"import":function(a,b){-1==this.dataset.indexOf(a)?this.createDataset(a):this.clear(a);for(var d in b)this.set(a,d,b[d]);return!0},clear:function(a){var b=this.dataset.indexOf(a);if(-1==b)return!1;var d=this["export"](a),c;for(c in d)this.del(a,
|
|
|
|
c);this.dataset_keys[b]=[];localStorage.setItem(a,JSON.stringify(this.dataset_keys[b]));return!0}};var lsi=new localStorageInterface;
|