-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathlocalstorage.js
107 lines (57 loc) · 1.61 KB
/
localstorage.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
// load local storage
function loadLS() {
// if selected file exists in storage
if (getStorage('selectedFile')) {
// load selected file from storage
selectedFile = JSON.parse(getStorage('selectedFile'));
} else {
// load empty file
changeSelectedFile(',,', '', '', '', '', [0, 0], [0, 0], false);
}
// if modified files exist in storage
// and not embed
if (getStorage('modifiedFiles') && !isEmbed) {
// load modified files from storage
modifiedFiles = Object.fromEntries(JSON.parse(getStorage('modifiedFiles')));
} else {
modifiedFiles = {};
}
// if modified repos exist in storage
if (getStorage('modifiedRepos')) {
// load modified repos from storage
modifiedRepos = Object.fromEntries(JSON.parse(getStorage('modifiedRepos')));
} else {
modifiedRepos = {};
}
setupLiveView();
setupCodeitApp();
}
// files
function updateSelectedFileLS() {
if (!isEmbed) {
setStorage('selectedFile', JSON.stringify(selectedFile));
}
}
function updateModFilesLS() {
if (!isEmbed) {
setStorage('modifiedFiles', JSON.stringify(Object.entries(modifiedFiles)));
}
}
// repos
function updateModReposLS() {
setStorage('modifiedRepos', JSON.stringify(Object.entries(modifiedRepos)));
}
// miscellaneous
function saveTreeLocLS(treeLoc) {
if (!isEmbed) {
setStorage('tree', treeLoc.join());
}
}
function saveSidebarStateLS() {
if (!isEmbed) {
setStorage('sidebar', body.classList.contains('expanded'));
}
}
function saveGitTokenLS(gitToken) {
setStorage('gitToken', gitToken);
}