-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathoptions.js
76 lines (63 loc) · 2.26 KB
/
options.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
66
67
68
69
70
71
72
73
74
75
76
let toggleKey = document.getElementById('toggleKey');
let changeKeyBtn = document.getElementById('changeKeyBtn');
let disableKey = document.getElementById('disableKey');
let disableKeyBtn = document.getElementById('changeDisableKeyBtn');
let refreshShowCircleButton = function () {
chrome.storage.sync.get(['showCircle'], function (option) {
toggleKey.innerText = option.showCircle.key;
});
};
let refreshDisableBubbleButton = function () {
chrome.storage.sync.get(['disableBubble'], function (option) {
disableKey.innerText = option.disableBubble.key;
});
};
refreshShowCircleButton();
refreshDisableBubbleButton();
let waitForKeyInput = 0;
let waitKeyFor = 0;
let newKeyForToggleCircle = 1;
let newKeyForDisableBubble = 2;
function recordNewKey(keyFor) {
if (waitForKeyInput == 0) {
waitForKeyInput = 1;
if (keyFor === newKeyForToggleCircle) {
changeKeyBtn.value = 'Press any key';
changeKeyBtn.disabled = true;
} else if (keyFor === newKeyForDisableBubble) {
disableKeyBtn.value = 'Press any key';
disableKeyBtn.disabled = true;
}
waitKeyFor = keyFor;
}
else {
waitForKeyInput = 0;
waitKeyFor = 0;
}
};
function newKeyPressed(e) {
if (waitForKeyInput == 1) {
let kcode = (e.keyCode ? e.keyCode : e.which);
if (waitKeyFor == newKeyForToggleCircle) {
chrome.storage.sync.set(
{ showCircle: { key: e.key, keyCode: kcode } },
function () {
refreshShowCircleButton();
});
changeKeyBtn.value = 'Change bubble toggle button';
changeKeyBtn.disabled = false;
} else if (waitKeyFor == newKeyForDisableBubble) {
chrome.storage.sync.set(
{ disableBubble: { key: e.key, keyCode: kcode } },
function () {
refreshDisableBubbleButton();
});
disableKeyBtn.value = 'Change disable bubble cursor button';
disableKeyBtn.disabled = false;
}
waitForKeyInput = 0;
}
}
document.getElementById('changeKeyBtn').addEventListener('click', function () { recordNewKey(newKeyForToggleCircle); });
document.getElementById('changeDisableKeyBtn').addEventListener('click', function () { recordNewKey(newKeyForDisableBubble); });
document.getElementById('bd').addEventListener('keypress', function () { newKeyPressed(event); });