const btnLoginPage = document.querySelector('.btn-login'); const btnUserProfile = document.querySelector('.btn-userProfile'); const btnLogout = document.querySelector('.btn-logout'); function getCookie(name) { const value = `; ${document.cookie}`; const parts = value.split(`; ${name}=`); if (parts.length === 2) return parts.pop().split(';').shift(); } function renderView() { let token = getCookie('jwt_token'); if(!token) { return; } // axios.defaults.withCredentials = false; axios({ method: 'post', url: 'https://www.choozmo.com:8887/user_profile', headers: { 'accept': 'text/html', 'Authorization': `Bearer ${token}` } }).then(res => { console.log(res.data); const userInfo = res.data; if(userInfo.user_info.left_sec < 20){ Swal.fire({ title: "剩餘秒數不足", text: '您的影片額度即將不足,加值以持續使用', icon: 'warning', showCancelButton: true, cancelButtonText: 'Cancel', confirmButtonColor: '#3085d6', confirmButtonText: '加值' }).then(result => { if (result.isConfirmed) { location.href = "pricing.html"; } }); } // const str = ` //

User Profile

//

${userInfo.user_info.userName}

//

${userInfo.user_info.email}

//
//
//

已使用

//

${userInfo.user_info.total_sec}

//
//
//

未使用

//

${userInfo.user_info.left_sec}

//
//
`; const str = `

User Profile

${userInfo.user_info.userName}

${userInfo.user_info.email}

已使用

${userInfo.user_info.total_sec}

未使用

${userInfo.user_info.left_sec}

`; // 使用者名稱 const userName = `

Hello,${userInfo.user_info.userName}

`; // 已使用 const usedtime=`

${userInfo.user_info.total_sec} 

`; // 未使用 const NotUsedTime=`

${userInfo.user_info.left_sec} 

`; // user資訊 const infContent=`

${userInfo.user_info.userName}

*************** 更改密碼

${userInfo.user_info.email}

`; // 歷史紀錄 // const historicalrecord var historicalrecord='' for (var i = 0; i < userInfo.video_info.length; i++) { historicalrecord+='\ \ '+userInfo.video_info[i].time_stamp+'\ '+userInfo.video_info[i].title+'\ '+userInfo.video_info[i].duration+'\ `\ '; } $('.historical-content').html(historicalrecord); $('.userinf').html(infContent); $('.userName').html(userName); $('.used-time').html(usedtime); $('.not-used-time').html(NotUsedTime); $('.card-profile').html(str); $('.card-profile').html(str); }).catch(err => { console.log(err); }) } renderView(); function checkLogin() { let token = getCookie('jwt_token'); if(token) { btnLoginPage.style.display = 'none'; btnLogout.style.display = 'block'; btnUserProfile.style.display = 'block'; } else { window.location.href = 'login.html'; btnLoginPage.style.display = 'block'; btnLogout.style.display = 'none'; btnUserProfile.style.display = 'none'; } } checkLogin(); $(".historical-record").hide(); $( ".check-history" ).click(function() { $(".historical-record").toggle(); $(".arrowdown").toggleClass("arrowdoup"); }); var loaded_data = '' function openNav() { document.getElementById("mySidenav").style.width = "250px"; document.querySelector('.loader').style.display = "block"; let token = getCookie('jwt_token'); axios({ method: 'post', url: 'https://www.choozmo.com:8887/history_input', headers: { 'accept': 'application/json', 'Authorization': `Bearer ${token}` } }).then(res => { console.log(res.data); loaded_data = res.data; for (var obj of loaded_data) { var historyList = document.querySelector('.historyList'); var list = document.createElement('li'); list.id = obj.id; // div-imgfr var divImgfr = document.createElement('div'); divImgfr.classList.add('item_imgfr'); var img = document.createElement('img'); img.setAttribute('src', obj['image_urls'][0]); divImgfr.appendChild(img); // div-content var contentBox = document.createElement('div'); contentBox.classList.add('content-box'); var boxTitle = document.createElement('p'); boxTitle.classList.add('box-title'); boxTitle.textContent = obj.name; boxTitle.id = obj.id; boxTitle.setAttribute('onclick', `direct(${obj.id})`); var boxLink = document.createElement('span'); boxLink.classList.add('box-link'); boxLink.setAttribute("data-url", obj.link); boxLink.setAttribute('onclick', 'view()'); boxLink.innerHTML = '觀看影片'; contentBox.appendChild(boxTitle); contentBox.appendChild(boxLink); list.classList.add("historyList-item"); list.setAttribute('onclick', `direct(${obj.id})`); list.appendChild(divImgfr); list.appendChild(contentBox); historyList.appendChild(list); } document.querySelector('.loader').style.display = "none"; }).catch(err => { console.log(err); }); } function direct(id) { location.href = `make_video.html?id=${id}`; } function view() { event.stopPropagation(); console.log(event.target); if (event.target.nodeName === 'I') { return; } else { window.open(`http://${event.target.dataset.url}`, '_blank'); } }