-
Notifications
You must be signed in to change notification settings - Fork 0
/
content.js
42 lines (39 loc) · 852 Bytes
/
content.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
const runModule = async (arg) => {
const src = chrome.runtime.getURL("module.js");
const script = await import(src);
script.translate();
};
// load extension shortcut settings
whale.storage.sync.get(
{
Key: "F8",
Short: 1,
Alt: 0,
Shift: 0,
Ctrl: 0,
},
(items) => {
key = items.Key;
short = items.Short;
alt = items.Alt;
shift = items.Shift;
ctrl = items.Ctrl;
}
);
// when contextMenu clicked
chrome.runtime.onMessage.addListener((request, sender, sendResponse) =>
sendResponse(runModule(request.arg))
);
// when shortcut pressed
window.onkeyup = (e) => {
if (
short &&
e.key.toUpperCase() == key.toUpperCase() &&
e.ctrlKey == ctrl &&
e.shiftKey == shift &&
e.altKey == alt
) {
e.preventDefault();
runModule();
}
};