-
Notifications
You must be signed in to change notification settings - Fork 0
/
storage.js
33 lines (29 loc) · 852 Bytes
/
storage.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
const storage_keys = {
head: 'extensions_dev_hub'
};
function isDataInitialized(data) {
return !!Object.keys(data).length;
}
function getData() {
return new Promise((resolve, reject) => {
chrome.storage.local.get([storage_keys.head], (data) => {
if (chrome.runtime.lastError) {
reject(chrome.runtime.lastError);
} else {
if (isDataInitialized(data)) {
resolve(data[storage_keys.head]);
} else {
initializeDefaultData().then(resolve).catch(reject);
}
}
});
});
}
async function setData(data) {
let root = {};
root[storage_keys.head] = data;
return await chrome.storage.local.set(root);
}
async function clearData() {
return await chrome.storage.local.clear();
}