forked from maurermj08/open-in-cyber-chef
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
43 lines (38 loc) · 1.36 KB
/
main.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
function encodeForCyberChef(data) {
return encodeURIComponent(btoa(unescape(encodeURIComponent(data))));
}
// Send message of accurate text selection, to be received by listener. workaround for https://crbug.com/116429
function passAccurateTextSelection() {
(async () => {
const response = await chrome.runtime.sendMessage({text: window.getSelection().toString()});
// do something with response here, not outside the function
//console.log(response);
})();
}
openInCyberChef = function(info, tab) {
// workaround https://crbug.com/116429
chrome.scripting.executeScript({
target: {tabId: tab.id},
func: passAccurateTextSelection,
});
};
chrome.runtime.onInstalled.addListener(() => {
chrome.contextMenus.create({
id: "cyberchef-link",
title: "Open in CyberChef",
contexts: ["selection"]
});
});
chrome.contextMenus.onClicked.addListener(openInCyberChef);
chrome.runtime.onMessage.addListener(
function(request, sender, sendResponse) {
var query = request.text;
chrome.storage.sync.get("my_url", function(items) {
if (!!items.my_url) {
chrome.tabs.create({url: items.my_url + "#input=" + encodeForCyberChef(query)});
} else {
chrome.tabs.create({url: "https://gchq.github.io/CyberChef#input=" + encodeForCyberChef(query)});
}
});
}
);