-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheventPage.js
87 lines (73 loc) · 2.37 KB
/
eventPage.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
console.log("eventPage loaded");
// creating screenshot context menu
var contextMenuDII = {
id: "dii",
title: "DII",
contexts: ["all"],
};
var subContextMenuIS = {
id: "imageSearch",
parentId: "dii",
title: "Image Search",
contexts: ["image"],
};
var subContextMenuSS = {
id: "screenshotSearch",
parentId: "dii",
title: "Screenshot Search",
contexts: ["all"],
};
chrome.contextMenus.create(contextMenuDII);
console.log("parent context menu DII created");
chrome.contextMenus.create(subContextMenuIS);
console.log("first child context menu Image Search created");
chrome.contextMenus.create(subContextMenuSS);
console.log("second child context menu Screenshot Search created");
chrome.contextMenus.onClicked.addListener(function (clickData) {
if (clickData.menuItemId == "dii") {
console.log("context menu DII clicked, its working fine!");
}
});
chrome.contextMenus.onClicked.addListener(function (clickData) {
if (clickData.menuItemId == "imageSearch") {
console.log("Sub context menu Image Search is Clicked, its working fine!");
console.log("Image url - ", clickData.srcUrl);
}
});
// addListener listens when user clicks on context menu and check whether id is
// same as our menuItemId
chrome.contextMenus.onClicked.addListener(function (clickData) {
if (clickData.menuItemId == "screenshotSearch") {
console.log("context item clicked");
// we to take screenshot of current and active tab
chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) {
// Capture screenshot of full visible tab
chrome.tabs.captureVisibleTab(null, null, function (dataUrl) {
console.log("Tab screenshot initiated");
// screenshot url
var screenshotUrl = dataUrl;
console.log("screenshot url - ", screenshotUrl);
// send Message to content to content script with screenshotUrl as data
chrome.tabs.sendMessage(
tabs[0].id,
{ action: "take_screenshot", data: screenshotUrl },
function (response) {
console.log("screenshot done!", response);
}
);
});
});
}
});
chrome.extension.onMessage.addListener(function (
request,
sender,
sendResponse
) {
if (request.name == "screenshot") {
chrome.tabs.captureVisibleTab(null, null, function (dataUrl) {
sendResponse({ screenshotUrl: dataUrl });
});
}
return true;
});