@wendongfly/myhi 1.3.175 → 1.3.180
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/admin.html +498 -497
- package/dist/chat.html +273 -4
- package/dist/grid.html +448 -447
- package/dist/index.html +88 -2
- package/dist/index.js +4 -4
- package/dist/index.min.js +138 -138
- package/dist/lib/machine.js +50 -0
- package/dist/terminal.html +1064 -1063
- package/package.json +1 -1
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
// 机器标识:多台电脑都跑 myhi 时,浏览器标签全叫「myhi」分不清。
|
|
2
|
+
// 拉 /api/machine-name → ① 标题里的「myhi」换成「机器名」并放最前(标签被挤窄时先露出来的是机器名)
|
|
3
|
+
// ② 标签图标换成按机器名哈希配色 + 首字的圆角方块,一眼认出是哪台。
|
|
4
|
+
// 页面后续自己改 document.title(如「会话名 — myhi」)也会被 MutationObserver 接住重写。
|
|
5
|
+
(function () {
|
|
6
|
+
let name = '';
|
|
7
|
+
try { name = localStorage.getItem('myhi_machine_name') || ''; } catch {} // 先用缓存,避免标题闪一下 myhi
|
|
8
|
+
|
|
9
|
+
function fmt(t) {
|
|
10
|
+
if (!name || t.startsWith(name + ' · ')) return t;
|
|
11
|
+
const rest = t.replace(/\s*—\s*myhi$/, '').replace(/^myhi\s*/, '').trim();
|
|
12
|
+
return rest ? `${name} · ${rest}` : `${name} · myhi`;
|
|
13
|
+
}
|
|
14
|
+
let busy = false;
|
|
15
|
+
function applyTitle() {
|
|
16
|
+
if (busy) return;
|
|
17
|
+
const t = fmt(document.title);
|
|
18
|
+
if (t !== document.title) { busy = true; document.title = t; busy = false; }
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function hue(s) { let h = 0; for (const c of s) h = (h * 31 + c.codePointAt(0)) >>> 0; return h % 360; }
|
|
22
|
+
function applyIcon() {
|
|
23
|
+
if (!name) return;
|
|
24
|
+
const ch = [...name][0].toUpperCase().replace(/[<&>"]/g, '');
|
|
25
|
+
const svg = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64"><rect width="64" height="64" rx="14" fill="hsl(${hue(name)},62%,46%)"/>` +
|
|
26
|
+
`<text x="32" y="45" font-size="38" font-family="sans-serif" font-weight="700" text-anchor="middle" fill="#fff">${ch}</text></svg>`;
|
|
27
|
+
let link = document.querySelector('link[rel="icon"]');
|
|
28
|
+
if (!link) { link = document.createElement('link'); link.rel = 'icon'; document.head.appendChild(link); }
|
|
29
|
+
link.type = 'image/svg+xml';
|
|
30
|
+
link.href = 'data:image/svg+xml,' + encodeURIComponent(svg);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function apply() { applyTitle(); applyIcon(); }
|
|
34
|
+
window.myhiSetMachineName = function (n) {
|
|
35
|
+
const old = name;
|
|
36
|
+
name = n || '';
|
|
37
|
+
try { localStorage.setItem('myhi_machine_name', name); } catch {}
|
|
38
|
+
// 已按旧名字改写过的标题,先剥掉旧前缀再按新名字重写
|
|
39
|
+
if (old && document.title.startsWith(old + ' · ')) { busy = true; document.title = document.title.slice(old.length + 3); busy = false; }
|
|
40
|
+
apply();
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', apply); else apply();
|
|
44
|
+
const titleEl = document.querySelector('title');
|
|
45
|
+
if (titleEl) new MutationObserver(applyTitle).observe(titleEl, { childList: true, characterData: true, subtree: true });
|
|
46
|
+
|
|
47
|
+
fetch('/api/machine-name').then(r => r.ok ? r.json() : null).then(d => {
|
|
48
|
+
if (d && d.name && d.name !== name) window.myhiSetMachineName(d.name);
|
|
49
|
+
}).catch(() => {});
|
|
50
|
+
})();
|