async function isFavorite(stop_id) { var res; var index; await fetch("https://livetag.noahyellow.fr/api/isFavorite", { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ stop: stop_id, user: getCookie("access_token") }) }) .then(response => response.json()) .then(data => { if(data['status'] == "success" && data['isFavorite'] == true){ res = true; index = data['index']; }else{ res = false index = null; } } ); return [res, index]; } function timesDisplay(box_id, stop_id) { if (current_stopid == stop_id.toString()) { return; } if(current_box != undefined){ current_box.innerHTML = ''; } var boxid = 'times_' + box_id; var box = document.getElementById(boxid); box.innerHTML = ""; current_boxid = box_id; current_stopid = stop_id; current_box = box; box.innerHTML = "

Patientez s'il vous plaît...

"; apiCall(stop_id, box, line, false); } function getTerminus(result){ var final = []; for(var i = 0; i < result.length; i++){ var direction = result[i].pattern.lastStopName; // On split avec la virgule pour récupérer le nom du terminus var direction = direction.split(','); var direction = direction[1]; // direction sera une clé associée à un tableau final[direction] = []; } return final; } function addFav(stop_id, line, network, name) { fetch("https://livetag.noahyellow.fr/api/addFavorite", { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ line: line, stop: stop_id, name: name, user: getCookie("access_token"), reseau: network }) }) .then(response => response.json()) .then(data => { if(data['status'] == "success"){ alert('Le favori a été ajouté avec succès.') reloadTimes() }else{ alert('Oups, une erreur est survenue : ' + data['status']) } } ); } function delFav(stop_index) { var url = "https://livetag.noahyellow.fr/api/removeFavorite"; fetch(url, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ index: stop_index, user: getCookie("access_token") }) }) .then(response => response.json()) .then(data => { if(data['status'] == "success"){ alert('Favori retiré avec succès.') reloadTimes(); }else{ alert('Oups, une erreur est survenue : ' + data['status']) } } ); } function calcul(tpsattente){ var heureactuelle = new Date(); var heureactuelle = heureactuelle.getHours() * 3600 + heureactuelle.getMinutes() * 60 + heureactuelle.getSeconds(); var tpsattente = tpsattente - heureactuelle; return tpsattente / 60; } function reloadTimes(){ if(current_stopid != ""){ apiCall(current_stopid, current_box, line, inFavorites); } } setInterval(reloadTimes, 10000); const inFavorites = false;