dsh-vt-web-chat 1.0.1 → 1.2.0
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 +112 -9
- 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.0
|
|
35
|
+
2. **npm**:`dsh plugin --profile <profile> add dsh-vt-web-chat@1.2.0`。
|
|
28
36
|
3. **Release tarball**:从 GitHub Release 下载 `.tgz`,再执行
|
|
29
37
|
`dsh plugin --profile <profile> add <该 .tgz 的本地路径或 URL>`。
|
|
30
38
|
|
package/client.js
CHANGED
|
@@ -21,19 +21,21 @@
|
|
|
21
21
|
* Leaving the panel releases the guest, so the page remembers the last
|
|
22
22
|
* conversation URL and reopens there instead of starting a new chat each time.
|
|
23
23
|
*/
|
|
24
|
-
/** Package identity: one source for the module id and every log/storage prefix. */
|
|
25
|
-
const PLUGIN_ID = 'dsh-vt-web-chat';
|
|
26
|
-
/** Must equal `version` in package.json; printed once in the mount trace below. */
|
|
27
|
-
const VERSION = '1.0.1';
|
|
28
|
-
|
|
29
|
-
// Mount trace: one line naming the loaded build (DevTools → verbose level).
|
|
30
|
-
console.debug(`[${PLUGIN_ID}] v${VERSION}`);
|
|
31
|
-
|
|
32
24
|
window.__ModuleLoader__.load({
|
|
33
|
-
id
|
|
25
|
+
// 模块 id 必须与包名一致;装载器把多个 client.js 拼进同一个脚本,所以顶层只能有
|
|
26
|
+
// 这一个 load() 调用,其余常量一律放进 factory 的作用域,避免重名 SyntaxError。
|
|
27
|
+
id: 'dsh-vt-web-chat',
|
|
34
28
|
factory(require) {
|
|
35
29
|
'use strict';
|
|
36
30
|
|
|
31
|
+
/** Package identity: one source for the module id and every log/storage prefix. */
|
|
32
|
+
const PLUGIN_ID = 'dsh-vt-web-chat';
|
|
33
|
+
/** Must equal `version` in package.json; printed once in the mount trace below. */
|
|
34
|
+
const VERSION = '1.2.0';
|
|
35
|
+
|
|
36
|
+
// Mount trace: one line naming the loaded build (DevTools → verbose level).
|
|
37
|
+
console.debug(`[${PLUGIN_ID}] v${VERSION}`);
|
|
38
|
+
|
|
37
39
|
const reactModule = require('react');
|
|
38
40
|
const React =
|
|
39
41
|
reactModule !== null && typeof reactModule.createElement === 'function'
|
|
@@ -53,6 +55,22 @@ window.__ModuleLoader__.load({
|
|
|
53
55
|
const PARTITION_KEY = 'panel:vt-web-chat';
|
|
54
56
|
/** Last visited conversation, remembered across panel switches and reloads. */
|
|
55
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;
|
|
56
74
|
/** Paths that are not a conversation: a brand-new chat, or an auth page. */
|
|
57
75
|
const AUTH_PATHS = new Set(['/sign_in', '/login', '/signup', '/auth']);
|
|
58
76
|
/** A guest that never reaches `dom-ready` is reported instead of hanging. */
|
|
@@ -184,6 +202,87 @@ window.__ModuleLoader__.load({
|
|
|
184
202
|
}
|
|
185
203
|
}
|
|
186
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
|
+
|
|
187
286
|
/**
|
|
188
287
|
* Open a chat URL in the system browser. The desktop shell routes
|
|
189
288
|
* `window.open` for http(s) to the OS browser and denies every other window.
|
|
@@ -523,6 +622,8 @@ window.__ModuleLoader__.load({
|
|
|
523
622
|
const raw = readUrl(element);
|
|
524
623
|
if (raw !== undefined) remember(raw);
|
|
525
624
|
restoring = false;
|
|
625
|
+
// Only a site document can carry the preferences; about:blank cannot.
|
|
626
|
+
if (parseChatUrl(raw) !== undefined) applyGuestPreferences(element);
|
|
526
627
|
try {
|
|
527
628
|
setPhase('ready');
|
|
528
629
|
setFailure(undefined);
|
|
@@ -539,6 +640,8 @@ window.__ModuleLoader__.load({
|
|
|
539
640
|
const onNavigateInPage = (event) => {
|
|
540
641
|
if (disposed || event?.isMainFrame !== true) return;
|
|
541
642
|
onNavigate();
|
|
643
|
+
// Signing in can be an in-page route change, which skips did-stop-loading.
|
|
644
|
+
applyGuestPreferences(element);
|
|
542
645
|
};
|
|
543
646
|
|
|
544
647
|
const onFailLoad = (event) => {
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-vt-web-chat",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.2.0",
|
|
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",
|