forked from jamielinux/default-zoom
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackground.js
34 lines (30 loc) · 993 Bytes
/
background.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
let defaultZoom = 1;
let gettingDefaultZoom = browser.storage.local.get("defaultZoom");
gettingDefaultZoom.then((storage) => {
if (storage.defaultZoom) {
let parsedZoom = parseFloat(storage.defaultZoom);
if (30 <= parsedZoom && parsedZoom <= 300) {
defaultZoom = parsedZoom / 100;
} else {
// If the setting is somehow outside the allowed range of
// values, set it back to the default.
browser.storage.local.set({
defaultZoom: "100"
});
}
}
});
function setZoom(tabId, changeInfo, tab) {
if ("status" in changeInfo && !tab.isInReaderMode) {
let gettingZoom = browser.tabs.getZoom(tabId);
gettingZoom.then((currentZoom) => {
if (defaultZoom != 1 && currentZoom == 1) {
browser.tabs.setZoom(tabId, defaultZoom);
}
});
}
}
browser.storage.onChanged.addListener((newSettings) => {
defaultZoom = parseFloat(newSettings.defaultZoom.newValue) / 100;
});
browser.tabs.onUpdated.addListener(setZoom);