5 lines
1.5 KiB
JavaScript
5 lines
1.5 KiB
JavaScript
function localStorageInterface(){}
|
|
localStorageInterface.prototype={dataset:[],dataset_keys:[],set:function(a,b,d){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){return-1==this.dataset.indexOf(a)?!1:JSON.parse(localStorage.getItem(a+"_"+b))},del:function(a,b){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){if(-1==this.dataset.indexOf(a))this.createDataset(a);else{var d=this["export"](a),c;for(c in d)this.del(a,c)}for(c in b)this.set(a,c,b[c]);return!0}};var lsi=new localStorageInterface;
|