2020-01-10 08:36:57 +01:00
|
|
|
var save = JSON.parse(localStorage.getItem('save')) || {};
|
|
|
|
|
|
|
|
return {
|
|
|
|
get: get,
|
|
|
|
set: set
|
|
|
|
};
|
|
|
|
|
|
|
|
function move(coordinates) {
|
|
|
|
if(coordinates.path.length == 1) {
|
|
|
|
return coordinates;
|
|
|
|
} else {
|
|
|
|
var newFocus = coordinates.focus[coordinates.path[0]];
|
|
|
|
if (newFocus != undefined) {
|
|
|
|
var newCoordinates = {path: coordinates.path.slice(1), focus: newFocus};
|
|
|
|
return move(newCoordinates);
|
|
|
|
} else {
|
|
|
|
return coordinates;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function get(key) {
|
|
|
|
if(key != undefined) {
|
|
|
|
var outputCoordinates = move({path: key.split('.'), focus: save});
|
|
|
|
if(outputCoordinates.focus != undefined && outputCoordinates.path.length == 1) {
|
|
|
|
return outputCoordinates.focus[outputCoordinates.path[0]]
|
|
|
|
} else {
|
|
|
|
return null;
|
|
|
|
}
|
2020-02-02 19:16:27 +01:00
|
|
|
} else {
|
|
|
|
return save;
|
2020-01-10 08:36:57 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function set(key, value) {
|
|
|
|
if(key != undefined) {
|
|
|
|
var outputCoordinates = move({path: key.split('.'), focus: save});
|
|
|
|
while(outputCoordinates.path.length > 1) {
|
|
|
|
outputCoordinates.focus[outputCoordinates.path[0]] = {};
|
|
|
|
outputCoordinates.focus = outputCoordinates.focus[outputCoordinates.path[0]];
|
|
|
|
outputCoordinates.path = outputCoordinates.path.slice(1);
|
|
|
|
}
|
|
|
|
outputCoordinates.focus[outputCoordinates.path[0]] = value;
|
|
|
|
} else {
|
|
|
|
save = value;
|
|
|
|
}
|
|
|
|
localStorage.setItem('save', JSON.stringify(save));
|
|
|
|
}
|