|
| 1 | +--- |
| 2 | +permalink: /qr-login.html |
| 3 | +layout: default |
| 4 | +--- |
| 5 | + |
| 6 | +<style> |
| 7 | + .selectable { |
| 8 | + -webkit-user-select: all; |
| 9 | + user-select: all; |
| 10 | + cursor: pointer; |
| 11 | + padding: 5px; |
| 12 | + background-color: #b2b2b2; |
| 13 | + border-radius: 5px; |
| 14 | + display: inline-block; |
| 15 | + margin-top: 10px; |
| 16 | + } |
| 17 | +</style> |
| 18 | +<script src=" https://cdn.jsdelivr.net/npm/[email protected]/build/qrcode.min.js" ></script> |
| 19 | +<script> |
| 20 | + function generateQRCode() { |
| 21 | + const urlParams = new URLSearchParams(window.location.search); |
| 22 | + const verificationUri = urlParams.get('verificationUri'); |
| 23 | + const userCode = urlParams.get('userCode'); |
| 24 | + const login = urlParams.get('login'); |
| 25 | + if (!verificationUri || !userCode) { |
| 26 | + return; // 不显示任何内容 |
| 27 | + } |
| 28 | + const qrcodeContainer = document.getElementById('qrcode'); |
| 29 | + if (login === '1') { |
| 30 | + const userPrompt = document.createElement('p'); |
| 31 | + userPrompt.innerHTML = `请复制代码 <span class="selectable" id="userCode">${userCode}</span> <br>并前往 <a href="${verificationUri}">${verificationUri}</a>,输入代码允许访问并登录微软账户。`; |
| 32 | + qrcodeContainer.appendChild(userPrompt); |
| 33 | + } else { |
| 34 | + const currentUrl = window.location.href + '?login=1'; |
| 35 | + console.log("currentUrl: ", currentUrl); |
| 36 | + const canvas = document.createElement('canvas'); |
| 37 | + QRCode.toCanvas(canvas, currentUrl, function (error) { |
| 38 | + if (error) console.error(error); |
| 39 | + }); |
| 40 | + qrcodeContainer.appendChild(canvas); |
| 41 | + const promptMessage = document.createElement('p'); |
| 42 | + promptMessage.innerHTML = `请扫描二维码。`; |
| 43 | + qrcodeContainer.appendChild(promptMessage); |
| 44 | + } |
| 45 | + } |
| 46 | + window.onload = function() { |
| 47 | + generateQRCode(); |
| 48 | + } |
| 49 | +</script> |
| 50 | + |
| 51 | +<div id="qrcode"></div> |
| 52 | + |
| 53 | +<noscript> |
| 54 | + <p>请开启 JavaScript 以查看二维码生成内容。</p> |
| 55 | +</noscript> |
0 commit comments