-
Notifications
You must be signed in to change notification settings - Fork 15k
/
background.js
65 lines (55 loc) · 1.49 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/* global chrome */
const handleRequest = (request, sender, sendResponse) => {
const { method, args = [] } = request;
const tabId = sender.tab.id;
switch (method) {
case 'getZoom': {
chrome.tabs.getZoom(tabId).then(sendResponse);
break;
}
case 'setZoom': {
const [zoom] = args;
chrome.tabs.setZoom(tabId, zoom).then(async () => {
const updatedZoom = await chrome.tabs.getZoom(tabId);
sendResponse(updatedZoom);
});
break;
}
case 'getZoomSettings': {
chrome.tabs.getZoomSettings(tabId).then(sendResponse);
break;
}
case 'setZoomSettings': {
const [settings] = args;
chrome.tabs.setZoomSettings(tabId, { mode: settings.mode }).then(async () => {
const zoomSettings = await chrome.tabs.getZoomSettings(tabId);
sendResponse(zoomSettings);
});
break;
}
case 'get': {
chrome.tabs.get(tabId).then(sendResponse);
break;
}
case 'query': {
const [params] = args;
chrome.tabs.query(params).then(sendResponse);
break;
}
case 'reload': {
chrome.tabs.reload(tabId).then(() => {
sendResponse({ status: 'reloaded' });
});
break;
}
case 'update': {
const [params] = args;
chrome.tabs.update(tabId, params).then(sendResponse);
break;
}
}
};
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
handleRequest(request, sender, sendResponse);
return true;
});