-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpopup.js
47 lines (40 loc) · 1.17 KB
/
popup.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
function onLoad() {
const buttonsContainer = document.querySelector('.readyButtonsContainer');
const accept = document.querySelector('.acceptSpeed')
const speedInput = document.querySelector('.speedInput')
const speedInputValue = document.querySelector('.actualSpeed')
speedInputValue.textContent = speedInput.value;
buttonsContainer.addEventListener('click', onclick)
accept.addEventListener('click', onAccept)
speedInput.addEventListener('keydown', () => {
if (e.keyCode === 13) { //13 = enter
onAccept()
}
})
speedInput.oninput = function () {
speedInputValue.innerHTML = this.value;
}
function onclick(e) {
try {
let send = e.target.closest('button').textContent;
chrome.tabs.query({
currentWindow: true,
active: true
}, function (tabs) {
chrome.tabs.sendMessage(tabs[0].id, send)
})
} catch (error) {}
}
function onAccept() {
let send = speedInput.value;
chrome.tabs.query({
currentWindow: true,
active: true
}, function (tabs) {
chrome.tabs.sendMessage(tabs[0].id, send)
})
}
}
window.addEventListener('DOMContentLoaded', () => {
onLoad();
});