Browse Source

Dont use :has, remove localstorage references

pull/54/head
coomdev 1 year ago
parent
commit
3e5be6351a
  1. 27
      src/platform.ts
  2. 5
      src/stores.ts
  3. 2
      src/websites/index.ts

27
src/platform.ts

@ -164,28 +164,11 @@ export class Platform {
}
static async getValue<T>(key: string, def: T) {
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;
}
}
const ret = def;
const d = await chrome.storage.local.get([key]);
if (typeof d[key] == "string")
return { ...def, ...(await JSON.parse('' + d[key] || '{}')) } as T;
return ret;
}

5
src/stores.ts

@ -14,10 +14,7 @@ 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));
chrome.storage.local.set({ [key]: JSON.stringify(value) });
};
export const initial_settings = {

2
src/websites/index.ts

@ -100,7 +100,7 @@ export const FoolFuuka: QueryProcessor = {
export const KChan: QueryProcessor = {
getFileThumbnail: post => post.querySelector('figure.uploadCell')!,
getPost: (post) => post.querySelector('.innerPost')!,
postsWithFiles: (h) => [...(h || document).querySelectorAll('.postCell:has(figure)')],
postsWithFiles: (h) => ([...(h || document).querySelectorAll('.postCell')] as HTMLElement[]).filter(p => p.querySelector('figure')),
settingsHost: () => document.getElementById("navOptionsSpanThread") as any,
catalogControlHost: () => document.getElementById("divTools") as HTMLDivElement,
getImageLink: async function* (post: HTMLElement) {

Loading…
Cancel
Save