-
Notifications
You must be signed in to change notification settings - Fork 10
/
index.js
22 lines (21 loc) · 906 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
// when focustube is clicked
browser.browserAction.onClicked.addListener(function () {
browser.storage.local.get("focustube")
.then(function (oldSettings) { // if has existing settings in storage
let newSettings;
if(oldSettings && oldSettings.focustube) {
newSettings = { focus: !(oldSettings.focustube.focus) }; // just toggle the value
} else {
newSettings = { focus: true }; // initial is true
}
save(newSettings);
}, function (error) {
console.debug('error: ' + JSON.stringify(error));
});
});
function save(newSettings) {
console.debug('Saving new settings: ' + JSON.stringify(newSettings));
browser.storage.local.set({ focustube: newSettings }).then(function (value) {
browser.tabs.executeScript(null, { file: "focus.js" }); // refresh tabs
});
}