summaryrefslogtreecommitdiff
path: root/source/helpers/used-storage.ts
diff options
context:
space:
mode:
authorGravatar Federico Brigante <me@fregante.com> 2023-05-04 17:52:33 +0800
committerGravatar GitHub <noreply@github.com> 2023-05-04 09:52:33 +0000
commit0f0d7435a649466084fab40bb7fe0481b0c73dba (patch)
tree8f78f48062c8d2599a6850c3c74b18957108f44b /source/helpers/used-storage.ts
parentb3e7358daa453481574a796bd8b3c2238701a2bc (diff)
downloadrefined-github-0f0d7435a649466084fab40bb7fe0481b0c73dba.tar.gz
refined-github-0f0d7435a649466084fab40bb7fe0481b0c73dba.tar.zst
refined-github-0f0d7435a649466084fab40bb7fe0481b0c73dba.zip
Meta: Include information about storage in options (#6595)
Diffstat (limited to 'source/helpers/used-storage.ts')
-rw-r--r--source/helpers/used-storage.ts10
1 files changed, 10 insertions, 0 deletions
diff --git a/source/helpers/used-storage.ts b/source/helpers/used-storage.ts
new file mode 100644
index 00000000..8a95bf18
--- /dev/null
+++ b/source/helpers/used-storage.ts
@@ -0,0 +1,10 @@
+/** `getBytesInUse` polyfill */
+export default async function getStorageBytesInUse(area: 'local' | 'sync'): Promise<any> {
+ const storage = browser.storage[area];
+ // From https://bugzilla.mozilla.org/show_bug.cgi?id=1385832#c20
+ return 'getBytesInUse' in storage ? storage.getBytesInUse() : new TextEncoder().encode(
+ Object.entries(await storage.get())
+ .map(([key, value]) => key + JSON.stringify(value))
+ .join(''),
+ ).length;
+}