2018-12-14 18:38:08 +03:00
|
|
|
|
|
|
|
document.addEventListener("DOMContentLoaded",function() {
|
|
|
|
document.getElementById("serverurl").addEventListener("input",updateServer);
|
|
|
|
document.getElementById("apikey").addEventListener("input",updateAPIKey);
|
|
|
|
|
2018-12-14 21:52:31 +03:00
|
|
|
document.getElementById("serverurl").addEventListener("change",checkServer);
|
|
|
|
document.getElementById("apikey").addEventListener("change",checkServer);
|
|
|
|
|
2018-12-14 18:38:08 +03:00
|
|
|
|
|
|
|
chrome.storage.local.get({"serverurl":"http://localhost:42010"},function(result) {
|
|
|
|
document.getElementById("serverurl").value = result["serverurl"]
|
2018-12-14 21:52:31 +03:00
|
|
|
checkServer()
|
2018-12-14 18:38:08 +03:00
|
|
|
});
|
|
|
|
chrome.storage.local.get({"apikey":"BlackPinkInYourArea"},function(result) {
|
|
|
|
document.getElementById("apikey").value = result["apikey"]
|
2018-12-14 21:52:31 +03:00
|
|
|
checkServer()
|
2018-12-14 18:38:08 +03:00
|
|
|
});
|
|
|
|
|
2018-12-14 21:52:31 +03:00
|
|
|
|
|
|
|
|
2018-12-14 18:38:08 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function updateServer() {
|
|
|
|
|
|
|
|
text = document.getElementById("serverurl").value
|
|
|
|
|
2018-12-14 21:52:31 +03:00
|
|
|
|
|
|
|
chrome.storage.local.set({"serverurl":text})
|
2018-12-14 18:38:08 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function updateAPIKey() {
|
|
|
|
text = document.getElementById("apikey").value
|
|
|
|
chrome.storage.local.set({"apikey":text})
|
|
|
|
}
|
2018-12-14 21:52:31 +03:00
|
|
|
|
|
|
|
function checkServer() {
|
|
|
|
url = document.getElementById("serverurl").value + "/db/test?key=" + document.getElementById("apikey").value
|
|
|
|
|
|
|
|
var xhttp = new XMLHttpRequest();
|
|
|
|
xhttp.onreadystatechange = createCheckmarks;
|
|
|
|
try {
|
|
|
|
xhttp.open("GET",url,true);
|
|
|
|
xhttp.send();
|
|
|
|
}
|
|
|
|
catch (e) {
|
|
|
|
//document.getElementById("checkmark_url").innerHTML = "❌"
|
|
|
|
//document.getElementById("checkmark_key").innerHTML = "❌"
|
|
|
|
document.getElementById("serverurl").style.backgroundColor = "red"
|
|
|
|
document.getElementById("apikey").style.backgroundColor = "red"
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function createCheckmarks() {
|
|
|
|
if (this.readyState == 4) {
|
2018-12-21 18:32:21 +03:00
|
|
|
if ((this.status == 204) || (this.status == 205)) {
|
2018-12-14 21:52:31 +03:00
|
|
|
//document.getElementById("checkmark_url").innerHTML = "✔️"
|
|
|
|
//document.getElementById("checkmark_key").innerHTML = "✔️"
|
|
|
|
document.getElementById("serverurl").style.backgroundColor = "lawngreen"
|
|
|
|
document.getElementById("apikey").style.backgroundColor = "lawngreen"
|
|
|
|
}
|
|
|
|
else if (this.status == 403) {
|
|
|
|
//document.getElementById("checkmark_url").innerHTML = "✔️"
|
|
|
|
//document.getElementById("checkmark_key").innerHTML = "❌"
|
|
|
|
document.getElementById("serverurl").style.backgroundColor = "lawngreen"
|
|
|
|
document.getElementById("apikey").style.backgroundColor = "red"
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
//document.getElementById("checkmark_url").innerHTML = "❌"
|
|
|
|
//document.getElementById("checkmark_key").innerHTML = "❌"
|
|
|
|
document.getElementById("serverurl").style.backgroundColor = "red"
|
|
|
|
document.getElementById("apikey").style.backgroundColor = "red"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|