script_profile.js 18 KB

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