Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions apps/cookie-butler/static/js/cookie.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,13 @@ async function scanCode(platform) {
if (timeoutTimer) clearTimeout(timeoutTimer);

const qrcode_expired = './static/img/qrcode_expired.jpg';
const img = document.getElementById('qrcode');

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

// 显示二维码
const img = document.getElementById('qrcode');
img.src = qrData.qrcode;

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

} catch (error) {
console.log(error)
if (pollInterval) clearInterval(pollInterval);
if (timeoutTimer) clearTimeout(timeoutTimer);
img.src = qrcode_expired;
showToast(`获取二维码失败:${error.message}`, 'error');
}
}

14 changes: 13 additions & 1 deletion apps/cookie-butler/static/js/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,19 @@ class QRCodeHandler {
}

static generateUUID() {
return crypto.randomUUID();
if (crypto && typeof crypto.randomUUID === 'function') {
return crypto.randomUUID();
} else if (crypto && typeof crypto.getRandomValues === 'function') {
return "10000000-1000-4000-8000-100000000000".replace(/[018]/g, c =>
(+c ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> +c / 4).toString(16)
);
} else {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
const r = (Math.random() * 16) | 0,
v = c == 'x' ? r : (r & 0x3) | 0x8;
return v.toString(16);
});
}
}

async _generateQRCode(url) {
Expand Down