Add room code clipboard fallback#5
Merged
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
This PR improves the “copy room code” UX in the lobby UI by adding a fallback path when the modern Clipboard API is unavailable or rejects, and providing a manual-copy dialog as a last resort.
Changes:
- Updated
copyRoomCodeto trynavigator.clipboard.writeTextfirst, then fall back to a DOM-based copy viadocument.execCommand('copy'). - Added a manual-copy modal (
layer.open) that presents the room code in a selectable<textarea>when automatic copy fails.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+1183
to
+1207
| 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: '<div style="padding:18px;text-align:center;">' + | ||
| '<div style="margin-bottom:10px;color:#666;">复制失败,请手动复制房号:</div>' + | ||
| '<textarea readonly style="box-sizing:border-box;width:100%;min-height:52px;padding:12px;text-align:center;font-size:22px;font-weight:bold;letter-spacing:2px;resize:none;" onclick="this.select()">' + escapeHtml(code) + '</textarea>' + | ||
| '</div>', | ||
| success: function (layero) { | ||
| var field = layero && layero[0] ? layero[0].querySelector('textarea') : null; | ||
| if (field) { | ||
| field.focus(); | ||
| field.select(); | ||
| } | ||
| } | ||
| }); | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
Description
copyRoomCodefunction instatic/index.htmlto trynavigator.clipboard.writeTextfirst and fall back to a DOM-based copy when that fails.fallbackCopythat creates a temporary<textarea>, callsselect()anddocument.execCommand('copy'), and reports success with the existinglayer.msg('房号已复制:' + code)on success.showManualCopywhich opens alayer.opendialog containing a readonly, selectable<textarea>with the room code and shows the explicit failure message复制失败,请手动复制房号:xxxwhen both copy attempts fail.escapeHtmlto safely render the room code inside the dialog and kept all UI messages and behavior consistent with existing patterns.Testing
git diff --checkand it reported no issues.Codex Task