script_profiles.js 14 KB

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