Can embed any file in a PNG/WebM/GIF/JPEG and upload it to a third-party host through 4chan
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

98 lines
2.4 KiB

import { writable } from "svelte/store";
import type { HydrusClient } from "./hydrus";
import type { Booru } from "./thirdeye";
// Todo: use GM get/setValue instead?
export const localLoad = async <T>(key: string, def: T) => {
if (execution_mode == "worker") {
return def;
}
const isinls = ('__pee__' + key) in localStorage;
let ret: T;
if (isinls) {
let it = localStorage.getItem('__pee__' + key);
if (it === "undefined")
it = null;
ret = { ...def, ...JSON.parse(it || '{}') } as T;
} else
ret = def;
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 == "worker") {
return;
}
if (execution_mode != "userscript")
chrome.storage.local.set({ [key]: JSON.stringify(value) });
else
localStorage.setItem('__pee__' + key, JSON.stringify(value));
};
export const initial_settings = localLoad('settingsv2', {
loop: true,
dh: false,
pmeth: 5,
xpv: false,
xpi: false,
hyd: false,
notcata: false,
ak: '',
auto_embed: 0,
auto_tags: '',
te: false,
eye: false,
ca: false,
pre: false,
prev: false,
sh: false,
ep: false,
tm: false,
dvc: false,
expte: false,
mdist: -1,
phash: false,
hotlink: false,
jpeg: false,
vercheck: false,
cache: undefined as (boolean | undefined), // meaning defaults to false, except on b4k
fhost: 0,
maxe: 5,
conc: 8,
ho: false,
blacklist: [] as string[],
rsources: [] as (Omit<Booru, 'quirks'> & { view: string, disabled?: boolean })[],
});
export const settings = writable<Awaited<typeof initial_settings>>();
initial_settings.then(v => {
settings.set(v);
});
export const appState = writable({
isCatalog: false,
is4chanX: false,
akValid: false,
herror: '' as string | undefined,
client: null as HydrusClient | null,
foundPosts: [] as HTMLElement[]
});
settings.subscribe(newVal => {
localSet('settingsv2', newVal);
});