-
Notifications
You must be signed in to change notification settings - Fork 12
/
index.html
executable file
·396 lines (357 loc) · 14.5 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
<!DOCTYPE html lang="zh-CN">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link rel="shortcut icon"
href="data:image/svg+xml;base64,PHN2ZyB2ZXJzaW9uPSIxLjEiIGlkPSImI3g1NkZFOyYjeDVDNDI7XzEiDQoJeG1sbnM9Imh0dHA6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yIvPg0KPC9zdmc+DQo=">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="author" content="Banka2017 (https://nest.moe)">
<meta name="description" content="扫码登录获取BDUSS">
<meta name="keywords" content="百度,登录,百度登录,BDUSS,BDUSS在线获取">
<title>扫码登录获取BDUSS</title>
<style>
.block {
display: block;
}
.none {
display: none;
}
a {
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
@media screen and (min-width: 0) {
.container {
padding-left: 30px;
padding-right: 30px;
}
}
@media screen and (min-width: 576px) {
.container {
padding-left: 20vw;
padding-right: 20vw;
}
}
</style>
<style>
/*
mock @geist-ui
*/
.zi-btn {
border-radius: 5px;
border: 1px solid #666666;
padding: 0.5em 0;
background-color: white;
width: 100%;
max-width: 200px;
font-size: 1em;
color: #666666;
cursor: pointer;
transition: all;
transition-duration: 150ms;
}
.zi-btn:hover {
color: white;
background-color: black;
}
.success {
color: white;
border-color: #0070f3;
background-color: #0070f3;
}
.success:hover {
color: #0070f3;
background-color: white;
}
.primary {
color: white;
border: 1px solid black;
background-color: black;
}
@keyframes spin {
to {
transform: rotate(360deg);
}
}
.animate-spin {
animation: spin 1s linear infinite;
}
.zi-card {
border-radius: 5px;
border: 1px solid #666666;
padding: 1rem;
}
li {
margin-bottom: 0.5rem;
}
.zi-note {
border-radius: 5px;
border: 2px solid #f5a623;
padding: 1rem
}
.zi-note-type {
color: #f5a623;
font-weight: 700;
}
</style>
</head>
<body>
<div id="app" class="container" style="padding-top: 2em;">
<p id="app-alert" class="zi-note alert none" style="font-size: 1.1em">
<span class="zi-note-type" style="font-size: 1.1rem">警告:</span> 将跳转到: <a id="app-alert-link" href="."
target="_blank" style="word-break: break-all;">localhost</a>
</p>
<div id="card" class="zi-card pin" style="text-align: center;">
<div id="card-loading" style="text-align: center;">
<svg style="margin-left: 0.5rem; margin-right: 1.5rem; height: 2.5rem; width: 2.5rem; color: #0070f3;"
class="animate-spin" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24">
<circle style="opacity: 0.25;" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4"></circle>
<path style="opacity: 0.75;" fill="currentColor"
d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z">
</path>
</svg>
</div>
<div id="card-success" class="none">
<img
src="data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHJvbGU9ImltZyIgdmVyc2lvbj0iMS4xIiB4PSIwcHgiIHk9IjBweCIgd2lkdGg9IjM2cHgiIGhlaWdodD0iMzZweCI+PGNpcmNsZSBmaWxsPSIjM0M3NkZGIiBjeD0iMTgiIGN5PSIxOCIgcj0iMTgiIC8+PHBhdGggZmlsbD0iI0ZGRkZGRiIgc3Ryb2tlPSIjRkZGRkZGIiBzdHJva2Utd2lkdGg9IjIiIHN0cm9rZS1saW5lY2FwPSJyb3VuZCIgc3Ryb2tlLWxpbmVqb2luPSJyb3VuZCIgZD0iTTEwLjQ1LDE3LjE2N2w2LDUuNzUgTDEwLjQ1LDE3LjE2N3oiIC8+PHBhdGggZmlsbD0iI0ZGRkZGRiIgc3Ryb2tlPSIjRkZGRkZGIiBzdHJva2Utd2lkdGg9IjIiIHN0cm9rZS1saW5lY2FwPSJyb3VuZCIgc3Ryb2tlLWxpbmVqb2luPSJyb3VuZCIgZD0iTTE2LjQ1LDIyLjkxN2wxMS0xMCBMMTYuNDUsMjIuOTE3eiIgLz48L3N2Zz4="
alt="qrcode-success" style="margin-bottom: 1em;">
<p>扫描成功<br>请确认登录</p>
</div>
<div id="card-scan" class="none">
<img id="card-scan-img" alt="QRcode" style="max-width: 200px; width: 100%; aspect-ratio: 1;">
<div style="margin-top: 1em;">
<button class="zi-btn" onclick="switchMode()" id="more-button">更多</button>
</div>
<div style="margin-top: 0.5em;">
<a id="web-check-button" href="https://wappass.baidu.com/wp/?qrlogin=&sign=" target="_blank">
<button class="zi-btn success">网页授权</button>
</a>
</div>
</div>
<div id="card-bduss-success-eta" class="none">
<h1>5</h1>
</div>
<div id="card-bduss-success" class="none">
<h3>BDUSS获取成功</h3>
<div style="margin-top: 1em;">
<p class="zi-card pin" style="user-select: all; text-align: start; word-break: break-all;" id="bduss-list">
</p>
</div>
<div id="card-bduss-success-inject"></div>
<div style="margin-top: 1em;">
<button class="zi-btn primary" onclick="init()">再次获取</button>
</div>
</div>
<div id="card-bduss-error" class="none">
<h3>BDUSS获取失败</h3>
<div style="margin-top: 1em;">
<button class="zi-btn primary" onclick="init()">再次获取</button>
</div>
</div>
</div>
<div class="zi-card pin" style="margin-top: 1em; border-color: #0dcaf0;">
<h3>提示</h3>
<ul>
<li>可直接点击 "网页授权" 并在新打开页授权,无需客户端扫码</li>
<li>打开百度页面时请使用移动设备或将浏览器 User-Agent 设置为移动设备的 User-Agent</li>
<li>点击 “更多” 将会获得更多信息,否则只会获取 BDUSS</li>
<li>前往本页 <a href="https://github.com/BANKA2017/get-bduss" target="_blank">GitHub 仓库</a> 获得更多信息</li>
</ul>
</div>
<div style="text-align: center; margin-top: 1em;">Created by <a href="https://nest.moe" target="_blank">BANKA</a>
with ♥</div>
</div>
<script>
'use strict';
// !!! DEPLOY YOUR OWN API ENDPOINT !!! vvv
const api = "https://api.nest.moe/baidu/bduss/v2/"
// !!! DEPLOY YOUR OWN API ENDPOINT !!! ^^^
const defaultResetCount = 15 //baidu is 18
let activeId = "card-loading"//active id
let fullModeStatus = false
let callbackURL = {}
let callbackStoken = null
let hashCallback = false
const getElement = (id) => {
return document.getElementById(id)
}
const switchActiveStatus = (id) => {
getElement(activeId).classList.remove("block")
getElement(activeId).classList.add("none")
getElement(id).classList.add("block")
getElement(id).classList.remove("none")
activeId = id
}
let controller = {
qrcode: new AbortController(),
bduss: [new AbortController()],
}
let resetCount = 0
let sign = ''
const init = () => {
switchActiveStatus("card-loading")
getElement("card-bduss-success-inject").innerHTML = ''
controller.qrcode.abort()
controller.qrcode = new AbortController()
//get qrcode
fetch(api + '?m=getqrcode', {
signal: controller.qrcode.signal
}).then(async response => {
response = await response.json()
if (response?.errno !== 0) {
switchActiveStatus("card-bduss-error")
return
}
sign = response.data.sign
getElement("card-scan-img").src = "//" + response.data.imgurl
getElement("web-check-button").href = "https://wappass.baidu.com/wp/?qrlogin=&sign=" + sign
switchActiveStatus("card-scan")
getStatus(1, sign)
}).catch(() => switchActiveStatus("card-bduss-error"))
}
const getStatus = (status, sign) => {
//-1 更换二维码
//0 进入下一步
//1 无需操作
//2 已确认
if (status > 1 || status < -1) {
return
}
controller.bduss[controller.bduss.length - 1].abort()
controller.bduss.push(new AbortController())
if (resetCount > defaultResetCount) {
init()
resetCount = 1
return
} else {
resetCount++
}
//get status
fetch(api + '?' + (new URLSearchParams('m=getbduss&sign=' + sign + (fullModeStatus ? "&full=1" : "")).toString()), {
signal: controller.bduss[controller.bduss.length - 1].signal
}).then(async response => {
response = await response.json()
if (response?.errno !== 0) {
switchActiveStatus("card-bduss-error")
return
}
if (response.data.status >= 0 && response.data.status < 2) {
if (response.data.status === 0) {
switchActiveStatus("card-success")
}
getStatus(response.data.status, sign)
} else if (response.data.status === -1) {
sign = ''
switchActiveStatus("card-bduss-error")
} else if (response.data.status === 2) {
getElement("bduss-list").innerText = response.data.bduss
if (callbackURL?.href) {
switchActiveStatus("card-bduss-success-eta")
callbackURL.searchParams.append('bduss', response.data.bduss)
if (fullModeStatus && response.data.data.stokenList[callbackStoken]) {
callbackURL.searchParams.append('stoken', response.data.data.stokenList[callbackStoken])
}
eta((new Date()).getTime() + 5000, callbackURL.href.replace(callbackURL.hash, '').replace(callbackURL.search, '') + (hashCallback ? '#/' : '?') + callbackURL.searchParams.toString())
} else {
if (fullModeStatus && response.data.data) {
//full mode
let htmlTemplate = `<ul style="text-align: start;">`
for (const key in response.data.data) {
if (key === "stokenList") {
for (const stokenKey in response.data.data["stokenList"]) {
htmlTemplate += `<li><span style="font-size: 1.1rem">stoken_${escapeHTML(stokenKey)}</span>: <span style="user-select: all; word-break: break-all; font-weight: 300;">${escapeHTML(response.data.data.stokenList[stokenKey])}</span></li>`
}
} else {
htmlTemplate += `<li><span style="font-size: 1.1rem">${escapeHTML(key)}</span>: <span style="user-select: all; word-break: break-all; font-weight: 300;">${escapeHTML(response.data.data[key])}</span></li>`
}
}
htmlTemplate += `</ul>`
getElement("card-bduss-success-inject").innerHTML = htmlTemplate
}
sign = ''
switchActiveStatus("card-bduss-success")
}
} else {
sign = ''
switchActiveStatus("card-bduss-error")
}
}).catch(e => {
if (!controller.bduss[controller.bduss.length - 2].signal.aborted) {
sign = ''
switchActiveStatus("card-bduss-error")
}
})
}
//hash check
const hashCheck = (hash) => {
if (!hash || (hash && hash.length < 3)) {
return
}
try {
callbackURL = new URL(atob(decodeURIComponent(hash.slice(2)).replaceAll('_', '/').replaceAll('-', '+')))
if (window.location.host + window.location.pathname === callbackURL.host + callbackURL.pathname) {
throw Error('Loop!')
}
callbackStoken = callbackURL.searchParams.get('stoken_type')
// try hash
if (callbackURL.hash) {
const hashParams = [...new URLSearchParams(callbackURL.hash.slice(2)).entries()]
for (const hashParam of hashParams) {
if (!callbackStoken && hashParam[0] === 'stoken_type') {
callbackStoken = hashParam[1]
hashCallback = true
}
if (!callbackURL.searchParams.has(hashParam[0])) {
callbackURL.searchParams.set(hashParam[0], hashParam[1])
}
}
}
if (callbackStoken) {
fullMode()
}
getElement("app-alert-link").innerText = hashCallback ? callbackURL.href.replace(callbackURL.search, '') : callbackURL.href.replace(callbackURL.hash, '')
getElement("app-alert-link").href = hashCallback ? callbackURL.href.replace(callbackURL.search, '') : callbackURL.href.replace(callbackURL.hash, '')
getElement("app-alert").classList.remove("none")
getElement("app-alert").classList.add("block")
} catch (error) {
console.error(error)
}
}
const eta = (endTime, loaction) => {
let now = new Date
if (now < endTime) {
document.querySelector("#card-bduss-success-eta > h1").innerText = Math.floor((endTime - now) / 1000)
setTimeout(() => eta(endTime, loaction), 200);
} else {
window.open(loaction, '_self')
}
}
const fullMode = () => {
fullModeStatus = !fullModeStatus
if (!fullModeStatus) {
document.getElementById("more-button").classList.remove("primary")
} else {
document.getElementById("more-button").classList.add("primary")
}
}
//https://stackoverflow.com/questions/30661497/xss-prevention-and-innerhtml
const escapeHTML = unsafe_str => {
return unsafe_str
.replace(/&/g, '&')
.replace(/</g, '<')
.replace(/>/g, '>')
.replace(/\"/g, '"')
.replace(/\'/g, ''')
.replace(/\//g, '/')
}
const switchMode = () => {
fullMode()
getStatus(1, sign)
}
hashCheck(location.hash)
init()
</script>
</body>
</html>