-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstorage.ts
28 lines (24 loc) · 841 Bytes
/
storage.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
export const getStorage = async (key: string) => {
const storage = await browser.storage.local.get(key);
if (!storage[key]) {
throw new Error("Storage not found");
}
return storage[key];
};
export const setStorage = async (key: string, value: any) => {
const newStorage = { [key]: value };
await browser.storage.local.set(newStorage);
};
export const removeStorage = async (key: string) => {
const storage = await browser.storage.local.get(key);
let newStorage = { ...storage };
delete newStorage[key];
await browser.storage.local.set(newStorage);
};
// ========= business logic =========
export const increaseSearchNoBy1 = async () => {
const searchNum = await getStorage("searchNum");
const newSearchNum = Number(searchNum) + 1;
await setStorage("searchNum", `${newSearchNum}`);
return newSearchNum;
};