script_profile.js 18 KB

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