2019-03-24 18:04:44 +03:00
|
|
|
apikeycorrect = false;
|
|
|
|
|
|
|
|
function insertAPIKeyFromCookie() {
|
|
|
|
cookies = decodeURIComponent(document.cookie).split(';');
|
|
|
|
for(var i = 0; i <cookies.length; i++) {
|
|
|
|
cookies[i] = cookies[i].trim()
|
|
|
|
if (cookies[i].startsWith("apikey=")) {
|
|
|
|
document.getElementById("apikey").value = cookies[i].replace("apikey=","")
|
|
|
|
checkAPIkey()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function saveAPIkey() {
|
|
|
|
key = document.getElementById("apikey").value
|
|
|
|
document.cookie = "apikey=" + encodeURIComponent(key)
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function checkAPIkey() {
|
|
|
|
saveAPIkey()
|
2019-05-12 12:58:51 +03:00
|
|
|
url = "/api/test?key=" + document.getElementById("apikey").value
|
2019-03-24 18:04:44 +03:00
|
|
|
var xhttp = new XMLHttpRequest();
|
|
|
|
xhttp.onreadystatechange = function() {
|
|
|
|
if (this.readyState == 4 && (this.status == 204 || this.status == 205)) {
|
|
|
|
document.getElementById("apikey").style.backgroundColor = "lawngreen"
|
|
|
|
apikeycorrect = true
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
document.getElementById("apikey").style.backgroundColor = "red"
|
|
|
|
apikeycorrect = false
|
|
|
|
}
|
|
|
|
};
|
|
|
|
try {
|
|
|
|
xhttp.open("GET",url,true);
|
|
|
|
xhttp.send();
|
|
|
|
}
|
|
|
|
catch (e) {
|
|
|
|
document.getElementById("apikey").style.backgroundColor = "red"
|
|
|
|
apikeycorrect = false
|
|
|
|
}
|
|
|
|
}
|
2019-05-14 13:50:31 +03:00
|
|
|
|
|
|
|
function APIkey() {
|
|
|
|
return document.getElementById("apikey").value;
|
|
|
|
}
|