🔥 Sync 2026-11-16 16:50:07

This commit is contained in:
github-actions[bot] committed 2026-11-16 16:50:08 +08:00
1 parent 6b8b3fec62
commit a2bf4e439b
87 files changed
+2498 -180

No files matched your search

@@ -169,6 +169,7 @@ kbd{font:11px var(--sans);padding:1px 6px;border:1px solid var(--line);border-ra
.td-pop-box{width:min(560px,100%);max-height:70vh;display:flex;flex-direction:column;background:var(--surface);border:1px solid var(--line-soft);border-radius:18px;box-shadow:var(--shadow-pop);overflow:hidden;animation:td-rise var(--base) var(--ease)}
/* exits get their own keyframes: reusing td-fade/td-rise would not restart the finished entrance */
.td-pop.td-out,.td-toast.td-out{animation:td-out var(--fast) var(--ease) both}
.td-pop.td-out{pointer-events:none}
.td-out .td-pop-box{animation:td-sink var(--fast) var(--ease) both}
@keyframes td-out{to{opacity:0}}
@keyframes td-sink{to{opacity:0;transform:translateY(6px)}}
@@ -662,7 +663,7 @@ body.modal-overlay-active .modal{transform:none;transition-duration:var(--base)}
.td-node.bad .ic{background:var(--bad-soft);color:var(--bad)}
.td-node .ic svg{width:24px;height:24px}
.td-node b{font-weight:500;margin-top:10px;font-size:14px;max-width:100%;overflow-wrap:anywhere}
.td-node small{color:var(--ink-3);font-size:12.5px}
.td-node small{color:var(--ink-3);font-size:12.5px;max-width:100%;overflow-wrap:anywhere}
.td-link{flex:1 1 0;min-width:18px;display:flex;flex-direction:column;align-items:center;gap:6px;padding-top:clamp(6px,2.6cqi,12px)}
.td-link .t{font-size:12px;color:var(--ink-3);white-space:nowrap;overflow:hidden;text-overflow:ellipsis;max-width:100%;line-height:17px}
.td-link .ln{position:relative;width:100%;height:2px;background:repeating-linear-gradient(90deg,var(--line) 0 6px,transparent 6px 11px)}
@@ -671,7 +672,7 @@ body.modal-overlay-active .modal{transform:none;transition-duration:var(--base)}
.td-link.down .ln i{display:none}
.td-link.down .ln{background:repeating-linear-gradient(90deg,var(--bad) 0 6px,transparent 6px 11px);opacity:.6}
@keyframes td-flow{from{left:0;opacity:0}15%,85%{opacity:1}to{left:calc(100% - 8px);opacity:0}}
@container (max-width:430px){.td-link .t{visibility:hidden}.td-node small{display:none}}
@container (max-width:430px){.td-link .t{visibility:hidden}}
.td-facts{display:grid;grid-template-columns:repeat(auto-fit,minmax(110px,1fr));gap:14px 8px;margin:22px 0 0;padding-top:18px;border-top:1px solid var(--line-soft)}
.td-facts dt{font-size:12.5px;color:var(--ink-3);font-weight:400}
.td-facts dd{font-size:14.5px;margin:3px 0 0;overflow-wrap:anywhere;color:var(--ink)}
@@ -32,7 +32,7 @@ const callInfo = rpc.declare({ object: 'system', method: 'info' });
const callServices = rpc.declare({ object: 'service', method: 'list', expect: { '': {} } });
const callMounts = rpc.declare({ object: 'luci', method: 'getMountPoints', expect: { result: [] } });
const DEFAULTS = { palette: 'clay', mode: 'auto', hidden_cards: '', shown_cards: '' };
const DEFAULTS = { palette: 'clay', mode: 'auto', hidden_cards: '', shown_cards: '', rate_unit: 'bit' };
const OPT_IN = [ 'apps' ]; // cards that are off until switched on (they show plugin information)
const words = s => String(s || '').split(/[\s,]+/).filter(Boolean);
@@ -306,6 +306,12 @@ function motion(name) {
}
/* Exits mirror entrances: fade (and sink) out, then go. */
/* A toggle button's state, for the eye (class) and for screen readers (aria-pressed) alike. */
function press(el, on) {
el.classList.toggle('on', on);
el.setAttribute('aria-pressed', on);
}
function leave(el) {
if (el.classList.contains('td-out')) return;
el.classList.add('td-out');
@@ -338,7 +344,17 @@ function toast(msg) {
/* ---------------- formatting ---------------- */
function rate(bytesPerSec) {
/* Live speed as [ number, unit ]: bits per second like broadband plans (Mbps), or bytes per
* second like download tools (MB/s) when the user picked that. */
function rate(bytesPerSec, inBytes) {
if (inBytes) {
const n = Math.max(0, bytesPerSec);
if (n >= 1073741824) return [ (n / 1073741824).toFixed(2), 'GB/s' ];
if (n >= 1048576) return [ (n / 1048576).toFixed(n >= 104857600 ? 0 : 1), 'MB/s' ];
if (n >= 1024) return [ (n / 1024).toFixed(0), 'KB/s' ];
return [ n.toFixed(0), 'B/s' ];
}
const bits = Math.max(0, bytesPerSec * 8);
if (bits >= 1e9) return [ (bits / 1e9).toFixed(2), 'Gbps' ];
if (bits >= 1e6) return [ (bits / 1e6).toFixed(bits >= 1e8 ? 0 : 1), 'Mbps' ];
@@ -684,7 +700,7 @@ return baseclass.extend({
PALETTES: PALETTES, OPT_IN: OPT_IN, words: words, cardOn: cardOn,
esc: esc, icon: icon, html: html,
loadMenu: loadMenu, flatten: flatten, realNode: realNode, menuHas: menuHas, software: software, grouped: grouped, appIcon: appIcon, service: service,
loadSettings: loadSettings, saveSettings: saveSettings, applyLook: applyLook, toast: toast, motion: motion, leave: leave,
loadSettings: loadSettings, saveSettings: saveSettings, applyLook: applyLook, toast: toast, motion: motion, leave: leave, press: press,
rate: rate, bytes: bytes, duration: duration, signal: signal, quality: quality, bandName: bandName, connName: connName,
readFile: readFile, temperature: temperature, wifiInfo: wifiInfo, clients: clients, wan: wan, ports: ports, dnsName: dnsName, netdev: netdev, cpuStat: cpuStat,
board: () => L.resolveDefault(callBoard(), {}),
@@ -107,7 +107,7 @@ return baseclass.extend({
if (items.length < 2) return;
/* everyday pages first; the rest wait behind "More" unless one of them is open */
const pill = (p, cls) => `<a href="${L.url(p.path)}" class="${p === current ? 'on' : cls || ''}">${esc(p.title)}</a>`;
const pill = (p, cls) => `<a href="${L.url(p.path)}" ${p === current ? 'class="on" aria-current="page"' : `class="${cls || ''}"`}>${esc(p.title)}</a>`;
const rest = items.filter(p => g.pages.indexOf(p.path) < 0);
const fold = rest.length > 1 && rest.indexOf(current) < 0;
box.innerHTML = (fold ? items.filter(p => rest.indexOf(p) < 0) : items).map(p => pill(p)).join('')
@@ -171,9 +171,10 @@ return baseclass.extend({
openSearch() {
if (document.querySelector('.td-pop:not(.td-out)')) return;
const pop = td.html(`<div class="td-pop" role="dialog" aria-modal="true">
const from = document.activeElement;
const pop = td.html(`<div class="td-pop" role="dialog" aria-modal="true" aria-label="${esc(T('搜索', 'Search'))}">
<div class="td-pop-box">
<label class="td-pop-in">${icon('search')}<input type="search" placeholder="${esc(T('搜索功能或设置,例如“端口转发”', 'Search pages and settings'))}" autocomplete="off"><kbd>Esc</kbd></label>
<label class="td-pop-in">${icon('search')}<input type="search" aria-label="${esc(T('搜索功能或设置', 'Search pages and settings'))}" placeholder="${esc(T('搜索功能或设置,例如“端口转发”', 'Search pages and settings'))}" autocomplete="off"><kbd>Esc</kbd></label>
<div class="td-pop-list"></div>
</div></div>`);
document.body.appendChild(pop);
@@ -194,14 +195,15 @@ return baseclass.extend({
if (on) on.scrollIntoView({ block: 'nearest' });
};
const close = () => td.leave(pop);
/* closing hands the keyboard back to whatever opened the search */
const close = pop._close = () => { td.leave(pop); if (from && from.focus) from.focus() };
input.addEventListener('input', () => { sel = 0; draw() });
input.addEventListener('keydown', ev => {
if (ev.key == 'ArrowDown') { sel = Math.min(sel + 1, shown.length - 1); draw(); ev.preventDefault() }
else if (ev.key == 'ArrowUp') { sel = Math.max(sel - 1, 0); draw(); ev.preventDefault() }
else if (ev.key == 'Enter' && shown[sel]) { location.href = L.url(shown[sel].path) }
else if (ev.key == 'Escape') close();
else if (ev.key == 'Tab') ev.preventDefault(); // the arrows move through the results; Tab must not wander to the page behind
});
list.addEventListener('mousemove', ev => {
const a = ev.target.closest('a[data-i]');
@@ -220,9 +222,9 @@ return baseclass.extend({
const rest = (this.groups || []).filter(g => g.mob === false || g.id == 'system');
const body = rest.map(g => `<div class="grp">${esc(g.label)}</div>` +
g.list.map(p => `<a href="${L.url(p.path)}" class="${this.current === p ? 'on' : ''}">${icon(g.id == 'apps' ? td.appIcon(p.path) : g.icon)}<span>${esc(p.title)}</span></a>`).join('')).join('');
g.list.map(p => `<a href="${L.url(p.path)}"${this.current === p ? ' class="on" aria-current="page"' : ''}>${icon(g.id == 'apps' ? td.appIcon(p.path) : g.icon)}<span>${esc(p.title)}</span></a>`).join('')).join('');
const pop = td.html(`<div class="td-pop" role="dialog" aria-modal="true"><div class="td-pop-box">
const pop = td.html(`<div class="td-pop" role="dialog" aria-modal="true" aria-label="${esc(T('更多', 'More'))}"><div class="td-pop-box">
<div class="td-pop-list">${body}</div>
<div class="td-sheet-tools">
<button class="btn" type="button" data-act="search">${icon('search')}${esc(T('搜索', 'Search'))}</button>
@@ -249,6 +251,10 @@ return baseclass.extend({
const typing = /^(INPUT|TEXTAREA|SELECT)$/.test((ev.target || {}).tagName || '') || (ev.target || {}).isContentEditable;
if ((ev.key == 'k' || ev.key == 'K') && (ev.metaKey || ev.ctrlKey)) { ev.preventDefault(); this.openSearch() }
else if (ev.key == '/' && !typing && !document.body.classList.contains('modal-overlay-active')) { ev.preventDefault(); this.openSearch() }
else if (ev.key == 'Escape') { // closes the search or the phone sheet, whichever is open
const pop = document.querySelector('.td-pop:not(.td-out)');
if (pop) (pop._close || (() => td.leave(pop)))();
}
});
},
@@ -56,6 +56,8 @@ return view.extend({
<h3 class="td-sect-t">${esc(T('首页卡片', 'Home cards'))}</h3>
<p class="td-sect-d">${esc(T('“网络连接”卡片始终显示。', 'The Connection card is always shown.'))}</p>
<div class="td-rows">${cards}</div>
<div class="td-row"><div class="lb"><b>${esc(T('速率单位', 'Speed unit'))}</b></div>
<div class="td-seg" id="td-units"><button type="button" data-m="bit">Mbps</button><button type="button" data-m="byte">MB/s</button></div></div>
</section>
<div class="td-hint">${icon('info')}<span>${esc(T('换回原主题:系统 → 通用 → 语言和界面', 'Switch back: System → General → Language and Style'))}</span></div>
@@ -65,6 +67,7 @@ return view.extend({
root.querySelectorAll('[data-pick]').forEach(b => b.addEventListener('click', () => this.update({ palette: b.dataset.pick })));
root.querySelectorAll('#td-modes button').forEach(b => b.addEventListener('click', () => this.update({ mode: b.dataset.m })));
root.querySelectorAll('#td-units button').forEach(b => b.addEventListener('click', () => this.update({ rate_unit: b.dataset.m })));
root.querySelectorAll('[data-card]').forEach(b => b.addEventListener('click', () => {
const k = b.dataset.card, field = td.OPT_IN.indexOf(k) > -1 ? 'shown_cards' : 'hidden_cards';
const list = td.words(this.conf[field]), i = list.indexOf(k);
@@ -85,9 +88,10 @@ return view.extend({
sync() {
const c = this.conf;
this.root.querySelectorAll('.td-pal').forEach(b => b.classList.toggle('on', b.dataset.pick == c.palette));
this.root.querySelectorAll('#td-modes button').forEach(b => b.classList.toggle('on', b.dataset.m == c.mode));
this.root.querySelectorAll('[data-card]').forEach(b => b.classList.toggle('on', td.cardOn(c, b.dataset.card)));
this.root.querySelectorAll('.td-pal').forEach(b => td.press(b, b.dataset.pick == c.palette));
this.root.querySelectorAll('#td-modes button').forEach(b => td.press(b, b.dataset.m == c.mode));
this.root.querySelectorAll('#td-units button').forEach(b => td.press(b, b.dataset.m == c.rate_unit));
this.root.querySelectorAll('[data-card]').forEach(b => td.press(b, td.cardOn(c, b.dataset.card)));
},
update(patch) {
@@ -81,6 +81,7 @@ return view.extend({
const software = td.software(menu);
this.s = {
inBytes: conf.rate_unit == 'byte',
down: new Array(N).fill(0), up: new Array(N).fill(0),
last: null, cpu: td.cpuStat(stat), cpuPct: null, wan: wan, wifi: wifi || { radios: {}, aps: [] }, info: info, board: board,
clients: [], ping: null, apps: apps, hasWifi: !!(wifi && Object.keys(wifi.radios).length), mode: mode
@@ -269,6 +270,8 @@ return view.extend({
if (!ok) {
this.set('td-proto', T('没有连接', 'Not connected'));
[ 'td-wanip', 'td-dns', 'td-wanup', 'td-ping' ].forEach(id => this.set(id, '—')); // not the last connection's values
this.set('td-lat', T('未连接', 'Offline'));
return;
}
@@ -402,7 +405,7 @@ return view.extend({
const rx = Math.max(0, (d.rx - this.s.last.rx) / dt), tx = Math.max(0, (d.tx - this.s.last.tx) / dt);
this.s.down.push(rx); this.s.down.shift();
this.s.up.push(tx); this.s.up.shift();
const [ dv, du ] = td.rate(rx), [ uv, uu ] = td.rate(tx);
const [ dv, du ] = td.rate(rx, this.s.inBytes), [ uv, uu ] = td.rate(tx, this.s.inBytes);
this.set('td-down', dv); this.set('td-down-u', du);
this.set('td-up', uv); this.set('td-up-u', uu);
this.drawChart();
@@ -493,13 +496,14 @@ return view.extend({
pingGateway() {
const w = this.s.wan;
if (!w || !w.gw || !/^[0-9.]+$/.test(w.gw)) {
if (!w || !w.up || !w.gw || !/^[0-9.]+$/.test(w.gw)) {
this.set('td-lat', w && w.up ? T('已连接', 'Connected') : T('未连接', 'Offline'));
return Promise.resolve();
}
/* a gateway that never answers ping (many ISP modems) is retried every few minutes, not every 30 s */
if (this.s.miss >= 3 && this.ticks % 18) return Promise.resolve();
return L.resolveDefault(fs.exec('/bin/ping', [ '-c', '1', '-W', '1', w.gw ]), {}).then(r => {
if (!this.s.wan || !this.s.wan.up || this.s.wan.gw != w.gw) return; // the connection changed while we waited
const m = String((r || {}).stdout || '').match(/time[=<]([\d.]+)/);
const v = m ? (+m[1] < 1 ? '<1' : Math.round(+m[1])) + ' ms' : null;
this.s.miss = v ? 0 : (this.s.miss || 0) + 1;
@@ -537,7 +541,7 @@ return view.extend({
/* OpenClash's proxy mode, switched through its own switch_rule_mode call */
ocSwitch(seg) {
let mode = seg.dataset.oc;
const mark = m => seg.querySelectorAll('button').forEach(b => b.classList.toggle('on', b.dataset.m == m));
const mark = m => seg.querySelectorAll('button').forEach(b => td.press(b, b.dataset.m == m));
mark(mode);
seg.addEventListener('click', ev => {
const b = ev.target.closest('button[data-m]');