-
Notifications
You must be signed in to change notification settings - Fork 0
/
storageManager.js
56 lines (41 loc) · 1.09 KB
/
storageManager.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
const conf = {}
for (const index in Object.keys(localStorage)) {
const key = localStorage.key(index)
if (!key.startsWith("func_")){
continue
}
const string = localStorage.getItem(key)
conf[key] = JSON.parse(string)
}
function getParameter(funcName, paramName) {
if (!funcName.startsWith("func_")){
return conf[funcName][paramName]
}
const func = conf[funcName]
if (func && func[paramName]){
const cached = func[paramName]
if (cached !== undefined) {
return cached
}
}
const defaultParam = tlui[funcName.replace("func_", "")].parameters[paramName]
switch(defaultParam.type){
case 'checkbox': return false
case 'enum[]': return []
case 'folderpath':
case 'filepath':
case 'string':
case 'enum':
return ''
}
}
function writeParameter(funcName, key, value) {
if (!conf[funcName]){
conf[funcName] = {}
}
conf[funcName][key] = value
localStorage.setItem(
funcName,
JSON.stringify(conf[funcName])
)
}