script_profile.js 16 KB

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