mirror of
https://github.com/krateng/maloja.git
synced 2023-08-10 21:12:55 +03:00
Modularized Javascript
This commit is contained in:
44
website/javascript/cookies.js
Normal file
44
website/javascript/cookies.js
Normal file
@@ -0,0 +1,44 @@
|
||||
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()
|
||||
url = "/db/test?key=" + document.getElementById("apikey").value
|
||||
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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user