Fix link/address copy over plain-HTTP LAN; show group link URL inline
navigator.clipboard only works in a secure context, so copy silently failed when served over a LAN IP on http. Add a robustCopy() with a textarea+execCommand fallback (used by group-link, address and channel-link copy). The group/channel 'Link' button now toggles a visible, selectable URL row beneath the group with a working copy button. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -299,9 +299,23 @@ function onAvatarChange(input) {
|
||||
reader.readAsDataURL(file);
|
||||
}
|
||||
|
||||
// Clipboard that also works over plain-HTTP LAN (navigator.clipboard needs a secure context).
|
||||
function robustCopy(text) {
|
||||
if (navigator.clipboard && window.isSecureContext) {
|
||||
return navigator.clipboard.writeText(text).catch(() => fallbackCopy(text));
|
||||
}
|
||||
return Promise.resolve(fallbackCopy(text));
|
||||
}
|
||||
function fallbackCopy(text) {
|
||||
const ta = document.createElement('textarea');
|
||||
ta.value = text; ta.style.position = 'fixed'; ta.style.opacity = '0';
|
||||
document.body.appendChild(ta); ta.focus(); ta.select();
|
||||
try { document.execCommand('copy'); } catch (e) {}
|
||||
document.body.removeChild(ta);
|
||||
}
|
||||
function copyAddr(ev, btn, addr) {
|
||||
ev.stopPropagation();
|
||||
navigator.clipboard.writeText(addr).then(() => {
|
||||
robustCopy(addr).then(() => {
|
||||
btn.innerHTML = '<i class="fa-solid fa-check"></i>';
|
||||
setTimeout(() => btn.innerHTML = '<i class="fa-solid fa-copy"></i>', 1500);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user