-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbrowser.js
More file actions
60 lines (50 loc) · 1.52 KB
/
browser.js
File metadata and controls
60 lines (50 loc) · 1.52 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
function lightPowerIcon(enabled) {
console.log(`STUB: lightPowerIcon(enabled)`);
//chrome.action.setBadgeText({text: "+"});
//var color = enabled ? "green" : "red";
//chrome.action.setBadgeBackgroundColor({color: color});
}
/*
chrome.storage.onChanged.addListener(function (changes, namespace) {
for (let [key, { oldValue, newValue }] of Object.entries(changes)) {
console.log(
`Storage key "${key}" in namespace "${namespace}" changed.`,
`Old value was "${JSON.stringify(oldValue)}", new value is "${JSON.stringify(newValue)}".`
);
}
});
*/
chrome = {};
chrome.storage = {};
chrome.storage.local = {};
chrome.storage.local.set = function(key, value) {
console.log(`key=` + JSON.stringify(key));
console.log(`value=` + JSON.stringify(value));
};
chrome.storage.local.get = function(key, value) {
console.log(`key=` + JSON.stringify(key));
console.log(`value=` + JSON.stringify(value));
};
function saveSetting(settings)
{
getSetting("options", function(options) {
if (options == undefined)
{
options = {};
}
for (const [key, value] of Object.entries(settings))
{
options[key] = value;
}
chrome.storage.local.set({"options": options}, function() {
console.log('Value is set to ' + JSON.stringify(options));
});
});
}
function getSetting(key, fn)
{
chrome.storage.local.get("options", (options) => {
console.log('Value currently is ' + JSON.stringify(options));
fn(options[key]);
});
}