-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStorage.js
More file actions
27 lines (17 loc) · 951 Bytes
/
Storage.js
File metadata and controls
27 lines (17 loc) · 951 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
"use strict";
var Storage = new function() {
this.haskey = function(name) { return name in window.localStorage; }
this.getstr = function(name) { return name in window.localStorage ? window.localStorage[name] : null; }
this.setstr = function(name, value) { window.localStorage[name] = value; }
this.getobj = function(name) { return name in window.localStorage ? JSON.parse(window.localStorage[name]) : null; }
this.setobj = function(name, value) { window.localStorage[name] = JSON.stringify(value); }
this.remove = function(name) { delete window.localStorage[name]; }
this.filename2savestatename = function(filename) {
var file2savestate = this.getobj("file2savestate");
return file2savestate ? file2savestate[filename] : null;
}
this.get_file = function(filename) {
var savestatename = this.filename2savestatename(filename);
return savestatename ? this.getobj(savestatename) : null;
}
}();