PageSourceSearch

https://www.speedpdf.com/js/en/login-logout.js

js speedpdf.com collected 2026-10-03 19:55:53 UTC 7,576 bytes, 216 lines download raw bytes

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.