PEE/src/stores.ts

23 lines
546 B
TypeScript
Raw Normal View History

2022-01-02 13:12:19 +00:00
import { writable } from "svelte/store";
const localLoad = (key: string, def: any) =>
2022-01-02 14:37:19 +00:00
('__pee__' + key) in localStorage
2022-01-02 13:12:19 +00:00
? JSON.parse(localStorage.getItem('__pee__' + key)!)
: def;
const localSet = (key: string, value: any) =>
localStorage.setItem('__pee__' + key, JSON.stringify(value));
export const settings = writable(localLoad('settings', {
apv: false,
2022-01-02 15:02:09 +00:00
xpv: false,
xpi: false,
2022-01-02 13:12:19 +00:00
apa: false,
blacklist: [],
sources: []
}));
settings.subscribe(newVal => {
localSet('settings', newVal);
});