1// éè¦æé guestId.js使ç¨,使ç¨äºcookie彿° 2 3let isLoggedIn = getCookie('isLoggedIn'); 4const userType = parseInt(getCookie('userType'), 10); 5const quotaBalance = parseInt(getCookie('quotaBalance'), 10); 6 7// æ ¹æ®æ¡ä»¶å¤æç¨æ·æ¯å¦æ¯ VIPï¼true为VIPï¼false为æ®éä¼å 8const isVIP = (isLoggedIn === 'true') && (userType !== 1 && userType !== 2) && (quotaBalance > 0); 9 10// è¾åºæä½¿ç¨ isVIP åé 11// console.log('Is VIP:', isVIP); 12 13if (isVIP) { 14 document.querySelector('.upgrade-to-vip').style.display = 'none'; 15} else { 16 document.querySelector('.renew-vip').style.display = 'none'; 17} 18 19let avatar = getCookie('avatar'); 20let email = getCookie('email'); 21const emailPattern = /^[^\s@]+@[^\s@]+\.[^\s@]+$/; 22email = emailPattern.test(email) ? email : 'Enter your main email.'; 23 24let nickName = getCookie('nickName'); 25const currentURL = window.location.href; 26 27// 没æuserId Cookieå¼çæ¶åï¼ælogin=member弿伿§è¡ 28//if (!getCookie('userId') && currentURL.includes('login=member')) { 29// ælogin=member弿伿§è¡ï¼login=member代表ç»éè¡ä¸º 30if (currentURL.includes('login=member')) { 31 const url = config.apiGetUserInfo; 32 const getUserInfoData = {}; // 妿éè¦ä¼ éåæ°ï¼è¯·æ ¹æ®æ¥å£ææ¡£æä¾çè¦æ±å¡«åç¸åºçæ°æ® 33 34 fetch(url, { 35 method: 'POST', 36 credentials: 'include', // èªå¨åé Cookies é ç½® 37 headers: { 38 'Content-Type': 'application/json' 39 }, 40 body: JSON.stringify(getUserInfoData) 41 }) 42 .then(function(response) { 43 if (response.ok) { 44 return response.json(); 45 } else { 46 throw new Error('Network response was not OK.'); 47 } 48 }) 49 50 .then(function(data) { 51 console.log(data); // å¤çè¿åçæ°æ® 52 53 // å»¶è¿ 30 ç§åç»§ç»æ§è¡ä»¥ä¸é»è¾ 54 //setTimeout(function() { 55 // å¨è¿éæ¾ç½®ä½ æ³è¦å¨å»¶è¿åæ§è¡ç代ç 56 //}, 30000); // 30000 毫ç§å³ä¸º 30 ç§ 57 58 // 夿æ¯å¦åå¨è¿åçæ°æ® 59 if (data && data.data && data.data.user) { 60 const userData = data.data.user; 61 const quotaData = data.data.quota; 62 avatar = userData.avatar; 63 email = userData.email; 64 nickName = userData.nickname; 65 const userId = userData.userId; 66 const userIdStr = userData.userIdStr; 67 const userStatus = userData.status; 68 const userType = userData.userType; 69 const quotaBalance = quotaData.quotaBalance; 70 const endTime = quotaData.endTime; 71 isLoggedIn = true; 72 73 // å°æ°æ®åå ¥ cookie 74 // å°æµè§å¨æçº¹åå¨å¨ä¸ä¸ªæææä¸º 1 天ç Cookie ä¸ 75 setCookie('avatar', avatar, 1); 76 setCookie('email', email, 1); 77 setCookie('nickName', nickName, 1); 78 // setCookie('userId', userId, 1); 79 // userIdStrè§£å³userIdè¶ é¿é æç精度é®é¢ 80 setCookie('userId', userIdStr, 1); 81 setCookie('userStatus', userStatus, 1); 82 setCookie('userType', userType, 1); 83 setCookie('quotaBalance', quotaBalance, 1); 84 setCookie('endTime', endTime, 1); 85 setCookie('isLoggedIn', isLoggedIn, 1); 86 87 // èªå¨å·æ°å½åé¡µé¢ 88 location.href = location.href.replace(/[?&]login=member/g, ''); 89 90 } else { 91 // è¾åºéè¯¯ä¿¡æ¯ 92 throw new Error('APIæ¥å£åºç°é®é¢ï¼è¯·èç³»ææ¯è´è´£äººæ¢å¤.'); 93 } 94 }) 95 .catch(function(error) { 96 console.log(error); // å¤ç请æ±é误 97 }); 98} 99 100if (isLoggedIn) { 101 document.querySelector('.login').style.display = 'none'; 102 103 // è·å img å ç´ 104 const imgElement1 = document.getElementById('avatarImg1'); 105 // æ¿æ¢ src 屿§çå¼ 106 imgElement1.setAttribute('src', avatar); 107 108 // è·å img å ç´ 109 const imgElement2 = document.getElementById('avatarImg2'); 110 // æ¿æ¢ src 屿§çå¼ 111 imgElement2.setAttribute('src', avatar); 112 113 // è·å span å ç´ 114 const userInfoElement = document.getElementById('userInfo'); 115 // 设置æ°çææ¬å 容 116 userInfoElement.innerHTML = `${nickName}<br>${email}`; 117 118} else { 119 document.querySelector('.login-avatar').style.display = 'none'; 120} 121 122function showAccountDropdown() { 123 document.getElementById("account-dropdown").classList.add("account-show"); 124} 125 126function hideAccountDropdown() { 127 document.getElementById("account-dropdown").classList.remove("account-show"); 128} 129 130document.addEventListener("click", function(event) { 131 if (!event.target.closest(".login-avatar")) { 132 hideAccountDropdown(); 133 } 134}); 135 136// è·åâå级VIPï¼äº«åæ éå¶è½¬æ¢ï¼â对åºç龿¥å ç´ 137const rightTopUpgradeVipLink = document.getElementById('right-top-upgrade-vip-link'); 138// ç¡®ä¿rightTopUpgradeVipä¸ä¸ºç©º 139if (rightTopUpgradeVipLink) { 140 // ç¹å»äºä»¶å¤ç彿° 141 rightTopUpgradeVipLink.addEventListener('click', function(event) { 142 event.preventDefault(); // 黿¢é»è®¤é¾æ¥è¡ä¸º 143 window.location.href = "/en/pricing/"; 144 }); 145} 146
147// è·åâå°æ¬çVIPï¼ç»è®¢äº«å9æï¼â对åºç龿¥å ç´ 148const rightTopRenewVipLink = document.getElementById('right-top-renew-vip-link'); 149// ç¡®ä¿rightTopRenewVipä¸ä¸ºç©º 150if (rightTopRenewVipLink) { 151 // ç¹å»äºä»¶å¤ç彿° 152 rightTopRenewVipLink.addEventListener('click', function(event) { 153 event.preventDefault(); // 黿¢é»è®¤é¾æ¥è¡ä¸º 154 window.location.href = "/en/pricing/"; 155 }); 156} 157 158// è·åâè´¦æ·â对åºç龿¥å ç´ 159const rightTopAccountLink = document.getElementById('right-top-account-link'); 160// ç¡®ä¿rightTopAccountLinkä¸ä¸ºç©º 161if (rightTopAccountLink) { 162 // ç¹å»äºä»¶å¤ç彿° 163 rightTopAccountLink.addEventListener('click', function(event) { 164 event.preventDefault(); // 黿¢é»è®¤é¾æ¥è¡ä¸º 165 window.location.href = "/en/account/"; 166 }); 167} 168 169// è·åâéåºâ龿¥å ç´ 170const logoutLink = document.querySelector('.logout'); 171 172// ç¹å»äºä»¶å¤ç彿° 173logoutLink.addEventListener('click', function(event) { 174 event.preventDefault(); // 黿¢é»è®¤é¾æ¥è¡ä¸º 175 176 // æ¸ é¤ cookie 177 clearCookie('avatar'); 178 clearCookie('email'); 179 clearCookie('nickName'); 180 clearCookie('userId'); 181 clearCookie('userStatus'); 182 clearCookie('userType'); 183 clearCookie('quotaBalance'); 184 clearCookie('endTime'); 185 clearCookie('isLoggedIn'); 186 187 // æ¸ ç©ºææç¼å 188 localStorage.clear(); 189 190 // åèµ· GET è¯·æ± 191 fetch(config.apiLogout, { 192 method: 'GET', 193 credentials: 'include' // èªå¨åé Cookies é ç½® 194 }) 195 .then(function(response) { 196 if (response.ok) { 197 // æåæ§è¡éåºæä½ï¼å¯ä»¥è¿è¡å ¶ä»å¤ç 198 //console.log('Logout successful!'); 199 200 // éæ°è·å游客çim_access_token 201 getGuestImAccessToken(); 202 203 setTimeout(function() { 204 // èªå¨å·æ°å½åé¡µé¢ 205 location.reload(); 206 }, 1000); // 模æå»¶è¿ 1 ç§ 207 208 } else { 209 throw new Error('Logout failed.'); 210 } 211 }) 212 .catch(function(error) { 213 console.log(error); // å¤ç请æ±é误 214 }); 215}); 216
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.