function clear_data(){ console.log("clear_data: running"); restaurants = null; latitude = null; longitude = null; } //from-logout document.getElementById("login-link-header").addEventListener("click", async function(){ if(document.getElementById("login-link-header").textContent == "logout"){ console.log("User is logged in"); document.getElementById('logout-modal').style.display='block'; var status = await send_logout_request(); if(status == 200){ console.log("successfully logged out."); document.getElementById("sign-up-link-footer").style.display = "block"; document.getElementById("sign-up-link-sidebar").style.display = "block"; document.getElementById("history-link-footer").style.display = "none"; document.getElementById("history-link-sidebar").style.display = "none"; //Change the login to logout document.getElementById("login-link-footer").textContent = "login"; document.getElementById("login-link-header").textContent = "login"; document.getElementById("login-link-sidebar").textContent = "login"; //Make the account link visible. document.getElementById("account-link-footer").style.display = "none"; document.getElementById("account-link-navbar").style.display = "none"; document.getElementById("account-link-sidebar").style.display = "none"; document.getElementById("favorites-footer").style.display = "none"; document.getElementById("likes-footer").style.display = "none"; document.getElementById("dislikes-footer").style.display = "none"; document.getElementById("favorites-sidebar").style.display = "none"; document.getElementById("likes-sidebar").style.display = "none"; document.getElementById("dislikes-sidebar").style.display = "none"; document.getElementById("sidebar-menu").style.display = "none"; document.getElementById("footer-hl1").style.display = "none"; document.getElementById("footer-hl2").style.display = "none"; document.getElementById("footer-hl3").style.display = "none"; document.getElementById("sidebar-hl1").style.display = "none"; document.getElementById("sidebar-hl2").style.display = "none"; document.getElementById("sidebar-hl3").style.display = "none"; localStorage.clear(); sessionStorage.clear(); clear_data(); console.log("cleared all local and session data."); try{ if(sessionStorage.username){ document.getElementById("favorites-and-likes-input-radio-div").style.display = "block"; document.getElementById("favorites-and-likes-input-radio-sub").style.display = "none"; }else{ document.getElementById("favorites-and-likes-input-radio-div").style.display = "none"; document.getElementById("favorites-and-likes-input-radio-sub").style.display = "block"; } }catch(e){ console.error("Could not change the visibility: " + e); } if( (location == "https://restaurnaut.com/profile") || (location == "https://restaurnaut.com/profile/") || (location == "https://restaurnaut.com/profile/history") || (location == "https://restaurnaut.com/profile/history/") || (location == "https://restaurnaut.com/profile/favorites") || (location == "https://restaurnaut.com/profile/favorites/") || (location == "https://restaurnaut.com/profile/likes") || (location == "https://restaurnaut.com/profile/likes/") || (location == "https://restaurnaut.com/profile/dislikes") || (location == "https://restaurnaut.com/profile/dislikes/") ){ location.reload(); } } } }); document.getElementById("login-link-footer").addEventListener("click", async function(){ if(document.getElementById("login-link-footer").textContent == "logout"){ console.log("User is logged in"); document.getElementById('logout-modal').style.display='block'; var status = await send_logout_request(); if(status == 200){ document.getElementById("sign-up-link-footer").style.display = "block"; document.getElementById("sign-up-link-sidebar").style.display = "block"; document.getElementById("history-link-footer").style.display = "none"; document.getElementById("history-link-sidebar").style.display = "none"; console.log("successfully logged out."); restaurnaut_key = null; //Change the login to logout document.getElementById("login-link-footer").textContent = "login"; document.getElementById("login-link-header").textContent = "login"; document.getElementById("login-link-sidebar").textContent = "login"; //Make the account link visible. document.getElementById("account-link-footer").style.display = "none"; document.getElementById("account-link-navbar").style.display = "none"; document.getElementById("account-link-sidebar").style.display = "none"; document.getElementById("favorites-footer").style.display = "none"; document.getElementById("likes-footer").style.display = "none"; document.getElementById("dislikes-footer").style.display = "none"; document.getElementById("favorites-sidebar").style.display = "none"; document.getElementById("likes-sidebar").style.display = "none"; document.getElementById("dislikes-sidebar").style.display = "none"; document.getElementById("sidebar-menu").style.display = "none"; document.getElementById("footer-hl1").style.display = "none"; document.getElementById("footer-hl2").style.display = "none"; document.getElementById("footer-hl3").style.display = "none"; document.getElementById("sidebar-hl1").style.display = "none"; document.getElementById("sidebar-hl2").style.display = "none"; document.getElementById("sidebar-hl3").style.display = "none"; // document.getElementById("favorites-and-likes-input-radio-div").style.display = "none"; // document.getElementById("favorites-and-likes-input-radio-sub").style.display = "block"; localStorage.clear(); sessionStorage.clear(); clear_data(); console.log("cleared all local and session data."); try{ if(sessionStorage.username){ document.getElementById("favorites-and-likes-input-radio-div").style.display = "block"; document.getElementById("favorites-and-likes-input-radio-sub").style.display = "none"; }else{ document.getElementById("favorites-and-likes-input-radio-div").style.display = "none"; document.getElementById("favorites-and-likes-input-radio-sub").style.display = "block"; } }catch(e){ console.error("Could not change the visibility: " + e); } if( (location == "https://restaurnaut.com/profile") || (location == "https://restaurnaut.com/profile/") || (location == "https://restaurnaut.com/profile/history") || (location == "https://restaurnaut.com/profile/history/") || (location == "https://restaurnaut.com/profile/favorites") || (location == "https://restaurnaut.com/profile/favorites/") || (location == "https://restaurnaut.com/profile/likes") || (location == "https://restaurnaut.com/profile/likes/") || (location == "https://restaurnaut.com/profile/dislikes") || (location == "https://restaurnaut.com/profile/dislikes/") ){ location.reload(); } } } }); document.getElementById("login-link-sidebar").addEventListener("click", async function(){ if(document.getElementById("login-link-sidebar").textContent == "logout"){ console.log("User is logged in"); document.getElementById('logout-modal').style.display='block'; var status = await send_logout_request(); if(status == 200){ document.getElementById("sign-up-link-footer").style.display = "block"; document.getElementById("sign-up-link-sidebar").style.display = "block"; document.getElementById("history-link-footer").style.display = "none"; document.getElementById("history-link-sidebar").style.display = "none"; console.log("successfully logged out."); restaurnaut_key = null; //Change the login to logout document.getElementById("login-link-footer").textContent = "login"; document.getElementById("login-link-header").textContent = "login"; document.getElementById("login-link-sidebar").textContent = "login"; //Make the account link visible. document.getElementById("account-link-footer").style.display = "none"; document.getElementById("account-link-navbar").style.display = "none"; document.getElementById("account-link-sidebar").style.display = "none"; document.getElementById("favorites-footer").style.display = "none"; document.getElementById("likes-footer").style.display = "none"; document.getElementById("dislikes-footer").style.display = "none"; document.getElementById("favorites-sidebar").style.display = "none"; document.getElementById("likes-sidebar").style.display = "none"; document.getElementById("dislikes-sidebar").style.display = "none"; document.getElementById("sidebar-menu").style.display = "none"; document.getElementById("footer-hl1").style.display = "none"; document.getElementById("footer-hl2").style.display = "none"; document.getElementById("footer-hl3").style.display = "none"; document.getElementById("sidebar-hl1").style.display = "none"; document.getElementById("sidebar-hl2").style.display = "none"; document.getElementById("sidebar-hl3").style.display = "none"; // document.getElementById("favorites-and-likes-input-radio-div").style.display = "none"; // document.getElementById("favorites-and-likes-input-radio-sub").style.display = "block"; localStorage.clear(); sessionStorage.clear(); clear_data(); console.log("cleared all local and session data."); try{ if(sessionStorage.username){ document.getElementById("favorites-and-likes-input-radio-div").style.display = "block"; document.getElementById("favorites-and-likes-input-radio-sub").style.display = "none"; }else{ document.getElementById("favorites-and-likes-input-radio-div").style.display = "none"; document.getElementById("favorites-and-likes-input-radio-sub").style.display = "block"; } }catch(e){ console.error("Could not change the visibility: " + e); } if( (location == "https://restaurnaut.com/profile") || (location == "https://restaurnaut.com/profile/") || (location == "https://restaurnaut.com/profile/history") || (location == "https://restaurnaut.com/profile/history/") || (location == "https://restaurnaut.com/profile/favorites") || (location == "https://restaurnaut.com/profile/favorites/") || (location == "https://restaurnaut.com/profile/likes") || (location == "https://restaurnaut.com/profile/likes/") || (location == "https://restaurnaut.com/profile/dislikes") || (location == "https://restaurnaut.com/profile/dislikes/") ){ location.reload(); } } } }); function send_logout_request(){ return new Promise((resolve) => { var xhr = new XMLHttpRequest(); // Paste your LocationIQ token below. xhr.open('POST', "https://restaurnaut.com/api/v1/user/secure/logout/", true); xhr.send(); xhr.onreadystatechange = processRequest; // xhr.addEventListener("readystatechange", processRequest, false); function processRequest(e) { if (xhr.readyState == 4 && xhr.status == 200) { var response = JSON.parse(xhr.responseText); console.log("send_logout_request: " + response.message); sessionStorage.clear(); resolve(xhr.status); //RESOLVE THE PROMISE }else if(xhr.status == 401){ var response = JSON.parse(xhr.responseText); console.log("send_logout_request: " + response.message); }else{ try{ console.log(xhr.status + " message: " + response.message); }catch(exception){ console.log("send_logout_request: status = " + xhr.status + "; readyState = " + xhr.readyState); } } } }); }