|
|
@ -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; |
|
|
|
} |
|
|
|