script_profiles.js 15 KB

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