Skip to content

Commit 010a468

Browse files
authored
Merge pull request #8 from Hiram-Wong/main
[optimize] uuid compatibility && [bug] fix img dom not find
2 parents 875447f + ff2f728 commit 010a468

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

Diff for: apps/cookie-butler/static/js/cookie.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,13 @@ async function scanCode(platform) {
6060
if (timeoutTimer) clearTimeout(timeoutTimer);
6161

6262
const qrcode_expired = './static/img/qrcode_expired.jpg';
63+
const img = document.getElementById('qrcode');
6364

6465
try {
6566
// 获取二维码
6667
const qrData = await qrcode_handler.startScan(platform);
6768

6869
// 显示二维码
69-
const img = document.getElementById('qrcode');
7070
img.src = qrData.qrcode;
7171

7272
// 开始轮询扫码结果
@@ -116,10 +116,10 @@ async function scanCode(platform) {
116116
}, 30000);
117117

118118
} catch (error) {
119+
console.log(error)
119120
if (pollInterval) clearInterval(pollInterval);
120121
if (timeoutTimer) clearTimeout(timeoutTimer);
121122
img.src = qrcode_expired;
122123
showToast(`获取二维码失败:${error.message}`, 'error');
123124
}
124125
}
125-

Diff for: apps/cookie-butler/static/js/core.js

+13-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,19 @@ class QRCodeHandler {
2929
}
3030

3131
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(/[018]/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(/[xy]/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+
}
3345
}
3446

3547
async _generateQRCode(url) {

0 commit comments

Comments
 (0)