diff --git a/apps/cookie-butler/static/js/cookie.js b/apps/cookie-butler/static/js/cookie.js index 2e3b7ba..564b79a 100644 --- a/apps/cookie-butler/static/js/cookie.js +++ b/apps/cookie-butler/static/js/cookie.js @@ -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; // 开始轮询扫码结果 @@ -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'); } } - diff --git a/apps/cookie-butler/static/js/core.js b/apps/cookie-butler/static/js/core.js index 3df2e0e..f87c0b4 100644 --- a/apps/cookie-butler/static/js/core.js +++ b/apps/cookie-butler/static/js/core.js @@ -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) {