2022-01-02 13:12:19 +00:00
|
|
|
import { writable } from "svelte/store";
|
2022-04-14 19:52:21 +00:00
|
|
|
import type { HydrusClient } from "./hydrus";
|
2022-01-09 14:29:51 +00:00
|
|
|
import type { Booru } from "./thirdeye";
|
2022-01-02 13:12:19 +00:00
|
|
|
|
2022-07-24 17:22:39 +00:00
|
|
|
// Todo: use GM get/setValue instead?
|
|
|
|
export const localLoad = async <T>(key: string, def: T) => {
|
|
|
|
const isinls = ('__pee__' + key) in localStorage;
|
|
|
|
const ret = isinls
|
|
|
|
? { ...def, ...JSON.parse(localStorage.getItem('__pee__' + key)!) } as T
|
2022-01-02 13:12:19 +00:00
|
|
|
: def;
|
|
|
|
|
2022-07-24 17:22:39 +00:00
|
|
|
if (execution_mode != "userscript") {
|
|
|
|
if (isinls) {
|
|
|
|
delete localStorage[('__pee__' + key)];
|
|
|
|
await chrome.storage.local.set({
|
|
|
|
[key]: JSON.stringify(ret)
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
const d = await chrome.storage.local.get([key]);
|
|
|
|
if (typeof d[key] == "string")
|
|
|
|
return { ...def, ...(await JSON.parse('' + d[key] || '{}')) } as T;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
};
|
|
|
|
|
|
|
|
const localSet = (key: string, value: any) => {
|
|
|
|
if (execution_mode != "userscript")
|
|
|
|
chrome.storage.local.set({ [key]: JSON.stringify(value) });
|
|
|
|
else
|
|
|
|
localStorage.setItem('__pee__' + key, JSON.stringify(value));
|
|
|
|
};
|
2022-01-02 13:12:19 +00:00
|
|
|
|
2022-04-14 20:07:13 +00:00
|
|
|
export const initial_settings = localLoad('settingsv2', {
|
2022-01-04 20:26:05 +00:00
|
|
|
loop: true,
|
2022-01-05 01:14:23 +00:00
|
|
|
dh: false,
|
2022-07-24 17:22:39 +00:00
|
|
|
pmeth: 4,
|
2022-01-02 15:02:09 +00:00
|
|
|
xpv: false,
|
|
|
|
xpi: false,
|
2022-04-14 19:52:21 +00:00
|
|
|
hyd: false,
|
2022-07-23 13:30:46 +00:00
|
|
|
notcata: false,
|
2022-04-14 19:52:21 +00:00
|
|
|
ak: '',
|
|
|
|
auto_embed: 0,
|
|
|
|
auto_tags: '',
|
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-08 07:29:19 +00:00
|
|
|
sh: false,
|
|
|
|
ep: false,
|
2022-04-11 21:31:32 +00:00
|
|
|
tm: false,
|
2022-06-08 22:35:05 +00:00
|
|
|
dvc: false,
|
2022-01-12 04:18:50 +00:00
|
|
|
expte: false,
|
2022-01-26 20:45:15 +00:00
|
|
|
mdist: -1,
|
|
|
|
phash: false,
|
2022-01-12 08:09:30 +00:00
|
|
|
hotlink: false,
|
2022-07-19 15:29:49 +00:00
|
|
|
jpeg: false,
|
2022-01-13 07:38:50 +00:00
|
|
|
vercheck: false,
|
2022-06-08 22:35:05 +00:00
|
|
|
cache: undefined as (boolean | undefined), // meaning defaults to false, except on b4k
|
2022-01-16 15:47:13 +00:00
|
|
|
fhost: 0,
|
|
|
|
maxe: 5,
|
2022-01-12 04:18:50 +00:00
|
|
|
conc: 8,
|
2022-01-09 19:41:04 +00:00
|
|
|
ho: false,
|
2022-07-22 18:47:39 +00:00
|
|
|
blacklist: [] as string[],
|
2022-07-24 17:22:39 +00:00
|
|
|
rsources: [] as (Omit<Booru, 'quirks'> & { view: string, disabled?: boolean })[],
|
2022-04-14 20:07:13 +00:00
|
|
|
});
|
|
|
|
|
2022-07-24 17:22:39 +00:00
|
|
|
export const settings = writable<Awaited<typeof initial_settings>>();
|
|
|
|
|
|
|
|
initial_settings.then(v => {
|
|
|
|
settings.set(v);
|
|
|
|
});
|
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,
|
2022-01-08 22:08:20 +00:00
|
|
|
is4chanX: false,
|
2022-04-14 19:52:21 +00:00
|
|
|
akValid: false,
|
|
|
|
herror: '' as string | undefined,
|
|
|
|
client: null as HydrusClient | null,
|
2022-01-07 06:45:30 +00:00
|
|
|
foundPosts: [] as HTMLElement[]
|
2022-01-07 04:43:28 +00:00
|
|
|
});
|
|
|
|
|
2022-01-02 13:12:19 +00:00
|
|
|
settings.subscribe(newVal => {
|
2022-01-09 14:29:51 +00:00
|
|
|
localSet('settingsv2', newVal);
|
2022-01-02 13:12:19 +00:00
|
|
|
});
|