mirror of
https://github.com/zombieFox/nightTab.git
synced 2024-11-23 00:23:28 +01:00
47 lines
812 B
JavaScript
47 lines
812 B
JavaScript
|
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()));
|
||
|
console.log(saveName + " saved");
|
||
|
};
|
||
|
|
||
|
var restore = function() {
|
||
|
var data = JSON.parse(get(saveName));
|
||
|
bookmarks.restore(data.bookmarks);
|
||
|
theme.restore(data.accent);
|
||
|
console.log(saveName + " restored");
|
||
|
};
|
||
|
|
||
|
var init = function() {
|
||
|
if (get(saveName)) {
|
||
|
restore();
|
||
|
} else {
|
||
|
save();
|
||
|
};
|
||
|
};
|
||
|
|
||
|
return {
|
||
|
init: init,
|
||
|
save: save,
|
||
|
clear: clear,
|
||
|
set: set,
|
||
|
get: get,
|
||
|
restore: restore
|
||
|
};
|
||
|
|
||
|
})();
|