File tree 2 files changed +15
-3
lines changed
apps/cookie-butler/static/js
2 files changed +15
-3
lines changed Original file line number Diff line number Diff line change @@ -60,13 +60,13 @@ async function scanCode(platform) {
60
60
if ( timeoutTimer ) clearTimeout ( timeoutTimer ) ;
61
61
62
62
const qrcode_expired = './static/img/qrcode_expired.jpg' ;
63
+ const img = document . getElementById ( 'qrcode' ) ;
63
64
64
65
try {
65
66
// 获取二维码
66
67
const qrData = await qrcode_handler . startScan ( platform ) ;
67
68
68
69
// 显示二维码
69
- const img = document . getElementById ( 'qrcode' ) ;
70
70
img . src = qrData . qrcode ;
71
71
72
72
// 开始轮询扫码结果
@@ -116,10 +116,10 @@ async function scanCode(platform) {
116
116
} , 30000 ) ;
117
117
118
118
} catch ( error ) {
119
+ console . log ( error )
119
120
if ( pollInterval ) clearInterval ( pollInterval ) ;
120
121
if ( timeoutTimer ) clearTimeout ( timeoutTimer ) ;
121
122
img . src = qrcode_expired ;
122
123
showToast ( `获取二维码失败:${ error . message } ` , 'error' ) ;
123
124
}
124
125
}
125
-
Original file line number Diff line number Diff line change @@ -29,7 +29,19 @@ class QRCodeHandler {
29
29
}
30
30
31
31
static generateUUID ( ) {
32
- return crypto . randomUUID ( ) ;
32
+ if ( crypto && typeof crypto . randomUUID === 'function' ) {
33
+ return crypto . randomUUID ( ) ;
34
+ } else if ( crypto && typeof crypto . getRandomValues === 'function' ) {
35
+ return "10000000-1000-4000-8000-100000000000" . replace ( / [ 0 1 8 ] / g, c =>
36
+ ( + c ^ crypto . getRandomValues ( new Uint8Array ( 1 ) ) [ 0 ] & 15 >> + c / 4 ) . toString ( 16 )
37
+ ) ;
38
+ } else {
39
+ return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx' . replace ( / [ x y ] / g, function ( c ) {
40
+ const r = ( Math . random ( ) * 16 ) | 0 ,
41
+ v = c == 'x' ? r : ( r & 0x3 ) | 0x8 ;
42
+ return v . toString ( 16 ) ;
43
+ } ) ;
44
+ }
33
45
}
34
46
35
47
async _generateQRCode ( url ) {
You can’t perform that action at this time.
0 commit comments