This repository has been archived by the owner on Aug 11, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
script.js
64 lines (59 loc) · 1.94 KB
/
script.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
chrome.runtime.onMessage.addListener(function(message, sender, sendResponse) {
if (message.type == "launchPopup") {
launchPopup();
}
});
function launchPopup(callback) {
chrome.windows.getCurrent(function (currentWindow) {
var width = screen.width - 350;
var height = screen.height / 2 - 440 / 2;
chrome.windows.create({
url: chrome.extension.getURL('popup/popup.html'),
type: 'popup',
top: height,
left: width,
width: 310,
height: 440
}, callback);
});
}
function menuItemClicked(info, tab) {
launchPopup(function (newWindow) {
// called once newWindow is created
setTimeout(function () {
chrome.tabs.sendMessage(newWindow.tabs[0].id, {
type: "selectionText",
text: info.selectionText || info.linkUrl
});
}, 200);
});
}
// Create the context menu item
chrome.contextMenus.create({
title: "Encrypt/Decrypt with Cryptr",
contexts: ["selection", "link", "editable"],
onclick: menuItemClicked
});
// Launch popup when browser action is clicked
chrome.browserAction.onClicked.addListener(function () {
launchPopup();
});
// Close the popup window if another Chrome window gains focus
// chrome.windows.onFocusChanged.addListener(function (newWindowId) {
// chrome.windows.getAll({
// populate: true
// }, function (windows) {
// for (var i = 0; i < windows.length; i++) {
// // If the Cryptr popup is not focused
// if (!windows[i].focused && windows[i].type == "popup" && windows[i].tabs[0].url == chrome.extension.getURL('popup/popup.html')) {
// for (var j = 0; j < windows.length; j++) {
// // If another normal window is focused
// if (windows[j].focused && windows[j].type == "normal") {
// // close the Cryptr window
// chrome.windows.remove(windows[i].id);
// }
// }
// }
// }
// });
// });