script_profile.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457
  1. const btnLoginPage = document.querySelector('.btn-login');
  2. const btnUserProfile = document.querySelector('.btn-userProfile');
  3. const btnLogout = document.querySelector('.btn-logout');
  4. let lan = localStorage.getItem('lan');
  5. function getCookie(name) {
  6. const value = `; ${document.cookie}`;
  7. const parts = value.split(`; ${name}=`);
  8. if (parts.length === 2) return parts.pop().split(';').shift();
  9. }
  10. let userBasics = JSON.parse(localStorage.getItem('user_profile')) || [];
  11. function checkLocal() {
  12. if(userBasics.length == 0){ return };
  13. //userBasics = JSON.parse(userBasics);
  14. console.log(userBasics);
  15. //$('.userName').html(`<h2 class="user-name text-white mt-4 fw-bold">Hi ${userBasics.user_info.userName}</h2>`);
  16. }
  17. $('.dropdown-toggle').click(() => {
  18. lan = localStorage.getItem('lan');
  19. checkLan();
  20. });
  21. //checkLocal();
  22. function checkLan() {
  23. if(lan == 'en') {
  24. $('.btn-makev').css('display', 'none');
  25. $('.btn-makelong').css('display', 'none');
  26. } else {
  27. $('.btn-makev').css('display', 'block');
  28. $('.btn-makelong').css('display', 'block');
  29. }
  30. }
  31. checkLan();
  32. function renderView() {
  33. let token = getCookie('jwt_token');
  34. if(!token) {
  35. window.location.replace("login.html");
  36. }
  37. axios({
  38. method: 'post',
  39. url: 'https://www.choozmo.com:8887/user_profile',
  40. headers: {
  41. 'accept': 'text/html',
  42. 'Authorization': `Bearer ${token}`
  43. }
  44. }).then(res => {
  45. console.log(res.data);
  46. let userInfo = res.data;
  47. if(!userInfo.user_info) {
  48. window.location.replace("login.html");
  49. }
  50. localStorage.setItem('user_profile', JSON.stringify(res.data));
  51. if(userInfo.user_info.left_sec < 20){
  52. let title = "剩餘秒數不足";
  53. let text = '您的影片額度即將不足,加值以持續使用';
  54. let confirmButtonText = '加值';
  55. if (lan == 'en') {
  56. title = "Insufficient seconds left!";
  57. text = 'Your seconds left is less than 20 seconds, refill to continue making videos.';
  58. confirmButtonText = 'Refill';
  59. }
  60. Swal.fire({
  61. title,
  62. text,
  63. icon: 'warning',
  64. showCancelButton: true,
  65. cancelButtonText: 'Cancel',
  66. confirmButtonColor: '#3085d6',
  67. confirmButtonText
  68. }).then(result => {
  69. if (result.isConfirmed) {
  70. location.href = "pricing.html";
  71. }
  72. });
  73. }
  74. const str = `<img src="static/img/undraw_male_avatar_323b.svg" alt="">
  75. <p class="card-profile-txt">User Profile</p>
  76. <p class="card-profile-cnt">${userInfo.user_info.userName}</p>
  77. <p class="card-profile-cnt">${userInfo.user_info.email}</p>
  78. <div class="d-flex justify-content-around">
  79. <div>
  80. <p set-lan="html:used">已使用</p>
  81. <p><strong>${userInfo.user_info.total_sec}</strong><span set-lan="html:sec">秒</span></p>
  82. </div>
  83. <div>
  84. <p set-lan="html:left">未使用</p>
  85. <p><strong>${userInfo.user_info.left_sec}</strong><span set-lan="html:sec">秒</span></p>
  86. </div>
  87. </div>`;
  88. let totalSec = (userInfo.user_info.total_sec == "None") ? 0 : userInfo.user_info.total_sec;
  89. let leftSec = (userInfo.user_info.left_sec == null)? 0 : userInfo.user_info.left_sec;
  90. // 使用者名稱
  91. let userName = `<h2 class="user-name text-white mt-lg-3 mt-xl-1 fw-bold">Hi ${userInfo.user_info.userName}</h2>`;
  92. // 已使用
  93. let usedtime=`<h1 class="text-center">${totalSec}&ensp;<span style="font-size:15px;" set-lan="html:sec">秒</span></h1>`;
  94. if(lang == 'en') {
  95. usedtime=`<h1 class="text-center">${totalSec}&ensp;<span style="font-size:15px;" set-lan="html:sec">Sec</span></h1>`;
  96. }
  97. // 未使用
  98. let NotUsedTime=`<h1 class="text-center">${leftSec}&ensp;<span style="font-size:15px;" set-lan="html:sec">秒</span></h1>`;
  99. if(lang == 'en') {
  100. NotUsedTime=`<h1 class="text-center">${leftSec}&ensp;<span style="font-size:15px;" set-lan="html:sec">Sec</span></h1>`;
  101. }
  102. // user資訊
  103. let infContent=`
  104. <div class="inf-content">
  105. <p>${userInfo.user_info.userName}</p>
  106. <p>************&nbsp;<a href="./reset_pwd_email.html" set-lan="html:resetPsd">更改密碼</a></p>
  107. <p>${userInfo.user_info.email}</p>
  108. </div>`;
  109. if(lang == 'en') {
  110. infContent=`
  111. <div class="inf-content">
  112. <p>${userInfo.user_info.userName}</p>
  113. <p>***************&nbsp;<a href="./reset_pwd_email.html" set-lan="html:resetPsd">Reset Password</a></p>
  114. <p>${userInfo.user_info.email}</p>
  115. </div>`;
  116. }
  117. // 歷史紀錄
  118. // const historicalrecord
  119. var historicalrecord='';
  120. for (var i = 0; i < userInfo.video_info.length; i++) {
  121. let formatted = userInfo.video_info[i].time_stamp;
  122. if (lan == 'zh') {
  123. const timeStamp = userInfo.video_info[i].time_stamp;
  124. const year = timeStamp.split(',')[0].split('/')[2];
  125. const arr = timeStamp.split(',')[0].split('/');
  126. arr.pop();
  127. arr.unshift(year);
  128. const fomatDate = [arr.join('/')];
  129. formatted = fomatDate.concat(timeStamp.split(',')[1]).join('');
  130. }
  131. historicalrecord+='\
  132. <tr>\
  133. <td class="px-0">'+formatted+'</td>\
  134. <td class="px-0">'+userInfo.video_info[i].title+'</td>\
  135. <td class="px-0 w-25">'+userInfo.video_info[i].duration+'</td>\
  136. </tr>`\
  137. ';
  138. }
  139. $('.historical-content').html(historicalrecord);
  140. $('.userinf').html(infContent);
  141. $('.userName').html(userName);
  142. $('.used-time').html(usedtime);
  143. $('.not-used-time').html(NotUsedTime);
  144. $('.card-profile').html(str);
  145. $('.card-profile').html(str);
  146. }).catch(err => {
  147. console.log(err);
  148. window.location.replace("login.html");
  149. })
  150. }
  151. renderView();
  152. function getDraft() {
  153. JsLoadingOverlay.show({
  154. "overlayBackgroundColor": "#FFFFFF",
  155. "overlayOpacity": "1",
  156. "spinnerIcon": "ball-circus",
  157. "spinnerColor": "#B9DDF3",
  158. "spinnerSize": "1x",
  159. "overlayIDName": "overlay",
  160. "spinnerIDName": "spinner",
  161. "offsetX": 0,
  162. "offsetY": 0,
  163. "containerID": "draft-table",
  164. "lockScroll": false,
  165. "overlayZIndex": 9998,
  166. "spinnerZIndex": 9999
  167. });
  168. let token = getCookie('jwt_token');
  169. axios({
  170. method: 'post',
  171. url: 'https://www.choozmo.com:8887/draft_list',
  172. headers: {
  173. 'accept': 'application/json',
  174. 'Authorization': `Bearer ${token}`
  175. }
  176. }).then(res => {
  177. console.log(res.data);
  178. let result = [...res.data];
  179. let str = '';
  180. let draftStr = '';
  181. if(result.length > 0){
  182. for(let i = 0;i < result.length; i++) {
  183. draftStr += `<tr>
  184. <td>${result[i].title}</td>
  185. <td>
  186. <span class="me-3 draft-content-icon" id="${result[i].id}" onclick="gotoDraft(${result[i].id})">
  187. <i class="fas fa-edit"></i>
  188. </span>
  189. <span class="ms-3 draft-content-icon draft-content-delete" id="${result[i].id}" onclick="deleteDraft(${result[i].id})">
  190. <i class="fas fa-trash-alt"></i>
  191. </span>
  192. </td>
  193. </tr>`
  194. }
  195. let titleTxt = '標題';
  196. let editTxt = '編輯';
  197. let nodraftTxt = '目前沒有草稿喔';
  198. if(lan == 'en') {
  199. titleTxt = 'Video Title';
  200. editTxt = 'Edit';
  201. nodraftTxt = 'no_draft';
  202. }
  203. str = `<table class="table text-center">
  204. <thead>
  205. <tr>
  206. <th scope="col" set-lan="html:video_title">${titleTxt}</th>
  207. <th class="px-0" scope="col" set-lan="html:draft_edit">${editTxt}</th>
  208. </tr>
  209. </thead>
  210. <tbody class="draft-content">${draftStr}</tbody>
  211. </table>`
  212. $('.draft-table .card').html(str);
  213. JsLoadingOverlay.hide();
  214. } else {
  215. str = `<div>
  216. <h5 set-lan="html:no_draft">${nodraftTxt}</h5>
  217. <img src="static/img/undraw_void_3ggu.svg" width="80">
  218. </div>`;
  219. $('.draft-table .card').html(str);
  220. JsLoadingOverlay.hide();
  221. }
  222. }).catch(err => {
  223. console.log(err);
  224. });
  225. }
  226. getDraft();
  227. function checkLogin() {
  228. let token = getCookie('jwt_token');
  229. if(token) {
  230. btnLoginPage.style.display = 'none';
  231. btnLogout.style.display = 'block';
  232. btnUserProfile.style.display = 'block';
  233. } else {
  234. window.location.href = 'login.html';
  235. btnLoginPage.style.display = 'block';
  236. btnLogout.style.display = 'none';
  237. btnUserProfile.style.display = 'none';
  238. }
  239. }
  240. checkLogin();
  241. $(".historical-record").hide();
  242. $( ".check-history" ).click(function() {
  243. $(".historical-record").slideToggle(150);
  244. $(".arrowdown").toggleClass("arrowdoup");
  245. });
  246. $('.draft-table').hide();
  247. $('.draft .arrowdown').click(function() {
  248. $(".draft-table").slideToggle(150);
  249. $(".draft .arrowdown").toggleClass("arrowdoup");
  250. });
  251. var loaded_data = ''
  252. function openNav() {
  253. document.getElementById("mySidenav").style.width = "250px";
  254. document.querySelector('.loader').style.display = "block";
  255. let token = getCookie('jwt_token');
  256. axios({
  257. method: 'post',
  258. url: 'https://www.choozmo.com:8887/history_input',
  259. headers: {
  260. 'accept': 'application/json',
  261. 'Authorization': `Bearer ${token}`
  262. }
  263. }).then(res => {
  264. console.log(res.data);
  265. loaded_data = res.data;
  266. var historyList = document.querySelector('.historyList');
  267. historyList.innerHTML = '';
  268. for (var obj of loaded_data) {
  269. var list = document.createElement('li');
  270. list.id = obj.id;
  271. // div-imgfr
  272. var divImgfr = document.createElement('div');
  273. divImgfr.classList.add('item_imgfr');
  274. var img = document.createElement('img');
  275. img.setAttribute('src', obj['image_urls'][0]);
  276. divImgfr.appendChild(img);
  277. // div-content
  278. var contentBox = document.createElement('div');
  279. contentBox.classList.add('content-box');
  280. var boxTitle = document.createElement('p');
  281. boxTitle.classList.add('box-title');
  282. boxTitle.textContent = obj.name;
  283. boxTitle.id = obj.id;
  284. boxTitle.setAttribute('onclick', `direct(${obj.id})`);
  285. var boxLink = document.createElement('span');
  286. boxLink.classList.add('box-link');
  287. boxLink.setAttribute("data-url", obj.link);
  288. boxLink.setAttribute('onclick', 'view()');
  289. boxLink.innerHTML = '<i class="fas fa-play-circle me-1"></i>觀看影片';
  290. contentBox.appendChild(boxTitle);
  291. contentBox.appendChild(boxLink);
  292. list.classList.add("historyList-item");
  293. list.setAttribute('onclick', `direct(${obj.id})`);
  294. list.appendChild(divImgfr);
  295. list.appendChild(contentBox);
  296. historyList.appendChild(list);
  297. }
  298. document.querySelector('.loader').style.display = "none";
  299. }).catch(err => {
  300. console.log(err);
  301. });
  302. }
  303. function direct(id) {
  304. location.href = `make_video.html?id=${id}`;
  305. }
  306. function view() {
  307. event.stopPropagation();
  308. console.log(event.target);
  309. if (event.target.nodeName === 'I') {
  310. return;
  311. } else {
  312. window.open(`http://${event.target.dataset.url}`, '_blank');
  313. }
  314. }
  315. function gotoDraft (id) {
  316. location.href = `make_video.html?draftid=${id}`;
  317. }
  318. function deleteDraft(id) {
  319. let token = getCookie('jwt_token');
  320. JsLoadingOverlay.show({
  321. "overlayBackgroundColor": "#FFFFFF",
  322. "overlayOpacity": "1",
  323. "spinnerIcon": "ball-circus",
  324. "spinnerColor": "#B9DDF3",
  325. "spinnerSize": "1x",
  326. "overlayIDName": "overlay",
  327. "spinnerIDName": "spinner",
  328. "offsetX": 0,
  329. "offsetY": 0,
  330. "containerID": "draft-table",
  331. "lockScroll": false,
  332. "overlayZIndex": 9998,
  333. "spinnerZIndex": 9999
  334. });
  335. axios({
  336. method: 'post',
  337. url: 'https://www.choozmo.com:8887/del_draft',
  338. headers: {
  339. 'accept': 'application/json',
  340. 'Authorization': `Bearer ${token}`,
  341. 'Content-Type': 'application/json'
  342. },
  343. data: { "id": id }
  344. }).then(res => {
  345. console.log(res.data);
  346. //$('.draft-content-delete').html('<i class="fas fa-trash-alt"></i>');
  347. JsLoadingOverlay.hide();
  348. getDraft();
  349. }).catch(err => {
  350. console.log(err);
  351. });
  352. }
  353. $('.share-email').click(function() {
  354. var link = `mailto:me@example.com?subject=
  355. ${encodeURIComponent("Check out AI Spokesgirl")}
  356. &body=${encodeURIComponent('I just created a video in 5 minutes, check out this amazing video making tool. https://video.choozmo.com/')}`;
  357. window.location.href = link;
  358. });
  359. function trialStart() {
  360. let title = "歡迎使用AiSpokesgirl!將你的生活、創作 、宣傳做成影片。";
  361. let html = `<p>您有 <b> 2 </b> 分鐘影片製作額度。</p><br>
  362. <p>您可以使用:</p>
  363. <ul>
  364. <li>1. 短影片製作</li>
  365. <li>2. 個人歷史紀錄儲存</li>
  366. <li>3. 影片下載(Mp4)</li>
  367. </ul>
  368. <p>欲使用其他功能請升級為Premium方案</p>`;
  369. let confirmButtonText = '我知道了!';
  370. if (lan == 'en') {
  371. title = "Welcome to AiSpokesgirl! Make your first video for promotion, creation and life today!";
  372. html = `<p>You get<b>2</b>minutes of video</p><br>
  373. <p>Here are several features you can try,</p>
  374. <ul>
  375. <li>1. Short video creation</li>
  376. <li>2. Personal video history</li>
  377. <li>3. Downloadable format (MP4)</li>
  378. </ul>
  379. <p>Want to access more features? Follow the link below to upgrade to a paid plan today.</p>`;
  380. confirmButtonText = 'OK';
  381. }
  382. Swal.fire({
  383. title,
  384. html,
  385. icon: 'success',
  386. confirmButtonColor: '#3085d6',
  387. confirmButtonText
  388. });
  389. }
  390. function trialEnd() {
  391. let title = "您的試用即將結束!好的idea值得延續,透過影片將你的idea完整呈現。";
  392. let html = `<p>前往網站以升級為Premium方案,或是聯絡我們以洽詢細節。</p>`;
  393. let confirmButtonText = '立即升級';
  394. if (lan == 'en') {
  395. title = "Your trial is gonna over soon. Your idea worth spreading.";
  396. html = `<p>All good things don't have to come to an end.</p><br>
  397. <h5>Show your idea through video</h5><br>
  398. <p>Want to access more features? Follow the link below to upgrade
  399. to a paid plan today or contact us get further details.</p>`;
  400. confirmButtonText = 'Upgrade Now';
  401. }
  402. Swal.fire({
  403. title,
  404. html,
  405. icon: 'success',
  406. confirmButtonColor: '#3085d6',
  407. confirmButtonText
  408. }).then(result => {
  409. if (result.isConfirmed) {
  410. location.href = "pricing.html";
  411. }
  412. });;
  413. }
  414. var screenWidth = screen.width;
  415. console.log(screenWidth)
  416. $( ".menu-bar" ).click(function() {
  417. $(".sidenav").show();
  418. });
  419. $( ".reply" ).click(function() {
  420. $(".sidenav").hide();
  421. });