PEE/src/stores.ts

42 lines
957 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', {
2022-01-04 20:26:05 +00:00
loop: true,
2022-01-05 01:14:23 +00:00
dh: false,
2022-01-02 15:02:09 +00:00
xpv: false,
xpi: false,
2022-01-05 01:14:23 +00:00
te: false,
2022-01-05 19:12:12 +00:00
eye: false,
2022-01-07 04:43:28 +00:00
ca: false,
pre: false,
prev: false,
2022-01-05 01:14:23 +00:00
blacklist: ['guro', 'scat', 'ryona', 'gore'],
sources: ['gelbooru.com',
'yande.re',
'capi-v2.sankakucomplex.com',
'api.rule34.xxx',
'danbooru.donmai.us',
'lolibooru.moe']
2022-01-02 13:12:19 +00:00
}));
2022-01-07 04:43:28 +00:00
export const appState = writable({
2022-01-07 06:45:30 +00:00
isCatalog: false,
foundPosts: [] as HTMLElement[]
2022-01-07 04:43:28 +00:00
});
appState.subscribe(v => {
console.log(v);
});
2022-01-02 13:12:19 +00:00
settings.subscribe(newVal => {
localSet('settings', newVal);
});