script_profiles.js 14 KB

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