script_profile.js 18 KB

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