-
Notifications
You must be signed in to change notification settings - Fork 7
/
background.js
38 lines (33 loc) · 1.04 KB
/
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
35
36
37
38
let defaultZoom = 1;
const gettingDefaultZoom = browser.storage.local.get("defaultZoom");
gettingDefaultZoom.then((storage) => {
if (storage.defaultZoom) {
const parsedZoom = parseFloat(storage.defaultZoom);
if (parsedZoom >= 30 && 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) {
if (changeInfo.status) {
const 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.onCreated.addListener((tab) => {
browser.tabs.setZoom(tab.id, defaultZoom);
});
browser.tabs.onUpdated.addListener(setZoom);