From bfee33bc7f595eb472f45c66ecf4d9ab56bf4d36 Mon Sep 17 00:00:00 2001 From: TypeTheory <104051227+TypeThe0ry@users.noreply.github.com> Date: Sat, 27 Jun 2026 18:49:02 +0800 Subject: [PATCH] Add room code clipboard fallback --- static/index.html | 54 +++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 50 insertions(+), 4 deletions(-) diff --git a/static/index.html b/static/index.html index 5cfbbf9..9df2e80 100755 --- a/static/index.html +++ b/static/index.html @@ -1180,12 +1180,58 @@

{{gameTypeName(selectedGameType)}}大厅

code = String(code || ''); if (!code) return; var done = function () { layer.msg('房号已复制:' + code); }; - if (navigator.clipboard && navigator.clipboard.writeText) { - navigator.clipboard.writeText(code).then(done).catch(function () { - layer.msg('房号:' + code); + var escapeHtml = function (text) { + return String(text).replace(/[&<>"']/g, function (ch) { + return ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' })[ch]; + }); + }; + var showManualCopy = function () { + layer.msg('复制失败,请手动复制房号:' + code); + layer.open({ + type: 1, + title: '手动复制房号', + shadeClose: true, + area: ['min(320px, 90vw)', 'auto'], + content: '
' + + '
复制失败,请手动复制房号:
' + + '' + + '
', + success: function (layero) { + var field = layero && layero[0] ? layero[0].querySelector('textarea') : null; + if (field) { + field.focus(); + field.select(); + } + } }); + }; + var fallbackCopy = function () { + var field = document.createElement('textarea'); + field.value = code; + field.setAttribute('readonly', 'readonly'); + field.style.position = 'fixed'; + field.style.left = '-9999px'; + field.style.top = '0'; + document.body.appendChild(field); + field.focus(); + field.select(); + var ok = false; + try { + ok = document.execCommand('copy'); + } catch (e) { + ok = false; + } + document.body.removeChild(field); + if (ok) { + done(); + } else { + showManualCopy(); + } + }; + if (navigator.clipboard && navigator.clipboard.writeText) { + navigator.clipboard.writeText(code).then(done).catch(fallbackCopy); } else { - layer.msg('房号:' + code); + fallbackCopy(); } }, openRules: function () {