Files
katelyatv/src/components/TvboxButton.tsx
T
3970260761 7d698273d0
Docker Build & Test / build (push) Canceled after 0s
Docker Build & Test / test (push) Canceled after 0s
Build & Push Docker image / build-and-push (linux/amd64) (push) Canceled after 0s
Build & Push Docker image / build-and-push (linux/arm/v7) (push) Canceled after 0s
Build & Push Docker image / build-and-push (linux/arm64) (push) Canceled after 0s
Build & Push Docker image / merge-images (push) Canceled after 0s
Release / release (push) Canceled after 0s
Release / docker (push) Canceled after 0s
fixed75: TVBOX按钮弹双地址(配置地址+直播源地址各带复制)
2026-11-08 00:59:44 +08:00

143 lines
5.5 KiB
TypeScript

'use client';
import { useState } from 'react';
export default function TvboxButton({ forceShow = false, compact = false }: { forceShow?: boolean; compact?: boolean }) {
const [label, setLabel] = useState('📺 TVBOX接口');
const copyText = (t: string, btn?: HTMLButtonElement) => {
try {
if (navigator.clipboard && navigator.clipboard.writeText) {
navigator.clipboard.writeText(t).then(() => {
if (btn) { btn.textContent = '✓ 已复制'; setTimeout(() => (btn.textContent = '复制'), 1600); }
}).catch(() => {});
return;
}
} catch {}
const ta = document.createElement('textarea');
ta.value = t;
document.body.appendChild(ta);
ta.select();
try { document.execCommand('copy'); } catch {}
document.body.removeChild(ta);
if (btn) { btn.textContent = '✓ 已复制'; setTimeout(() => (btn.textContent = '复制'), 1600); }
};
const showTvboxModal = (cfg: string, live: string) => {
const ov = document.createElement('div');
ov.className =
'fixed inset-0 z-[9999] flex items-center justify-center bg-black/50 p-4';
(ov.style as any).backdropFilter = 'blur(4px)';
const card = document.createElement('div');
card.className =
'bg-white dark:bg-gray-800 rounded-2xl shadow-2xl max-w-md w-full max-h-[80vh] flex flex-col overflow-hidden';
const head = document.createElement('div');
head.className = 'flex items-center justify-between px-6 pt-5 pb-3';
const h3 = document.createElement('h3');
h3.className =
'text-base font-bold text-gray-900 dark:text-gray-100 truncate mr-2';
h3.textContent = '📺 TVBOX 接入';
const xb = document.createElement('button');
xb.className =
'text-gray-400 hover:text-gray-600 dark:hover:text-gray-200 text-lg leading-none flex-shrink-0';
xb.textContent = '✕';
head.appendChild(h3);
head.appendChild(xb);
const bd = document.createElement('div');
bd.className =
'px-6 pb-4 overflow-y-auto text-sm text-gray-700 dark:text-gray-300';
const mkRow = (label: string, url: string) => {
const wrap = document.createElement('div');
wrap.style.marginBottom = '14px';
const lb = document.createElement('div');
lb.style.fontWeight = '700';
lb.style.marginBottom = '6px';
lb.textContent = label;
const urlDiv = document.createElement('div');
urlDiv.style.wordBreak = 'break-all';
urlDiv.style.background = 'rgba(127,127,127,.12)';
urlDiv.style.borderRadius = '8px';
urlDiv.style.padding = '8px 10px';
urlDiv.style.fontSize = '12px';
urlDiv.textContent = url;
const row = document.createElement('div');
row.style.display = 'flex';
row.style.gap = '8px';
row.style.marginTop = '8px';
const cp = document.createElement('button');
cp.textContent = '复制';
cp.className =
'px-3 py-1.5 rounded-lg text-xs font-medium text-white bg-purple-600 hover:bg-purple-700';
cp.onclick = () => copyText(url, cp);
const op = document.createElement('a');
op.href = url;
op.target = '_blank';
op.rel = 'noopener';
op.textContent = '打开 →';
op.className =
'px-3 py-1.5 rounded-lg text-xs font-medium text-purple-600 dark:text-purple-400 hover:bg-purple-500/10';
row.appendChild(cp);
row.appendChild(op);
wrap.appendChild(lb);
wrap.appendChild(urlDiv);
wrap.appendChild(row);
return wrap;
};
bd.appendChild(mkRow('配置地址(含直播,推荐)', cfg));
bd.appendChild(mkRow('直播源地址(仅直播)', live));
const tip = document.createElement('div');
tip.style.fontSize = '12px';
tip.style.opacity = '0.75';
tip.textContent = '影视仓/TVBox「设置 → 配置地址」粘贴保存即可';
bd.appendChild(tip);
card.appendChild(head);
card.appendChild(bd);
const foot = document.createElement('div');
foot.className =
'px-6 py-4 bg-gray-50 dark:bg-gray-700/50 flex items-center justify-end gap-2';
const kb = document.createElement('button');
kb.className =
'px-3 py-1.5 rounded-lg text-xs font-medium text-gray-500 dark:text-gray-400 hover:bg-gray-100 dark:hover:bg-gray-600';
kb.textContent = '我知道了';
foot.appendChild(kb);
card.appendChild(foot);
const close = () => {
if (ov && ov.parentNode) ov.parentNode.removeChild(ov);
};
xb.onclick = close;
kb.onclick = close;
ov.onclick = (ev) => {
if (ev.target === ov) close();
};
ov.appendChild(card);
document.body.appendChild(ov);
};
const onClick = (ev: React.MouseEvent<HTMLButtonElement>) => {
const cfg = location.origin + '/api/tvbox';
const live = location.origin + '/api/tvbox?live=txt';
const bt = ev.currentTarget;
const ok = () => {
setLabel('✓ 已复制');
setTimeout(() => setLabel('📺 TVBOX接口'), 1600);
};
void bt;
void ok;
showTvboxModal(cfg, live);
};
return (
<button
onClick={onClick}
title='TVBOX接口 · 点击复制配置地址'
className={
forceShow
? 'flex shrink-0 items-center rounded-lg px-2 py-1.5 text-xs font-medium text-gray-200 hover:bg-white/10 hover:text-white transition-colors duration-200'
: 'hidden md:flex shrink-0 items-center rounded-lg px-3 py-2 text-sm font-medium text-gray-700 hover:bg-purple-100/30 hover:text-purple-600 dark:text-gray-300 dark:hover:bg-purple-500/10 transition-colors duration-200'
}
>
{compact && label === '📺 TVBOX接口' ? '📺 TVBOX' : label}
</button>
);
}