-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackground.js
46 lines (41 loc) · 958 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
35
36
37
38
39
40
41
42
43
44
45
46
'use strict';
var gPos = null;
chrome.extension.onMessage.addListener(function (msg, sender, sendResponse) {
if (msg.from === 'mouseup') {
gPos = msg.point;
}
});
var getClickHandler = function (info, tab) {
sendRequest({
type: 'context',
point: gPos
});
};
var createSquare = function (info,tab){
sendRequest({
type: 'square',
point: gPos
});
}
function sendRequest(data) {
chrome.tabs.query({
active: true,
currentWindow: true
}, function (tabs) {
chrome.tabs.sendMessage(tabs[0].id, data, function (response) {
//console.log(response.mess);
});
});
}
chrome.contextMenus.create({
'title': 'Make red point',
'type': 'normal',
'contexts': ['all'],
'onclick': getClickHandler
});
chrome.contextMenus.create({
'title': 'Create square',
'type': 'normal',
'contexts': ['all'],
'onclick': createSquare
});