2018-12-26 08:45:53 +01:00
|
|
|
var data = (function() {
|
|
|
|
|
|
|
|
var saveName = "nitghTab";
|
|
|
|
|
|
|
|
var set = function(key, data) {
|
|
|
|
localStorage.setItem(key, data);
|
|
|
|
};
|
|
|
|
|
|
|
|
var get = function(key) {
|
|
|
|
return localStorage.getItem(key);
|
|
|
|
};
|
|
|
|
|
2019-01-13 23:54:48 +01:00
|
|
|
var remove = function(key) {
|
2018-12-26 08:45:53 +01:00
|
|
|
localStorage.removeItem(key);
|
|
|
|
};
|
|
|
|
|
|
|
|
var save = function() {
|
2019-01-03 23:30:27 +01:00
|
|
|
var data = {
|
2019-01-06 16:47:08 +01:00
|
|
|
version: version.get(),
|
2019-01-03 23:30:27 +01:00
|
|
|
state: state.get(),
|
|
|
|
bookmarks: bookmarks.get()
|
|
|
|
};
|
|
|
|
set(saveName, JSON.stringify(data));
|
2018-12-27 19:41:40 +01:00
|
|
|
console.log("data saved");
|
2018-12-26 08:45:53 +01:00
|
|
|
};
|
|
|
|
|
2019-01-13 23:54:48 +01:00
|
|
|
var wipe = function() {
|
|
|
|
remove(saveName);
|
|
|
|
};
|
|
|
|
|
2019-01-03 23:30:27 +01:00
|
|
|
var load = function() {
|
2019-05-26 10:09:15 +02:00
|
|
|
return JSON.parse(get(saveName));
|
2018-12-26 08:45:53 +01:00
|
|
|
};
|
|
|
|
|
2019-05-23 20:15:14 +02:00
|
|
|
var restore = function(data) {
|
2019-01-06 16:47:08 +01:00
|
|
|
if (data) {
|
|
|
|
if (!("version" in data) || data.version != version.get()) {
|
2019-04-18 14:30:40 +02:00
|
|
|
console.log("data version " + data.version + " found less than current");
|
2019-02-03 14:51:54 +01:00
|
|
|
data = update.run(data);
|
2019-01-06 16:47:08 +01:00
|
|
|
set(saveName, JSON.stringify(data));
|
|
|
|
} else {
|
2019-04-18 14:30:40 +02:00
|
|
|
console.log("data version " + version.get() + " no need to run update");
|
2019-01-06 16:47:08 +01:00
|
|
|
};
|
|
|
|
} else {
|
|
|
|
console.log("no data found to load");
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
var init = function() {
|
2019-05-23 20:15:14 +02:00
|
|
|
restore(load());
|
2019-01-06 16:47:08 +01:00
|
|
|
};
|
|
|
|
|
2018-12-26 08:45:53 +01:00
|
|
|
return {
|
2019-01-06 16:47:08 +01:00
|
|
|
init: init,
|
2018-12-26 08:45:53 +01:00
|
|
|
save: save,
|
2019-01-13 23:54:48 +01:00
|
|
|
remove: remove,
|
2018-12-26 08:45:53 +01:00
|
|
|
set: set,
|
|
|
|
get: get,
|
2019-01-06 16:47:08 +01:00
|
|
|
load: load,
|
2019-05-23 20:15:14 +02:00
|
|
|
wipe: wipe,
|
|
|
|
restore: restore
|
2018-12-26 08:45:53 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
})();
|