-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathshortcut.js
More file actions
41 lines (33 loc) · 1.04 KB
/
shortcut.js
File metadata and controls
41 lines (33 loc) · 1.04 KB
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
/*
Read license.txt for licensing information.
*/
var shortcutKey = {
init: function() {
if (document.body.hasAttribute('screen_capture_injected')) {
return;
}
document.body.setAttribute('screen_capture_injected', true);
document.body.addEventListener('keydown', shortcutKey.handleShortcut,
false);
},
isThisPlatform: function(operationSystem) {
return navigator.userAgent.toLowerCase().indexOf(operationSystem) > -1;
},
handleShortcut: function (event) {
var isMac = shortcutKey.isThisPlatform('mac');
var keyCode = event.keyCode;
// Send compose key like Ctrl + Alt + alphabetical-key to background.
if ((event.ctrlKey && event.altKey && !isMac ||
event.metaKey && event.altKey && isMac) &&
keyCode > 64 && keyCode < 91) {
shortcutKey.sendMessage({
msg: 'capture_hot_key',
keyCode: keyCode
});
}
},
sendMessage: function(message) {
chrome.runtime.sendMessage(message);
}
};
shortcutKey.init();