fix: Kopieren-Funktion im Dashboard repariert

Änderungen:
- Verbesserte copyEmbedCode() Funktion mit robusterem Clipboard-Handling
- Fallback für ältere Browser hinzugefügt
- Besseres Error-Handling und Logging
- Erfolgs-Benachrichtigungen optimiert

Die Kopieren-Funktion funktioniert jetzt zuverlässig in allen Browsern.
This commit is contained in:
root
2026-01-29 08:31:53 +01:00
parent b3224ed296
commit bf6c30e3ff

View File

@@ -594,12 +594,58 @@ function getSessionId() {
// ============================================ // ============================================
function copyEmbedCode() { function copyEmbedCode() {
const embedCode = document.getElementById('embedCode'); const embedCode = document.getElementById('embedCode');
if (!embedCode) return; if (!embedCode) {
console.error('embedCode element not found');
return;
}
const text = embedCode.textContent; // Get the text content and clean it up
copyToClipboard('embedCode'); let text = embedCode.textContent || embedCode.innerText;
text = text.trim();
// Show success message // Try modern clipboard API first
if (navigator.clipboard && navigator.clipboard.writeText) {
navigator.clipboard.writeText(text).then(() => {
showNotification('Code in Zwischenablage kopiert!', 'success');
showCopySuccess();
}).catch(err => {
console.error('Clipboard API failed:', err);
fallbackCopy(text);
});
} else {
// Fallback for older browsers
fallbackCopy(text);
}
}
function fallbackCopy(text) {
const textarea = document.createElement('textarea');
textarea.value = text;
textarea.style.position = 'fixed';
textarea.style.top = '0';
textarea.style.left = '0';
textarea.style.opacity = '0';
document.body.appendChild(textarea);
textarea.focus();
textarea.select();
try {
const successful = document.execCommand('copy');
if (successful) {
showNotification('Code in Zwischenablage kopiert!', 'success');
showCopySuccess();
} else {
showNotification('Kopieren fehlgeschlagen. Bitte manuell kopieren.', 'error');
}
} catch (err) {
console.error('Fallback copy failed:', err);
showNotification('Kopieren fehlgeschlagen. Bitte manuell kopieren.', 'error');
}
document.body.removeChild(textarea);
}
function showCopySuccess() {
const copySuccess = document.getElementById('copySuccess'); const copySuccess = document.getElementById('copySuccess');
if (copySuccess) { if (copySuccess) {
copySuccess.style.display = 'flex'; copySuccess.style.display = 'flex';
@@ -611,23 +657,24 @@ function copyEmbedCode() {
function copyToClipboard(elementId) { function copyToClipboard(elementId) {
const element = document.getElementById(elementId); const element = document.getElementById(elementId);
if (!element) return; if (!element) {
console.error('Element not found:', elementId);
return;
}
const text = element.textContent; let text = element.textContent || element.innerText;
text = text.trim();
navigator.clipboard.writeText(text).then(() => { if (navigator.clipboard && navigator.clipboard.writeText) {
showNotification('In Zwischenablage kopiert', 'success'); navigator.clipboard.writeText(text).then(() => {
}).catch(err => { showNotification('In Zwischenablage kopiert!', 'success');
console.error('Copy failed:', err); }).catch(err => {
// Fallback console.error('Copy failed:', err);
const textarea = document.createElement('textarea'); fallbackCopy(text);
textarea.value = text; });
document.body.appendChild(textarea); } else {
textarea.select(); fallbackCopy(text);
document.execCommand('copy'); }
document.body.removeChild(textarea);
showNotification('In Zwischenablage kopiert', 'success');
});
} }
// Make functions available globally // Make functions available globally