script_profile.js 16 KB

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