@wendongfly/myhi 1.3.190 → 1.3.191
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 +114 -20
- package/dist/chat.html +76 -60
- package/dist/index.html +134 -10
- package/dist/index.js +4 -4
- package/dist/index.min.js +9 -8
- package/dist/lib/machine.js +5 -2
- package/dist/lib/prefs.js +51 -0
- package/package.json +1 -1
package/dist/lib/machine.js
CHANGED
|
@@ -11,8 +11,11 @@
|
|
|
11
11
|
|
|
12
12
|
function fmt(t) {
|
|
13
13
|
if (sessionPage) {
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
// 会话页设的标题是「任务名 — myhi」,只留任务名(任务名本身叫 myhi 也照样显示 myhi);
|
|
15
|
+
// 还没加载出任务时是页面自带的「myhi 会话」,先显示机器名
|
|
16
|
+
const m = t.match(/^(.*?)\s*—\s*myhi$/);
|
|
17
|
+
if (m && m[1].trim()) return m[1].trim();
|
|
18
|
+
return /^myhi (会话|终端)$/.test(t) ? (name || 'myhi') : t; // 只认页面自带的占位标题,改写后的结果再进来保持不动
|
|
16
19
|
}
|
|
17
20
|
if (!name || t.startsWith(name + ' · ')) return t;
|
|
18
21
|
const rest = t.replace(/\s*—\s*myhi$/, '').replace(/^myhi\s*/, '').trim();
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
// 个人偏好跨设备同步:外观(主题/字号)、会话页的聊天显示与快捷栏。
|
|
2
|
+
// 各页面照旧读写 localStorage(myhi_theme / myhi_font / myhi_chat_settings),本脚本负责和服务端 /api/prefs 对齐:
|
|
3
|
+
// · 打开页面:服务端那份比本机新 → 写回 localStorage,有差异就刷新一次让页面按新设置渲染(每个标签页最多一次);
|
|
4
|
+
// 本机比服务端新(或服务端还没有)→ 推上去。
|
|
5
|
+
// · 页面改了设置后调 myhiPrefsPush()(防抖 800ms)推上去。
|
|
6
|
+
(function () {
|
|
7
|
+
const LS = { theme: 'myhi_theme', font: 'myhi_font', chat: 'myhi_chat_settings' };
|
|
8
|
+
const AT = 'myhi_prefs_at'; // 本机这份偏好对应的服务端时间戳
|
|
9
|
+
const get = (k) => { try { return localStorage.getItem(k); } catch { return null; } };
|
|
10
|
+
const set = (k, v) => { try { v == null ? localStorage.removeItem(k) : localStorage.setItem(k, v); } catch {} };
|
|
11
|
+
const dirty = () => get(AT + '_dirty') === '1';
|
|
12
|
+
|
|
13
|
+
function snapshot() {
|
|
14
|
+
let chat = null;
|
|
15
|
+
try { chat = JSON.parse(get(LS.chat) || 'null'); } catch {}
|
|
16
|
+
return { theme: get(LS.theme), font: get(LS.font), chat };
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
let timer = null;
|
|
20
|
+
window.myhiPrefsPush = function () {
|
|
21
|
+
set(AT + '_dirty', '1'); // 先记「本机有未推送的改动」,推失败/页面关了下次打开再推
|
|
22
|
+
clearTimeout(timer);
|
|
23
|
+
timer = setTimeout(async () => {
|
|
24
|
+
try {
|
|
25
|
+
const r = await fetch('/api/prefs', { method: 'PUT', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(snapshot()) });
|
|
26
|
+
const d = await r.json();
|
|
27
|
+
if (d.ok) { set(AT, String(d.updatedAt)); set(AT + '_dirty', null); }
|
|
28
|
+
} catch {}
|
|
29
|
+
}, 800);
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
fetch('/api/prefs').then((r) => (r.ok ? r.json() : null)).then((d) => {
|
|
33
|
+
if (!d?.ok) return;
|
|
34
|
+
const p = d.prefs;
|
|
35
|
+
const localAt = Number(get(AT) || 0);
|
|
36
|
+
if (!p || dirty() || (p.updatedAt || 0) <= localAt) {
|
|
37
|
+
// 服务端没有 / 本机有没推的改动 / 本机已是最新:本机为准(有值才推,空白新设备不推空值覆盖)
|
|
38
|
+
if ((!p || dirty()) && (get(LS.theme) || get(LS.font) || get(LS.chat))) window.myhiPrefsPush();
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
const before = JSON.stringify(snapshot());
|
|
42
|
+
if (p.theme !== undefined) set(LS.theme, p.theme);
|
|
43
|
+
if (p.font !== undefined) set(LS.font, p.font);
|
|
44
|
+
if (p.chat !== undefined) set(LS.chat, p.chat == null ? null : JSON.stringify(p.chat));
|
|
45
|
+
set(AT, String(p.updatedAt));
|
|
46
|
+
if (JSON.stringify(snapshot()) !== before) {
|
|
47
|
+
try { if (sessionStorage.getItem('myhi_prefs_reloaded')) return; sessionStorage.setItem('myhi_prefs_reloaded', '1'); } catch {}
|
|
48
|
+
location.reload();
|
|
49
|
+
}
|
|
50
|
+
}).catch(() => {});
|
|
51
|
+
})();
|
package/package.json
CHANGED