nightTab/js/data.js

55 lines
956 B
JavaScript
Raw Normal View History

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);
};
var clear = function(key) {
localStorage.removeItem(key);
};
var save = function() {
set(saveName, JSON.stringify(state.get()));
2018-12-26 22:58:53 +01:00
console.log(saveName + " data saved");
2018-12-26 08:45:53 +01:00
};
var restore = function() {
var data = JSON.parse(get(saveName));
2018-12-27 00:46:53 +01:00
if (data) {
bookmarks.restore(data.bookmarks);
theme.restore(data.theme);
control.restore(data.control);
console.log(saveName + " data restored");
};
2018-12-26 08:45:53 +01:00
};
2018-12-26 16:24:52 +01:00
var wipe = function() {
clear(saveName);
};
2018-12-26 08:45:53 +01:00
var init = function() {
if (get(saveName)) {
restore();
} else {
save();
};
};
return {
init: init,
save: save,
clear: clear,
set: set,
get: get,
2018-12-26 16:24:52 +01:00
wipe: wipe,
2018-12-26 08:45:53 +01:00
restore: restore
};
})();