-
Notifications
You must be signed in to change notification settings - Fork 0
/
inject.js
35 lines (31 loc) · 934 Bytes
/
inject.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
document.addEventListener(
'keydown',
function handleKeyDown(event) {
var keyCode = event.keyCode;
// Ignore keydown event if typing in an input box
if (
(document.activeElement.nodeName === 'INPUT' && document.activeElement.getAttribute('type') === 'text') ||
document.activeElement.nodeName === 'TEXTAREA' ||
document.activeElement.isContentEditable
) {
return false;
}
var port = chrome.runtime.connect();
//m
if (keyCode === 77) {
port.onMessage.addListener(function(message, sender) {
port.postMessage({ type: 'toggleMute' });
});
}
//shift+alt+p
if (keyCode === 80 && event.altKey && event.shiftKey) {
port.onMessage.addListener(function(message, sender) {
port.postMessage({ type: 'popDown' });
});
}
},
true
);
window.onbeforeunload = function() {
chrome.runtime.sendMessage({ type: 'closeMe' });
};