From d4f7b138c5a0b948805400229dbc7292a6a6ce20 Mon Sep 17 00:00:00 2001 From: mike Date: Thu, 12 Nov 2026 15:17:34 +0800 Subject: [PATCH] Update App.jsx via upload script - 2026-11-12 15:17:14 --- App.jsx | 112 ++++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 101 insertions(+), 11 deletions(-) diff --git a/App.jsx b/App.jsx index 3da0495..d744cd0 100644 --- a/App.jsx +++ b/App.jsx @@ -1851,6 +1851,15 @@ const Styles = () => ( .jms-spin { animation: jms-spin .8s linear infinite; } @keyframes jms-spin { to { transform: rotate(360deg); } } + .jms-links { display: flex; flex-direction: column; gap: 6px; } + .jms-link-row { display: flex; align-items: center; gap: 4px; } + .jms-link-name { width: 82px; flex-shrink: 0; font-size: 11.5px; color: var(--ink-soft); border: 1px solid transparent; border-radius: 6px; padding: 5px 6px; background: transparent; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; } + input.jms-link-name:hover, input.jms-link-name:focus { border-color: var(--line); background: var(--bg); outline: none; } + .jms-link-url { flex: 1; min-width: 0; font-family: 'IBM Plex Mono', monospace; font-size: 11.5px; border: 1px solid var(--line); border-radius: 6px; padding: 5px 8px; background: var(--bg); color: var(--ink); } + .jms-link-url:focus { outline: none; border-color: var(--ink-soft); background: var(--panel); } + .jms-link-btn { padding: 4px 6px; flex-shrink: 0; } + .jms-link-add { align-self: flex-start; display: inline-flex; align-items: center; gap: 4px; font-size: 11.5px; color: var(--ink-soft); background: none; border: 1px dashed var(--line); border-radius: 6px; padding: 4px 10px; cursor: pointer; } + .jms-link-add:hover { color: var(--ink); border-color: var(--ink-soft); } .jms-card-actions { display: flex; gap: 8px; flex-wrap: wrap; } .jms-card-actions .btn { flex: 1; justify-content: center; } @@ -6370,6 +6379,38 @@ function jmsBuildLink(line) { return ''; } +// 主链接:手动填写的优先,留空则按参数自动生成 +function jmsMainLink(line) { + return String(line.link || '').trim() || jmsBuildLink(line); +} + +// 卡片上可直接编辑的链接行:失焦或回车保存,Esc 取消 +function JmsLinkRow({ label, url, placeholder, onNameChange, onUrlChange, onCopy, onQr, onReset, onRemove }) { + const [u, setU] = useState(url || ''); + const [n, setN] = useState(label || ''); + useEffect(() => { setU(url || ''); }, [url]); + useEffect(() => { setN(label || ''); }, [label]); + const commitU = () => { if (u.trim() !== (url || '').trim()) onUrlChange(u.trim()); }; + const commitN = () => { if (onNameChange && n.trim() !== (label || '').trim()) onNameChange(n.trim()); }; + const keys = (commit, reset) => (e) => { + if (e.key === 'Enter') { e.preventDefault(); e.currentTarget.blur(); } + if (e.key === 'Escape') { reset(); setTimeout(() => e.target.blur(), 0); } + }; + return ( +
+ {onNameChange + ? setN(e.target.value)} onBlur={commitN} onKeyDown={keys(commitN, () => setN(label || ''))} /> + : {label}} + setU(e.target.value)} onBlur={commitU} onKeyDown={keys(commitU, () => setU(url || ''))} onFocus={e => e.target.select()} /> + + + {onReset && } + {onRemove && } +
+ ); +} + async function jmsResolveIp(domain) { const res = await fetch(`https://cloudflare-dns.com/dns-query?name=${encodeURIComponent(domain)}&type=A`, { headers: { Accept: 'application/dns-json' }, @@ -6386,11 +6427,16 @@ function jmsCopyText(text, label, onNotify) { .catch(() => onNotify && onNotify('复制失败,请手动选择')); } -function JmsLineCard({ line, idx, ip, dragIdx, onDragStart, onDropCard, onDragEnd, onRefreshIp, onCopy, onQr, onDuplicate, onEdit, onDelete, onNotify }) { +function JmsLineCard({ line, idx, ip, dragIdx, onDragStart, onDropCard, onDragEnd, onRefreshIp, onCopy, onQr, onDuplicate, onEdit, onDelete, onPatch, onNotify }) { const meta = JMS_PROTO_META[line.protocol] || { label: line.protocol }; const ipDisplay = ip === 'resolving' ? '解析中…' : (ip || '解析中…'); const hasPassword = line.protocol === 'ss' && !!line.password; const hasMethod = line.protocol === 'ss' && !!line.method; + const autoLink = line.addr && line.port ? jmsBuildLink(line) : ''; + const isCustom = !!String(line.link || '').trim(); + const extras = Array.isArray(line.extraLinks) ? line.extraLinks : []; + const setExtra = (i, patch) => onPatch({ extraLinks: extras.map((x, k) => (k === i ? { ...x, ...patch } : x)) }); + const copyUrl = (url) => jmsCopyText(url, '链接', onNotify); return (
)}
+
+ onPatch({ link: v === autoLink ? '' : v })} + onCopy={copyUrl} + onQr={(u) => onQr(line, u)} + onReset={isCustom && autoLink ? () => onPatch({ link: '' }) : null} + /> + {extras.map((x, i) => ( + setExtra(i, { name: v })} + onUrlChange={(v) => setExtra(i, { url: v })} + onCopy={copyUrl} + onQr={(u) => onQr(line, u, x.name)} + onRemove={() => onPatch({ extraLinks: extras.filter((_, k) => k !== i) })} + /> + ))} + +
@@ -6527,17 +6597,19 @@ function JmsPage({ lines, onSave, onDelete, onReorder, onNotify }) { }, [lines]); function copyLink(line) { - const link = jmsBuildLink(line); + const link = jmsMainLink(line); + if (!link) { onNotify('没有可复制的链接'); return; } navigator.clipboard.writeText(link).then(() => onNotify('订阅链接已复制')).catch(() => onNotify('复制失败,请手动选择')); } - async function openQr(line) { - setQrLine(line); + async function openQr(line, url, label) { + const link = url !== undefined ? url : jmsMainLink(line); + if (!link) { onNotify('链接为空,无法生成二维码'); return; } + setQrLine({ ...line, _qrUrl: link, _qrLabel: label }); setQrDataUrl(''); try { const mod = await import('qrcode'); const QRCode = mod.default || mod; - const link = jmsBuildLink(line); const dataUrl = await QRCode.toDataURL(link, { width: 220, margin: 1, color: { dark: '#18233A', light: '#ffffff' } }); setQrDataUrl(dataUrl); } catch (e) { @@ -6569,12 +6641,14 @@ function JmsPage({ lines, onSave, onDelete, onReorder, onNotify }) { function handleProtocolChange(p) { setProtocol(p); - setDraft(d => ({ name: d.name, addr: d.addr, port: d.port })); + setDraft(d => ({ name: d.name, addr: d.addr, port: d.port, link: d.link, extraLinks: d.extraLinks })); } function handleSave() { - if (!draft.addr || !draft.port) { onNotify('请填写服务器地址和端口'); return; } - onSave({ ...draft, protocol }, editingId); + const hasLink = String(draft.link || '').trim() || (draft.extraLinks || []).some(x => String(x.url || '').trim()); + if ((!draft.addr || !draft.port) && !hasLink) { onNotify('请填写服务器地址和端口,或直接填写订阅链接'); return; } + const extraLinks = (draft.extraLinks || []).map(x => ({ name: String(x.name || '').trim(), url: String(x.url || '').trim() })).filter(x => x.url || x.name); + onSave({ ...draft, link: String(draft.link || '').trim(), extraLinks, protocol }, editingId); closeModal(); } @@ -6612,6 +6686,7 @@ function JmsPage({ lines, onSave, onDelete, onReorder, onNotify }) { onDuplicate={duplicateLine} onEdit={openEditModal} onDelete={onDelete} + onPatch={(patch) => onSave({ ...line, ...patch }, line.id)} onNotify={onNotify} /> ))} @@ -6639,6 +6714,21 @@ function JmsPage({ lines, onSave, onDelete, onReorder, onNotify }) {
端口 setDraft(d => ({ ...d, port: e.target.value }))} placeholder="8388" />
+
+ 订阅链接(可选 · 留空则按上面参数自动生成) +