script_profiles.js 14 KB

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