-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbrain.js
46 lines (39 loc) · 1.1 KB
/
brain.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
34
35
36
37
38
39
40
41
42
43
44
45
46
document.body.style.background = "blue";
console.log('Hi! The demo is working.');
alert('Hi! The demo is working.');
function onError(error) {
console.log(error);
}
// clearStorage();
initializeStorage();
addToStorage('test key', 'some data');
updateStorage('test key', 'updated data');
setTimeout(function() {
getStorage(); // delay to let storage update
}, 100);
function initializeStorage() {
browser.storage.local.get(null).then((results) => {
console.log('initializeStorage', results);
}, onError);
}
function getStorage() {
browser.storage.local.get(null).then((results) => {
console.log('getStorage', results);
}, onError);
}
function addToStorage(key, data) {
browser.storage.local.set({ [key] : data }).then(() => {
console.log('addToStorage', key, data);
}, onError);
}
function updateStorage(key, data) {
browser.storage.local.get(key).then((result) => {
browser.storage.local.remove(key);
addToStorage(key, data);
console.log('updateStorage', key, data);
}, onError);
}
function clearStorage() {
browser.storage.local.clear();
console.log('clearStorage');
}