From 847d19942f0a2e854fc3d32e5b45c80d9a369d9f Mon Sep 17 00:00:00 2001 From: michaelyuhe <2312744987@qq.com> Date: Mon, 11 Dec 2023 15:42:55 +0800 Subject: [PATCH] feat: add new utils --- src/util.ts | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 src/util.ts diff --git a/src/util.ts b/src/util.ts new file mode 100644 index 0000000..a964477 --- /dev/null +++ b/src/util.ts @@ -0,0 +1,23 @@ +export function setStorage(key: string, value: V) { + return new Promise((resolve, reject) => { + chrome.storage.local.set({ [key]: value }, () => { + if (chrome.runtime.lastError) { + reject(chrome.runtime.lastError); + } else { + resolve(true); + } + }); + }); +} + +export function getStorage(key: string): Promise { + return new Promise((resolve, reject) => { + chrome.storage.local.get(key, (result) => { + if (chrome.runtime.lastError) { + reject(chrome.runtime.lastError); + } else { + resolve(result[key]); + } + }); + }); +}