-
Notifications
You must be signed in to change notification settings - Fork 0
/
popup.js
40 lines (33 loc) · 1.05 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
document.addEventListener("DOMContentLoaded", setup)
let connected
let mSwitch = document.getElementById("onOffButton")
let mStatus = document.getElementById("connectionStatus")
let mValue = document.getElementById("pingValue")
mSwitch.addEventListener("click", function() {
if (connected) {
chrome.runtime.sendMessage("disconnect");
} else {
chrome.runtime.sendMessage("connect");
}
})
function setup() {
chrome.runtime.sendMessage("setupPopup");
}
chrome.runtime.onMessage.addListener(function(message, sender, sendResponse) {
let mes = message.toString().split(",")
console.log(mes[0])
if (mes[0] == "pingValue") {
mValue.innerText = `ping: ${mes[1]}`;
} else if (mes[0] == "connectionChange") {
console.log(mes[1])
if (mes[1] == "connected") {
mSwitch.src = "on.png"
connected = true
} else {
mSwitch.src = "off.png"
mValue.innerText = ""
connected = false
}
mStatus.innerText = `Status: ${mes[1]}`;
}
});