script_profile.js 15 KB

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