-
-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathsettings.ts
More file actions
45 lines (36 loc) · 683 Bytes
/
Copy pathsettings.ts
File metadata and controls
45 lines (36 loc) · 683 Bytes
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
import { proxy, useSnapshot } from 'valtio'
export const config = proxy({
accessKey: '',
})
type Config = typeof config
export const useConfigStore = function () {
return useSnapshot(config)
}
/**
* storage
*/
const nsp = 'bilibili-app-recommend'
const key = `${nsp}.config`
export function load() {
const val = GM_getValue<Config>(key)
if (val && typeof val === 'object') {
Object.assign(config, val)
}
}
export function save() {
GM_setValue(key, config)
}
export function clean() {
GM_deleteValue(key)
}
/**
* update & persist
*/
export function updateConfig(c: Partial<Config>) {
Object.assign(config, c)
save()
}
/**
* load on init
*/
load()