-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.js
65 lines (56 loc) · 1.9 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/*globals chrome, Status, View*/
"use strict";
/****************************************************/
/*Main Events for running actions*/
/****************************************************/
chrome.storage.local.get(null, function(o) {
Status.options = o.options;
Status.disurls = o.disurls;
window.onkeydown = keydown;
window.onkeyup = keyup;
});
/*Save options to Status when changed settings in popup*/
chrome.storage.onChanged.addListener(function(changes) {
for (var key in changes) {
var storageChange = changes[key];
Status[key] = storageChange.newValue;
}
});
/*On keypress t key create ready popup and translate text*/
var keydown = function(e) {
/*Run only if non-blacklisted urls*/
if(Status.disurls.indexOf(location.host) === -1) {
/*instance of View*/
var view = new View();
/*Get holding key string from event*/
var getholdkey = function(ev) {
var holding;
if (ev.altKey) {
holding = 'Alt';
} else if (ev.ctrlKey) {
holding = 'Ctrl';
} else if (ev.shiftKey) {
holding = 'Shift';
} else {
holding = '----';
}
return holding;
};
/*run translate || audio actions*/
if ((e.keyCode === Status.options['translate-key'][1]) && (getholdkey(e) === Status.options['translate-key'][2])) {
keyup(); //run keyp fn because eliminate freeze and resize status switching when key is ex. ctrl + V or shift + V
view.popupcreate();
} else if ((e.keyCode === Status.options['tts-key'][1]) && (getholdkey(e) === Status.options['tts-key'][2])) {
keyup();
view.voice();
} else if (e.keyCode === Status.options['freeze-hold-key'][1]) { /*<CTRL>*/
Status.freeze = true;
} else if (e.keyCode === Status.options['resize-hold-key'][1]) { /*<SHIFT>*/
Status.resize = true;
}
}
};
var keyup = function(e) {
Status.resize = false;
Status.freeze = false;
};