2023-09-02 07:10:07 +02:00
|
|
|
var root = ""; // À modifier sur le serveur
|
2023-09-02 07:07:45 +02:00
|
|
|
|
2023-06-28 20:38:52 +02:00
|
|
|
// Gestion de la langue :
|
|
|
|
var url_string = window.location.href;
|
|
|
|
var url = new URL(url_string);
|
|
|
|
var lg = url.searchParams.get("lg");
|
|
|
|
|
|
|
|
if (lg == null) {
|
|
|
|
lg = "en"; // Langue par défaut
|
|
|
|
// Recherche dans les cookies :
|
|
|
|
var cookies = decodeURIComponent(document.cookie);
|
|
|
|
if (cookies != "") {
|
|
|
|
// On part du principe qu'on n'a qu'un cookie, et que c'est celui de la langue
|
|
|
|
// 9 caractères pour "language", et 2 pour la langue
|
|
|
|
lg = cookies.substring(9, 11);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-28 21:20:16 +02:00
|
|
|
if (lg == "en") {
|
2023-07-27 12:47:06 +02:00
|
|
|
var qr_error = "Sorry, wrong QR code, please try another one !\n\nHint : ";
|
2023-06-28 21:20:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (lg == "fr") {
|
2023-07-27 12:47:06 +02:00
|
|
|
var qr_error = "Désolé, ce n'est pas le bon QR code, veuillez en essayer un autre !\n\nIndice : ";
|
2023-06-28 21:20:16 +02:00
|
|
|
}
|
|
|
|
|
2023-06-28 20:38:52 +02:00
|
|
|
export async function puzzleSolve(code, team_id, art_id) {
|
|
|
|
try {
|
2023-09-02 07:10:07 +02:00
|
|
|
const response = await fetch(url.origin + "/" + root + "answer.php?lg=" + lg + "&team=" + team_id + "&code=" + code + "&id=" + art_id);
|
2023-07-27 12:47:06 +02:00
|
|
|
const data = await response.json();
|
|
|
|
if (data["valid_qr"]) {
|
|
|
|
location.reload();
|
2023-06-28 21:20:16 +02:00
|
|
|
}
|
|
|
|
else {
|
2023-07-27 12:47:06 +02:00
|
|
|
alert(qr_error + data["hint"]);
|
2023-06-28 21:20:16 +02:00
|
|
|
}
|
2023-06-28 20:38:52 +02:00
|
|
|
}
|
|
|
|
catch (error) {
|
|
|
|
console.log(error);
|
|
|
|
}
|
|
|
|
}
|