let userInfo = window.localStorage.getItem('userInfo'); userInfo = JSON.parse(userInfo); if (userInfo) { let parentEle = document.getElementById('userLogo'); let newChild = document.createElement('img'); document.getElementById('isLogin').style.display = 'none'; document.getElementById('isLogin1').style.display = 'none'; newChild.src = userInfo.avatar; parentEle.appendChild(newChild); let arr = userInfo.nickname; if(arr.length <= 8){ document.getElementById('userName').innerText = arr; }else{ document.getElementById('userName').innerText = arr.substring(0, 8) + "..."; } }else{ document.getElementById('isshouother').style.display = 'none'; } let nowPath = window.location.pathname; console.log(nowPath,'当前路径'); if(!userInfo && !nowPath.includes('login.html') && !nowPath.includes('signup.html')){ let language = window.localStorage.getItem("languageNow"); let message = language == 'zh' ? '請先登入或註冊' : 'Please log in or register first'; const html ="
" document.body.innerHTML += html; const item = document.getElementById('customizeBox'); item.classList.add('show') setTimeout(()=>{ window.location.href = "login.html"; item.classList.remove('show') },2000) } baseUrl = "https://demo.samsaradao.com/" if(window.location.host === 'www.samsaradao.com'){ baseUrl = "https://www.samsaradao.com/" } function publikRequesFunction(api,type,params){ return new Promise((resolve, reject) => { $.ajax({ url:baseUrl + api, type: type, dataType: "json", headers:{ token: JSON.parse(window.localStorage.getItem("userInfo")).token, }, data: params, success(res) { resolve(res) if(res.code === 401){ window.localStorage.clear(); window.location.href = 'login.html' }else{ resolve(res) } }, error(rej){ console.log(rej,'错误请求'); if(rej.status === 401){ window.localStorage.clear(); window.location.href = 'login.html' }else{ reject("failed") } } }); }) } function signOutPage(){ $.ajax({ url:baseUrl+"api/user/logout", type: "post", dataType: "json", data:{ token:JSON.parse(window.localStorage.getItem("userInfo")).token, }, success(res) { if(res.code === 1){ console.log(res,'aaaasss'); window.localStorage.removeItem("userInfo"); setTimeout(()=>{ window.location.href = "index.html"; },1000) } }, error: function(rej){ alert("failed") } }); } customClick(false) document.addEventListener('DOMContentLoaded', () => { let tradingcenter = document.getElementById('isOpenTrading'); if (tradingcenter) { tradingcenter.addEventListener('click', ()=>{ customClick(true) }); } let links = document.querySelectorAll('#isshouother a'); links.forEach((link , index) => { if(index > 2 && index < (links.length /2 - 1)){ link.addEventListener('click', function(event) { event.preventDefault(); customClick(true) }); } }); }); function customClick(isShow){ const item = document.getElementById('customizeBox') let language = window.localStorage.getItem("languageNow"); let message = language == 'zh' ? '功能開放中' : 'Function open'; if(!isShow){ const html =" " document.body.innerHTML += html }else{ item.classList.add('show') } setTimeout(()=>{ const item = document.getElementById('customizeBox') item.classList.remove('show') },3000) }