OrbiSubs panel: make the copy button work over plain http (clipboard API needs a secure context)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
guy
2026-11-21 23:08:56 -03:00
parent 40789c196d
commit 47e51897b1
+21 -1
View File
@@ -364,8 +364,28 @@ function urlLine(label, url) {
document.addEventListener('click', e => { document.addEventListener('click', e => {
const b = e.target.closest('.out-copy'); const b = e.target.closest('.out-copy');
if (!b) return; 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('input', syncForm);
F().addEventListener('change', syncForm); F().addEventListener('change', syncForm);
$('#btn-new-channel').onclick = () => openModal(null); $('#btn-new-channel').onclick = () => openModal(null);