dsh-vt-web-chat 1.0.2 → 1.2.1
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/README.md +10 -2
- package/client.js +109 -4
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,13 +1,21 @@
|
|
|
1
1
|
# dsh-vt-web-chat · 网页对话
|
|
2
2
|
|
|
3
3
|
在 DSH 桌面版的「新会话」正下方加一行「网页对话」入口,点开后在主内容区整页显示
|
|
4
|
-
`chat.deepseek.com
|
|
4
|
+
`chat.deepseek.com`,用官网自己的对话历史,记住上次停留的对话,默认收起网页自己的
|
|
5
|
+
会话侧边栏,并关掉站点的「使用环境异常」提示。
|
|
5
6
|
|
|
6
7
|
## 它改了什么
|
|
7
8
|
|
|
8
9
|
- 侧栏「新会话」下面多一行「网页对话」,点击后在主内容区打开整页网页对话;
|
|
9
10
|
- 载体是桌面壳的 guest 租约桥(Electron `<webview>`)。官网返回
|
|
10
11
|
`frame-ancestors 'none'`,普通 iframe 无法承载,租约是主进程唯一放行的建法;
|
|
12
|
+
- 进入面板时把网页自己的会话侧边栏收起:改写站点存在 localStorage 里的
|
|
13
|
+
`siderCollapsed` 记录并重载一次,不依赖站点按钮的 DOM;每次进面板都会回到收起状态,
|
|
14
|
+
你在本次停留里手动展开不会被覆盖;
|
|
15
|
+
- 进入面板时关掉站点的「使用环境异常」提示:写站点自己的 `closeUnsafeEnvWarn` 记录,
|
|
16
|
+
等同于点一次弹窗上的 X。**不改 UA、不伪装运行环境**,因此站点仍然知道自己在 Electron
|
|
17
|
+
里运行,只把这条提示的“别再显示”提前替你勾上;
|
|
18
|
+
- 两条记录都在同一次重载里生效,guest 侧有重载次数上限,写失败也不会死循环;
|
|
11
19
|
- 离开面板会释放 guest,回来时按本机记录的上次对话地址恢复;
|
|
12
20
|
- 纯 Web 环境(没有桌面桥)显示说明卡,并可「在浏览器打开」;
|
|
13
21
|
- 入口文案与面板文案随宿主语言切换(zh / en)。
|
|
@@ -24,7 +32,7 @@
|
|
|
24
32
|
|
|
25
33
|
1. **插件市场(推荐)**:在「插件 → 发现 → 添加索引源」里填入
|
|
26
34
|
`https://vontean.github.io/vt-dsh-plugin/index.json`,找到「网页对话」点安装。
|
|
27
|
-
2. **npm**:`dsh plugin --profile <profile> add dsh-vt-web-chat@1.
|
|
35
|
+
2. **npm**:`dsh plugin --profile <profile> add dsh-vt-web-chat@1.2.1`。
|
|
28
36
|
3. **Release tarball**:从 GitHub Release 下载 `.tgz`,再执行
|
|
29
37
|
`dsh plugin --profile <profile> add <该 .tgz 的本地路径或 URL>`。
|
|
30
38
|
|
package/client.js
CHANGED
|
@@ -31,7 +31,7 @@ window.__ModuleLoader__.load({
|
|
|
31
31
|
/** Package identity: one source for the module id and every log/storage prefix. */
|
|
32
32
|
const PLUGIN_ID = 'dsh-vt-web-chat';
|
|
33
33
|
/** Must equal `version` in package.json; printed once in the mount trace below. */
|
|
34
|
-
const VERSION = '1.
|
|
34
|
+
const VERSION = '1.2.1';
|
|
35
35
|
|
|
36
36
|
// Mount trace: one line naming the loaded build (DevTools → verbose level).
|
|
37
37
|
console.debug(`[${PLUGIN_ID}] v${VERSION}`);
|
|
@@ -55,6 +55,22 @@ window.__ModuleLoader__.load({
|
|
|
55
55
|
const PARTITION_KEY = 'panel:vt-web-chat';
|
|
56
56
|
/** Last visited conversation, remembered across panel switches and reloads. */
|
|
57
57
|
const STORAGE_KEY = `${PLUGIN_ID}:last-url`;
|
|
58
|
+
/**
|
|
59
|
+
* Record the site keeps its own UI preferences in. It is written by the
|
|
60
|
+
* site's storage kit, so a hand-written value must keep the same envelope
|
|
61
|
+
* (`{ value, __version }`) or the site discards it.
|
|
62
|
+
*/
|
|
63
|
+
const SITE_PREFS_KEY = '__appKit_@deepseek/chat_lastSessionValue';
|
|
64
|
+
/**
|
|
65
|
+
* The site's own "environment warning dismissed" flag. The warning is shown
|
|
66
|
+
* because the embedded browser reports Electron; closing it writes this
|
|
67
|
+
* flag, so writing it here is the same dismissal without a click.
|
|
68
|
+
*/
|
|
69
|
+
const UNSAFE_WARN_KEY = 'closeUnsafeEnvWarn';
|
|
70
|
+
/** Guest-side reload counter, so a failed write cannot reload forever. */
|
|
71
|
+
const PREF_GUARD_KEY = `${PLUGIN_ID}:pref-reloads`;
|
|
72
|
+
/** Reloads one guest session may perform while it settles its preferences. */
|
|
73
|
+
const PREF_RELOAD_LIMIT = 2;
|
|
58
74
|
/** Paths that are not a conversation: a brand-new chat, or an auth page. */
|
|
59
75
|
const AUTH_PATHS = new Set(['/sign_in', '/login', '/signup', '/auth']);
|
|
60
76
|
/** A guest that never reaches `dom-ready` is reported instead of hanging. */
|
|
@@ -70,7 +86,7 @@ window.__ModuleLoader__.load({
|
|
|
70
86
|
crashed: '内嵌页面已退出',
|
|
71
87
|
retry: '重试',
|
|
72
88
|
unsupportedTitle: '需要桌面版 App',
|
|
73
|
-
unsupportedBody: '
|
|
89
|
+
unsupportedBody: '网页对话依赖桌面端的内嵌浏览器(桥接协议 v1)。当前环境要么不是桌面版,要么桌面壳的协议版本与插件不一致。请在浏览器新标签中打开,或把 DSH 升级到与插件匹配的版本。',
|
|
74
90
|
openExternal: '在浏览器打开',
|
|
75
91
|
signInHint: '登录状态只在本次运行中保留;重启 DSH 后需要重新登录。',
|
|
76
92
|
signInAction: '在系统浏览器登录',
|
|
@@ -85,7 +101,7 @@ window.__ModuleLoader__.load({
|
|
|
85
101
|
retry: 'Retry',
|
|
86
102
|
unsupportedTitle: 'Desktop app required',
|
|
87
103
|
unsupportedBody:
|
|
88
|
-
'Web Chat
|
|
104
|
+
'Web Chat needs the desktop embedded browser (bridge protocol v1). This environment is either not the desktop app, or its shell speaks a different protocol version. Open it in a browser tab instead, or update DSH to match this plugin.',
|
|
89
105
|
openExternal: 'Open in browser',
|
|
90
106
|
signInHint:
|
|
91
107
|
'Your sign-in lasts only for this app run; restarting DSH requires signing in again.',
|
|
@@ -186,6 +202,87 @@ window.__ModuleLoader__.load({
|
|
|
186
202
|
}
|
|
187
203
|
}
|
|
188
204
|
|
|
205
|
+
/**
|
|
206
|
+
* Script that settles the site's own preferences before the panel is used.
|
|
207
|
+
*
|
|
208
|
+
* Two records carry the state, and the site reads both once at boot: the
|
|
209
|
+
* environment-warning dismissal and the sidebar state. Writing them without
|
|
210
|
+
* a reload has no effect, so the script writes only what differs and
|
|
211
|
+
* reloads once. A guest sessionStorage counter caps the reloads, so a site
|
|
212
|
+
* that refuses the write cannot loop. Without a sign-in token there is no
|
|
213
|
+
* sidebar yet, so only the warning is handled on the auth page.
|
|
214
|
+
* @returns the script text, safe to hand to `executeJavaScript`.
|
|
215
|
+
*/
|
|
216
|
+
function guestPreferencesScript() {
|
|
217
|
+
return `(() => {
|
|
218
|
+
try {
|
|
219
|
+
const reloads = Number(sessionStorage.getItem('${PREF_GUARD_KEY}') || '0');
|
|
220
|
+
if (reloads >= ${PREF_RELOAD_LIMIT}) return 'settled';
|
|
221
|
+
const read = (key) => {
|
|
222
|
+
try {
|
|
223
|
+
const raw = localStorage.getItem(key);
|
|
224
|
+
if (raw === null) return null;
|
|
225
|
+
const parsed = JSON.parse(raw);
|
|
226
|
+
return parsed !== null && typeof parsed === 'object' ? parsed : null;
|
|
227
|
+
} catch (error) {
|
|
228
|
+
return null;
|
|
229
|
+
}
|
|
230
|
+
};
|
|
231
|
+
const write = (key, value) => {
|
|
232
|
+
const record = read(key) || {};
|
|
233
|
+
record.value = value;
|
|
234
|
+
if (typeof record.__version !== 'string') record.__version = '0';
|
|
235
|
+
localStorage.setItem(key, JSON.stringify(record));
|
|
236
|
+
};
|
|
237
|
+
let reload = false;
|
|
238
|
+
const warning = read('${UNSAFE_WARN_KEY}');
|
|
239
|
+
if (warning === null || warning.value !== true) {
|
|
240
|
+
write('${UNSAFE_WARN_KEY}', true);
|
|
241
|
+
reload = true;
|
|
242
|
+
}
|
|
243
|
+
const token = read('userToken');
|
|
244
|
+
if (token !== null && token.value !== null && token.value !== undefined) {
|
|
245
|
+
const prefs = read('${SITE_PREFS_KEY}');
|
|
246
|
+
const value = prefs !== null && prefs.value !== null && typeof prefs.value === 'object' ? prefs.value : {};
|
|
247
|
+
if (value.siderCollapsed !== true) {
|
|
248
|
+
const next = prefs === null ? {} : prefs;
|
|
249
|
+
next.value = Object.assign({}, value, { siderCollapsed: true });
|
|
250
|
+
if (typeof next.__version !== 'string') next.__version = '0';
|
|
251
|
+
localStorage.setItem('${SITE_PREFS_KEY}', JSON.stringify(next));
|
|
252
|
+
reload = true;
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
if (!reload) return 'ready';
|
|
256
|
+
sessionStorage.setItem('${PREF_GUARD_KEY}', String(reloads + 1));
|
|
257
|
+
location.reload();
|
|
258
|
+
return 'reloading';
|
|
259
|
+
} catch (error) {
|
|
260
|
+
return 'unavailable';
|
|
261
|
+
}
|
|
262
|
+
})()`;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
/**
|
|
266
|
+
* Apply the guest preferences to a live guest.
|
|
267
|
+
*
|
|
268
|
+
* The changes go through the site's own records rather than its DOM, so a
|
|
269
|
+
* site redesign cannot break them into wrong clicks. Every failure stays
|
|
270
|
+
* inside this panel: a guest that refuses the script keeps its own layout
|
|
271
|
+
* and its own warning.
|
|
272
|
+
* @param element - webview element hosting the site.
|
|
273
|
+
*/
|
|
274
|
+
function applyGuestPreferences(element) {
|
|
275
|
+
if (!attached(element)) return;
|
|
276
|
+
try {
|
|
277
|
+
const pending = element.executeJavaScript(guestPreferencesScript(), false);
|
|
278
|
+
if (pending !== undefined && pending !== null && typeof pending.catch === 'function') {
|
|
279
|
+
pending.catch(() => {});
|
|
280
|
+
}
|
|
281
|
+
} catch {
|
|
282
|
+
/* scripting disabled for this guest: keep the site's own behaviour */
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
|
|
189
286
|
/**
|
|
190
287
|
* Open a chat URL in the system browser. The desktop shell routes
|
|
191
288
|
* `window.open` for http(s) to the OS browser and denies every other window.
|
|
@@ -456,7 +553,11 @@ window.__ModuleLoader__.load({
|
|
|
456
553
|
|
|
457
554
|
React.useEffect(() => {
|
|
458
555
|
const host = hostRef.current;
|
|
459
|
-
|
|
556
|
+
// 桌面壳用 protocolVersion 声明这套桥接契约的版本。内置侧边栏浏览器也做同样的
|
|
557
|
+
// 判断(dsh-client-ui-sidebar-browser 的 carrier?.protocolVersion === 1)。不校验的话,
|
|
558
|
+
// 一旦壳升版,这里会拿到形状不对的对象,表现为「打不开、重试」而看不出原因。
|
|
559
|
+
const carrier = globalThis.dshDesktop;
|
|
560
|
+
const bridge = carrier?.protocolVersion === 1 ? carrier.browser : undefined;
|
|
460
561
|
if (host === null) return undefined;
|
|
461
562
|
if (bridge === undefined) {
|
|
462
563
|
try {
|
|
@@ -525,6 +626,8 @@ window.__ModuleLoader__.load({
|
|
|
525
626
|
const raw = readUrl(element);
|
|
526
627
|
if (raw !== undefined) remember(raw);
|
|
527
628
|
restoring = false;
|
|
629
|
+
// Only a site document can carry the preferences; about:blank cannot.
|
|
630
|
+
if (parseChatUrl(raw) !== undefined) applyGuestPreferences(element);
|
|
528
631
|
try {
|
|
529
632
|
setPhase('ready');
|
|
530
633
|
setFailure(undefined);
|
|
@@ -541,6 +644,8 @@ window.__ModuleLoader__.load({
|
|
|
541
644
|
const onNavigateInPage = (event) => {
|
|
542
645
|
if (disposed || event?.isMainFrame !== true) return;
|
|
543
646
|
onNavigate();
|
|
647
|
+
// Signing in can be an in-page route change, which skips did-stop-loading.
|
|
648
|
+
applyGuestPreferences(element);
|
|
544
649
|
};
|
|
545
650
|
|
|
546
651
|
const onFailLoad = (event) => {
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-vt-web-chat",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.1",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"description": "Adds a Web Chat entry under New Session that opens chat.deepseek.com as a full main-area panel in the desktop embedded browser
|
|
5
|
+
"description": "Adds a Web Chat entry under New Session that opens chat.deepseek.com as a full main-area panel in the desktop embedded browser, remembers the last conversation, starts with the site sidebar collapsed and keeps the site's environment warning dismissed.",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"author": "Vontean",
|
|
8
8
|
"homepage": "https://github.com/Vontean/vt-dsh-plugin/tree/main/plugins/vt-web-chat#readme",
|