diff --git a/frontend/src/tools/dateien.jsx b/frontend/src/tools/dateien.jsx index e39ab3c..1bf1167 100644 --- a/frontend/src/tools/dateien.jsx +++ b/frontend/src/tools/dateien.jsx @@ -220,33 +220,41 @@ function UploadShareManager({ toast }) { setShortening(null); }; - const copyLink = async (shareId, token) => { - // Wenn Kurz-URL vorhanden, die nehmen - sonst generieren - if (shortUrls[shareId]) { - navigator.clipboard?.writeText(shortUrls[shareId]).catch(()=>{}); - setCopied(token); setTimeout(()=>setCopied(null),2500); - return; + const doCopy = (text) => { + // Fallback-Kopieren ohne navigator.clipboard (funktioniert auch in PWA/mobile) + if (navigator.clipboard) { + navigator.clipboard.writeText(text).catch(() => { + const ta = document.createElement('textarea'); + ta.value = text; ta.style.cssText='position:fixed;opacity:0'; + document.body.appendChild(ta); ta.focus(); ta.select(); + document.execCommand('copy'); document.body.removeChild(ta); + }); + } else { + const ta = document.createElement('textarea'); + ta.value = text; ta.style.cssText='position:fixed;opacity:0'; + document.body.appendChild(ta); ta.focus(); ta.select(); + document.execCommand('copy'); document.body.removeChild(ta); } - // Kurz-URL erst generieren - setShortening(shareId); - const url = `${window.location.origin}/u/${token}`; - try { - const r = await fetch(`https://is.gd/create.php?format=simple&url=${encodeURIComponent(url)}`); - const short = await r.text(); - if (short.startsWith('http')) { - setShortUrls(p=>({...p,[shareId]:short.trim()})); - navigator.clipboard?.writeText(short.trim()).catch(()=>{}); - setCopied(token); setTimeout(()=>setCopied(null),2500); - } else { - // Fallback auf Original-URL - navigator.clipboard?.writeText(url).catch(()=>{}); - setCopied(token); setTimeout(()=>setCopied(null),2500); - } - } catch { - navigator.clipboard?.writeText(url).catch(()=>{}); - setCopied(token); setTimeout(()=>setCopied(null),2500); + }; + + const copyLink = (shareId, token) => { + // SOFORT kopieren (synchron, innerhalb User-Gesture-Kontext) + const url = shortUrls[shareId] || `${window.location.origin}/u/${token}`; + doCopy(url); + setCopied(token); setTimeout(()=>setCopied(null), 2500); + + // Falls noch keine Kurz-URL: im Hintergrund generieren (für nächsten Klick) + if (!shortUrls[shareId] && shortening !== shareId) { + setShortening(shareId); + const fullUrl = `${window.location.origin}/u/${token}`; + fetch(`https://is.gd/create.php?format=simple&url=${encodeURIComponent(fullUrl)}`) + .then(r => r.text()) + .then(short => { + if (short.startsWith('http')) setShortUrls(p=>({...p,[shareId]:short.trim()})); + }) + .catch(()=>{}) + .finally(()=>setShortening(null)); } - setShortening(null); }; const loadLogs = () => {