-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathoptions.js
34 lines (30 loc) · 1.25 KB
/
options.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
function saveOptions(e) {
e.preventDefault();
var newZoomFactor = parseFloat(document.querySelector("#zoomFactor").value);
var newZoomThreshold = parseInt(document.querySelector("#zoomThreshold").value);
browser.storage.local.set({
zoomFactor: newZoomFactor,
zoomThreshold: newZoomThreshold
});
// update "constants" in background.js, bypassing local storage
var gettingBackground = browser.runtime.getBackgroundPage();
gettingBackground.then(function (page) {
page.setZoomFactor(newZoomFactor);
page.setZoomThreshold(newZoomThreshold);
page.resized();
});
}
function restoreOptions() {
function setFieldValues(result) {
// defaults from globals.js
document.querySelector("#zoomFactor").value = result.zoomFactor || DEFAULT_ZOOM_FACTOR;
document.querySelector("#zoomThreshold").value = result.zoomThreshold || DEFAULT_ZOOM_THRESHOLD;
}
function onError(error) {
console.log(`Error: ${error}`);
}
var getting = browser.storage.local.get(["zoomFactor", "zoomThreshold"]);
getting.then(setFieldValues, onError);
}
document.addEventListener("DOMContentLoaded", restoreOptions);
document.querySelector("form").addEventListener("submit", saveOptions);