-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
20 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,24 @@ | ||
/** | ||
* Sets a value to storage with the given key. | ||
* @param {string} key - The key to set the value. | ||
* @param {*} value - The value to be set. | ||
*/ | ||
const setToStorage = (key, value) => { | ||
chrome.storage.sync.set({ | ||
[key]: value, | ||
}); | ||
// Use chrome.storage.sync to set the key-value pair to storage | ||
chrome.storage.sync.set({ [key]: value }); | ||
}; | ||
|
||
const getFromStorage = (key, defaultValue) => { | ||
return new Promise((resolve) => { | ||
chrome.storage.sync.get([key], (result) => { | ||
resolve(result[key] || defaultValue); | ||
}); | ||
}); | ||
/** | ||
* Retrieves a value from the Chrome storage sync API using the provided key. | ||
* @param {string} key - The key used to retrieve the value from storage. | ||
* @returns {Promise<any>} - A promise that resolves with the retrieved value. | ||
*/ | ||
const getFromStorage = (key) => { | ||
return new Promise((resolve) => { | ||
// Use the chrome.storage.sync.get method to retrieve the value associated with the provided key | ||
chrome.storage.sync.get([key], (result) => { | ||
// Resolve the promise with the retrieved value | ||
resolve(result[key]); | ||
}); | ||
}); | ||
}; |