fix: HTTP fallback for clipboard — execCommand('copy') textarea method
- Added copyToClipboard() in utils.js with dual strategy:
- HTTPS: navigator.clipboard.writeText() (modern API)
- HTTP: textarea + execCommand('copy') (legacy fallback)
- viewer.js: uses copyToClipboard() instead of direct navigator.clipboard
- popout.html: same dual-strategy inline
- Fixed: 'Erreur lors de la copie' on HTTP contexts
This commit is contained in:
@@ -681,16 +681,16 @@ export function renderFile(data) {
|
||||
wrapper.appendChild(pre);
|
||||
|
||||
const btn = el("button", { class: "copy-code-btn", title: "Copier le code" }, [document.createTextNode("Copier")]);
|
||||
btn.addEventListener("click", async (e) => {
|
||||
btn.addEventListener("click", (e) => {
|
||||
e.stopPropagation();
|
||||
const code = pre.querySelector("code")?.textContent || pre.textContent;
|
||||
try {
|
||||
await navigator.clipboard.writeText(code);
|
||||
const copied = copyToClipboard(code);
|
||||
if (copied) {
|
||||
btn.textContent = "✓ Copié";
|
||||
btn.classList.add("copied");
|
||||
if (typeof showToast === "function") showToast("Code copié dans le presse-papiers", "success");
|
||||
setTimeout(() => { btn.textContent = "Copier"; btn.classList.remove("copied"); }, 2000);
|
||||
} catch {
|
||||
} else {
|
||||
if (typeof showToast === "function") showToast("Erreur lors de la copie", "error");
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user