forked from pjzzz/iScroll
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackground.js
More file actions
93 lines (80 loc) · 2.09 KB
/
background.js
File metadata and controls
93 lines (80 loc) · 2.09 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
// if (request.type == "snapshot") {
// sendSnapshotToServer(request.payload);
// return true;
// }
routeMessage(request.type);
return true;
});
function routeMessage(messageType) {
switch (messageType) {
// case "openWS":
// openConnection();
// break;
// case "closeWS":
// closeConnection();
// break;
case "zoom-in":
zoomIn();
break;
case "zoom-out":
zoomOut();
break;
// break;
// case "next-Tab":
// nextTab();
// break;
default:
chrome.tabs.getSelected(null, function(tab) {
chrome.tabs.sendMessage(tab.id, { type: messageType, tabID: tab.id });
});
break;
}
}
function zoomIn() {
console.log('zoom in');
chrome.tabs.getSelected(null, function(tab) {
chrome.tabs.getZoom(tab.id, function(zoomFactor) {
chrome.tabs.setZoom(tab.id, zoomFactor + 0.2);
});
});
}
function zoomOut() {
chrome.tabs.getSelected(null, function(tab) {
chrome.tabs.getZoom(tab.id, function(zoomFactor) {
chrome.tabs.setZoom(tab.id, zoomFactor - 0.2);
});
});
}
// var ws = null;
// function closeConnection() {
// if (ws)
// ws.close();
// }
// function openConnection() {
// closeConnection();
// var url = "ws://localhost:9001";
// ws = new WebSocket(url);
// ws.onopen = onOpen;
// ws.onclose = onClose;
// ws.onmessage = onMessage;
// ws.onerror = onError;
// }
// function onOpen() {
// console.log("Websocket connected.");
// }
// function onClose() {
// console.log("Websocket disconnected.");
// ws = null;
// }
function onMessage(event) {
console.log(event);
routeMessage(event.data);
}
// function onError(event) {
// alert("Websocket error.");
// }
// function sendSnapshotToServer(snapshot) {
// if (ws)
// ws.send(snapshot);
// }