-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathstorage_handler.js
38 lines (32 loc) · 1.03 KB
/
storage_handler.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
async function getJson(url) {
let response = await fetch(url);
let data = await response.json();
return data;
}
async function getOriginalJSON(){
var actURL = window.location.href;
[actURL] = actURL.split('?');
var path = window.location.pathname;
var actURL = actURL.replace(path,'');
var userData = await getJson(actURL+'/LearnCity/data.json');
return userData;
}
async function initStorage(){
var userData2 = await getOriginalJSON();
localStorage.setItem('LearnStorage', JSON.stringify(userData2));
}
async function getStorage() {
// Retrieve the object from storage
var retrievedObject = localStorage.getItem('LearnStorage');
var learnjson = JSON.parse(retrievedObject);
return learnjson;
}
async function writeStorage(json) {
localStorage.setItem('LearnStorage', JSON.stringify(json));
}
async function main() {
if (localStorage.getItem("LearnStorage") === null) {
await initStorage();
}
}
export {main, getJson, getOriginalJSON, initStorage, getStorage, writeStorage };