mirror of
https://github.com/willmiao/ComfyUI-Lora-Manager.git
synced 2026-03-25 15:15:44 -03:00
Enhance clipboard functionality in LoraCard: implement modern clipboard API with fallback for older browsers
This commit is contained in:
@@ -78,15 +78,32 @@ export function createLoraCard(lora) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Copy button click event
|
// Copy button click event
|
||||||
card.querySelector('.fa-copy')?.addEventListener('click', e => {
|
card.querySelector('.fa-copy')?.addEventListener('click', async e => {
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
const usageTips = JSON.parse(card.dataset.usage_tips || '{}');
|
const usageTips = JSON.parse(card.dataset.usage_tips || '{}');
|
||||||
const strength = usageTips.strength || 1;
|
const strength = usageTips.strength || 1;
|
||||||
const loraSyntax = `<lora:${card.dataset.file_name}:${strength}>`;
|
const loraSyntax = `<lora:${card.dataset.file_name}:${strength}>`;
|
||||||
|
|
||||||
navigator.clipboard.writeText(loraSyntax)
|
try {
|
||||||
.then(() => showToast('LoRA syntax copied', 'success'))
|
// Modern clipboard API
|
||||||
.catch(() => showToast('Copy failed', 'error'));
|
if (navigator.clipboard && window.isSecureContext) {
|
||||||
|
await navigator.clipboard.writeText(loraSyntax);
|
||||||
|
} else {
|
||||||
|
// Fallback for older browsers
|
||||||
|
const textarea = document.createElement('textarea');
|
||||||
|
textarea.value = loraSyntax;
|
||||||
|
textarea.style.position = 'absolute';
|
||||||
|
textarea.style.left = '-99999px';
|
||||||
|
document.body.appendChild(textarea);
|
||||||
|
textarea.select();
|
||||||
|
document.execCommand('copy');
|
||||||
|
document.body.removeChild(textarea);
|
||||||
|
}
|
||||||
|
showToast('LoRA syntax copied', 'success');
|
||||||
|
} catch (err) {
|
||||||
|
console.error('Copy failed:', err);
|
||||||
|
showToast('Copy failed', 'error');
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Civitai button click event
|
// Civitai button click event
|
||||||
|
|||||||
Reference in New Issue
Block a user