From 47e51897b123f6e582ce9e74ca7a58c47c2449b4 Mon Sep 17 00:00:00 2001 From: guy Date: Sat, 21 Nov 2026 23:08:56 -0300 Subject: [PATCH] OrbiSubs panel: make the copy button work over plain http (clipboard API needs a secure context) Co-Authored-By: Claude Opus 5.5 --- panel/src/public/app.js | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/panel/src/public/app.js b/panel/src/public/app.js index a9bb18b..65fcaca 100644 --- a/panel/src/public/app.js +++ b/panel/src/public/app.js @@ -364,8 +364,28 @@ function urlLine(label, url) { document.addEventListener('click', e => { const b = e.target.closest('.out-copy'); if (!b) return; - navigator.clipboard?.writeText(b.dataset.url).then(() => { b.classList.add('copied'); setTimeout(() => b.classList.remove('copied'), 1200); }); + copiar(b.dataset.url).then(ok => { + b.classList.add(ok ? 'copied' : 'copy-fail'); + if (!ok) window.prompt(t('Copiar URL'), b.dataset.url); + setTimeout(() => b.classList.remove('copied', 'copy-fail'), 1200); + }); }); +// navigator.clipboard solo existe en contexto seguro (https o localhost); el panel corre por +// http://IP, así que ahí no existe y el botón no copiaba nada. Respaldo: textarea + execCommand. +// Si eso también falla, se muestra la URL en un prompt para copiarla a mano. +async function copiar(texto) { + if (navigator.clipboard && window.isSecureContext) { + try { await navigator.clipboard.writeText(texto); return true; } catch {} + } + const ta = document.createElement('textarea'); + ta.value = texto; ta.setAttribute('readonly', ''); + ta.style.position = 'fixed'; ta.style.top = '-1000px'; + document.body.appendChild(ta); ta.select(); + let ok = false; + try { ok = document.execCommand('copy'); } catch {} + ta.remove(); + return ok; +} F().addEventListener('input', syncForm); F().addEventListener('change', syncForm); $('#btn-new-channel').onclick = () => openModal(null);