forked from zombieFox/nightTab
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdata.js
More file actions
64 lines (53 loc) · 1.25 KB
/
Copy pathdata.js
File metadata and controls
64 lines (53 loc) · 1.25 KB
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
var data = (function() {
var saveName = "nitghTab";
var set = function(key, data) {
localStorage.setItem(key, data);
};
var get = function(key) {
return localStorage.getItem(key);
};
var remove = function(key) {
localStorage.removeItem(key);
};
var save = function() {
var data = {
version: version.get(),
state: state.get(),
bookmarks: bookmarks.get()
};
set(saveName, JSON.stringify(data));
// console.log("data saved");
};
var wipe = function() {
remove(saveName);
};
var load = function() {
return JSON.parse(get(saveName));
};
var restore = function(data) {
if (data) {
if (!("version" in data) || data.version != version.get()) {
console.log("data version " + data.version + " found less than current");
data = update.run(data);
set(saveName, JSON.stringify(data));
} else {
console.log("data version " + version.get() + " no need to run update");
};
} else {
console.log("no data found to load");
};
};
var init = function() {
restore(load());
};
return {
init: init,
save: save,
remove: remove,
set: set,
get: get,
load: load,
wipe: wipe,
restore: restore
};
})();