mirror of
https://github.com/BewlyBewly/BewlyBewly.git
synced 2025-04-14 13:15:29 +00:00
29 lines
700 B
TypeScript
29 lines
700 B
TypeScript
import type {
|
|
MaybeRef,
|
|
RemovableRef,
|
|
StorageLikeAsync,
|
|
UseStorageAsyncOptions,
|
|
} from '@vueuse/core'
|
|
import {
|
|
useStorageAsync,
|
|
} from '@vueuse/core'
|
|
import { storage } from 'webextension-polyfill'
|
|
|
|
const storageLocal: StorageLikeAsync = {
|
|
removeItem(key: string) {
|
|
return storage.local.remove(key)
|
|
},
|
|
|
|
setItem(key: string, value: string) {
|
|
return storage.local.set({ [key]: value })
|
|
},
|
|
|
|
async getItem(key: string) {
|
|
return (await storage.local.get(key))[key]
|
|
},
|
|
}
|
|
|
|
export function useStorageLocal<T>(key: string, initialValue: MaybeRef<T>, options?: UseStorageAsyncOptions<T>): RemovableRef<T> {
|
|
return useStorageAsync(key, initialValue, storageLocal, options)
|
|
}
|