Add app.storage wrapper for handling localStorage

This commit is contained in:
Niko 2022-02-14 16:55:26 +01:00
parent 230b406722
commit 351e1a20b1
1 changed files with 19 additions and 0 deletions

View File

@ -84,6 +84,25 @@ app.template = {
},
}
app.storage = {
_init: function() {
if (localStorage['fedilove'] === undefined)
localStorage['fedilove'] = '{}';
},
get: function(key) {
app.storage._init();
const js = JSON.parse(localStorage['fedilove']);
return js[key];
},
set: function(key, value) {
app.storage._init();
const js = JSON.parse(localStorage['fedilove']);
js[key] = value;
localStorage['fedilove'] = JSON.stringify(js);
return true;
},
};
app.overlay = {
hideAll: function() {
document.querySelectorAll('.overlay')