import { StorageSchema } from 'types/storage'; class StorageUtils { async get(key: K): Promise; async get( key: K, defaultValue?: StorageSchema[K], ): Promise; /** * 获取值 * @param key * @param defaultValue * @returns */ async get( key: K, defaultValue?: StorageSchema[K], ): Promise { const result = await chrome.storage.local.get([key]); return (result[key] ?? defaultValue) as StorageSchema[K] | undefined; } /** * 设置值 * @param key * @param value */ async set(key: K, value: StorageSchema[K]): Promise { await chrome.storage.local.set({ [key]: value }); } /** * 删除值 * @param key */ async remove(key: keyof StorageSchema): Promise { await chrome.storage.local.remove([key]); } } export const storageUtil = new StorageUtils();