script_profile.js 16 KB

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