dsh-ustc-quota 1.1.25 → 1.1.27
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 +4 -3
- package/client.js +86 -36
- package/index.js +41 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -107,9 +107,10 @@ key-c 8.7/30 29% 8.7/70 12% 11.1/100 11%
|
|
|
107
107
|
|
|
108
108
|
## 面板位置
|
|
109
109
|
|
|
110
|
-
-
|
|
111
|
-
-
|
|
112
|
-
-
|
|
110
|
+
- 卡片默认在左侧边栏底部。**鼠标移到卡片上时,标题左边的品牌图标会变成方向图标**(布局图示,标出卡片将要去的那一侧),点一下即可换边;移开鼠标图标复原。选择会记住,重启后保持。
|
|
111
|
+
- 右侧位置会在对话区右侧**预留一条槽**:插件给对话列加右侧内边距,正文与轮次导航条整体左移,卡片占住这条槽——因此不遮挡正文、不遮挡轮次导航条、也不遮挡右侧原生按钮。上沿从「对话 / 轨迹 / 看板」选项卡下的分隔线以下 6px 开始。
|
|
112
|
+
- 窄窗口或打开侧栏时槽宽自动收窄(下限 140px),卡片始终可见;如果连正文最小宽度都不够,则允许卡片比常规更窄,而不是消失。
|
|
113
|
+
- 换边不重新加载:两处卡片共用同一份已取到的数据。底色用左侧边栏的底色(`--dsw-specific-sidebar-fill`),阴影与左侧一致。
|
|
113
114
|
## 更新
|
|
114
115
|
|
|
115
116
|
- 标题「USTC 词元额度」右侧显示灰色小字版本号;点击版本号可手动检查更新;
|
package/client.js
CHANGED
|
@@ -11,7 +11,7 @@ window.__ModuleLoader__.load({
|
|
|
11
11
|
const UPDATE_ENDPOINT = 'plugins/dsh-ustc-quota/update';
|
|
12
12
|
const UPDATE_APPLY_ENDPOINT = 'plugins/dsh-ustc-quota/update/apply';
|
|
13
13
|
const WINDOW_IDS = ['3h', '12h', '24h'];
|
|
14
|
-
const CLIENT_VERSION = '1.1.
|
|
14
|
+
const CLIENT_VERSION = '1.1.27';
|
|
15
15
|
const UPDATE_INTERVAL_MS = 24 * 60 * 60 * 1000;
|
|
16
16
|
const CLIENT_VERSION_KEY = `${NS}:client-version`;
|
|
17
17
|
const CLIENT_RELOAD_KEY = `${NS}:client-reload`;
|
|
@@ -1135,43 +1135,45 @@ window.__ModuleLoader__.load({
|
|
|
1135
1135
|
// between the chat content and the turn navigator, so it follows the
|
|
1136
1136
|
// conversation when either side is dragged or toggled.
|
|
1137
1137
|
const DOCK_GAP = 6;
|
|
1138
|
-
const DOCK_MIN_WIDTH =
|
|
1139
|
-
const DOCK_MAX_WIDTH =
|
|
1138
|
+
const DOCK_MIN_WIDTH = 200;
|
|
1139
|
+
const DOCK_MAX_WIDTH = 340;
|
|
1140
|
+
const DOCK_FLOOR_WIDTH = 140;
|
|
1141
|
+
const DOCK_TRANSCRIPT_FLOOR = 360;
|
|
1140
1142
|
|
|
1143
|
+
|
|
1144
|
+
let lastDiagAt = 0;
|
|
1145
|
+
function reportDiag(payload) {
|
|
1146
|
+
const now = Date.now();
|
|
1147
|
+
if (now - lastDiagAt < 4000) return;
|
|
1148
|
+
lastDiagAt = now;
|
|
1149
|
+
try {
|
|
1150
|
+
fetch('/plugins/dsh-ustc-quota/diag', {
|
|
1151
|
+
method: 'POST',
|
|
1152
|
+
cache: 'no-store',
|
|
1153
|
+
headers: { 'content-type': 'application/json' },
|
|
1154
|
+
body: JSON.stringify(payload),
|
|
1155
|
+
}).catch(() => {});
|
|
1156
|
+
} catch {
|
|
1157
|
+
// diagnostics are best-effort
|
|
1158
|
+
}
|
|
1159
|
+
}
|
|
1141
1160
|
function measureRightDock() {
|
|
1142
1161
|
const holder = document.querySelector('[data-slot="main.conversation"]');
|
|
1143
1162
|
const column = holder ? (holder.firstElementChild || holder) : null;
|
|
1144
1163
|
if (!column) return null;
|
|
1145
1164
|
const columnRect = column.getBoundingClientRect();
|
|
1146
|
-
if (columnRect.width <
|
|
1147
|
-
|
|
1148
|
-
//
|
|
1149
|
-
//
|
|
1150
|
-
//
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
if (rect.width <= 0 || rect.height < 40) continue;
|
|
1157
|
-
const edge = rect.right;
|
|
1158
|
-
if (boundaryRight === null || edge > boundaryRight) boundaryRight = edge;
|
|
1165
|
+
if (columnRect.width < 220 || columnRect.height < 160) return null;
|
|
1166
|
+
|
|
1167
|
+
// Reserve a strip on the right of the conversation box instead of overlapping
|
|
1168
|
+
// it: DSH centres the transcript and the turn rail inside the padding box, so
|
|
1169
|
+
// padding-right slides both of them left and the dock owns the strip.
|
|
1170
|
+
const columnWidth = Math.round(columnRect.width);
|
|
1171
|
+
let width = Math.round(columnWidth * 0.26);
|
|
1172
|
+
width = Math.min(DOCK_MAX_WIDTH, Math.max(DOCK_MIN_WIDTH, width));
|
|
1173
|
+
if (columnWidth - (width + DOCK_GAP * 2) < DOCK_TRANSCRIPT_FLOOR) {
|
|
1174
|
+
width = Math.max(DOCK_FLOOR_WIDTH, columnWidth - DOCK_TRANSCRIPT_FLOOR - DOCK_GAP * 2);
|
|
1159
1175
|
}
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
// Turn navigator rail: per-turn buttons stacked at the column's right edge.
|
|
1163
|
-
let navLeft = null;
|
|
1164
|
-
for (const button of document.querySelectorAll('button[aria-label]')) {
|
|
1165
|
-
const label = button.getAttribute('aria-label') || '';
|
|
1166
|
-
if (!/turnNavigation|轮次|跳转/i.test(label)) continue;
|
|
1167
|
-
const rect = button.getBoundingClientRect();
|
|
1168
|
-
if (rect.width > 0 && rect.height > 0) navLeft = navLeft === null ? rect.left : Math.min(navLeft, rect.left);
|
|
1169
|
-
}
|
|
1170
|
-
if (navLeft === null) navLeft = columnRect.right - 26;
|
|
1171
|
-
|
|
1172
|
-
const leftEdge = Math.round(boundaryRight) + DOCK_GAP;
|
|
1173
|
-
const rightEdge = Math.round(navLeft) - DOCK_GAP;
|
|
1174
|
-
if (rightEdge - leftEdge < DOCK_MIN_WIDTH) return null;
|
|
1176
|
+
const reserve = width + DOCK_GAP * 2;
|
|
1175
1177
|
|
|
1176
1178
|
// Vertical bound: never cross or touch the separator under the tab strip.
|
|
1177
1179
|
let contentTop = Math.round(columnRect.top) + DOCK_GAP;
|
|
@@ -1184,10 +1186,45 @@ window.__ModuleLoader__.load({
|
|
|
1184
1186
|
}
|
|
1185
1187
|
}
|
|
1186
1188
|
|
|
1189
|
+
const rectOf = (el) => {
|
|
1190
|
+
if (!el) return null;
|
|
1191
|
+
const r = el.getBoundingClientRect();
|
|
1192
|
+
return { x: Math.round(r.left), y: Math.round(r.top), w: Math.round(r.width), h: Math.round(r.height) };
|
|
1193
|
+
};
|
|
1194
|
+
const chain = [];
|
|
1195
|
+
let node = document.querySelector('[data-slot="conversation.chat.flow"]');
|
|
1196
|
+
while (node && chain.length < 8) {
|
|
1197
|
+
chain.push({ tag: node.tagName, cls: String(node.className || '').slice(0, 60), r: rectOf(node), pad: getComputedStyle(node).paddingRight });
|
|
1198
|
+
if (node === column) break;
|
|
1199
|
+
node = node.parentElement;
|
|
1200
|
+
}
|
|
1201
|
+
reportDiag({
|
|
1202
|
+
at: new Date().toISOString(),
|
|
1203
|
+
column: rectOf(column),
|
|
1204
|
+
columnPad: getComputedStyle(column).paddingRight,
|
|
1205
|
+
columnInlinePad: column.style.getPropertyValue('padding-right'),
|
|
1206
|
+
flowChain: chain,
|
|
1207
|
+
handles: [...document.querySelectorAll('[class*="widthHandle"]')].map((el) => ({ side: el.getAttribute('data-side'), r: rectOf(el) })),
|
|
1208
|
+
nav: (() => {
|
|
1209
|
+
let min = null;
|
|
1210
|
+
let count = 0;
|
|
1211
|
+
for (const b of document.querySelectorAll('button[aria-label]')) {
|
|
1212
|
+
const l = b.getAttribute('aria-label') || '';
|
|
1213
|
+
if (!/turnNavigation|轮次|跳转/i.test(l)) continue;
|
|
1214
|
+
const r = b.getBoundingClientRect();
|
|
1215
|
+
if (r.width <= 0) continue;
|
|
1216
|
+
count += 1;
|
|
1217
|
+
min = min === null ? r.left : Math.min(min, r.left);
|
|
1218
|
+
}
|
|
1219
|
+
return { count, left: min === null ? null : Math.round(min) };
|
|
1220
|
+
})(),
|
|
1221
|
+
dock: { width, reserve, top: contentTop },
|
|
1222
|
+
viewport: window.innerWidth,
|
|
1223
|
+
});
|
|
1187
1224
|
return {
|
|
1188
1225
|
top: contentTop,
|
|
1189
|
-
|
|
1190
|
-
|
|
1226
|
+
width,
|
|
1227
|
+
reserve,
|
|
1191
1228
|
maxHeight: Math.max(120, Math.round(columnRect.bottom) - contentTop - DOCK_GAP),
|
|
1192
1229
|
};
|
|
1193
1230
|
}
|
|
@@ -1225,14 +1262,28 @@ window.__ModuleLoader__.load({
|
|
|
1225
1262
|
if (frame) window.cancelAnimationFrame(frame);
|
|
1226
1263
|
};
|
|
1227
1264
|
}, []);
|
|
1265
|
+
const reserve = box ? box.reserve : 0;
|
|
1266
|
+
React.useEffect(() => {
|
|
1267
|
+
if (!active || !reserve) return undefined;
|
|
1268
|
+
const holder = document.querySelector('[data-slot="main.conversation"]');
|
|
1269
|
+
const column = holder ? (holder.firstElementChild || holder) : null;
|
|
1270
|
+
if (!column) return undefined;
|
|
1271
|
+
const saved = column.style.getPropertyValue('padding-right');
|
|
1272
|
+
const priority = column.style.getPropertyPriority('padding-right');
|
|
1273
|
+
column.style.setProperty('padding-right', reserve + 'px', 'important');
|
|
1274
|
+
return () => {
|
|
1275
|
+
if (saved) column.style.setProperty('padding-right', saved, priority);
|
|
1276
|
+
else column.style.removeProperty('padding-right');
|
|
1277
|
+
};
|
|
1278
|
+
}, [active, reserve]);
|
|
1228
1279
|
const shown = active && box !== null;
|
|
1229
1280
|
return h('div', {
|
|
1230
1281
|
'data-ustc-quota-dock': 'right',
|
|
1231
1282
|
style: {
|
|
1232
1283
|
position: 'fixed',
|
|
1233
1284
|
top: box ? box.top : 0,
|
|
1234
|
-
right:
|
|
1235
|
-
width: box ? box.width :
|
|
1285
|
+
right: DOCK_GAP,
|
|
1286
|
+
width: box ? box.width : DOCK_MIN_WIDTH,
|
|
1236
1287
|
maxHeight: box ? box.maxHeight : 0,
|
|
1237
1288
|
overflow: 'visible',
|
|
1238
1289
|
display: shown ? 'flex' : 'none',
|
|
@@ -1243,7 +1294,6 @@ window.__ModuleLoader__.load({
|
|
|
1243
1294
|
},
|
|
1244
1295
|
}, h(QuotaStrip, Object.assign({}, props, { placement: 'right', wide: true, active, visible: active })));
|
|
1245
1296
|
}
|
|
1246
|
-
|
|
1247
1297
|
function QuotaStrip(props) {
|
|
1248
1298
|
const t = typeof props.t === 'function' ? props.t : fallbackT;
|
|
1249
1299
|
const placement = props.placement === 'right' ? 'right' : 'left';
|
package/index.js
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import os from 'node:os';
|
|
3
|
+
import path from 'node:path';
|
|
1
4
|
/**
|
|
2
5
|
* Host half of dsh-ustc-quota.
|
|
3
6
|
*
|
|
@@ -22,7 +25,7 @@ const ROUTE_PATH = '/plugins/dsh-ustc-quota/snapshot';
|
|
|
22
25
|
const UPDATE_PATH = '/plugins/dsh-ustc-quota/update';
|
|
23
26
|
const UPDATE_APPLY_PATH = '/plugins/dsh-ustc-quota/update/apply';
|
|
24
27
|
const UPDATE_TOKEN_TTL_MS = 30 * 60 * 1000;
|
|
25
|
-
const PLUGIN_VERSION = '1.1.
|
|
28
|
+
const PLUGIN_VERSION = '1.1.27';
|
|
26
29
|
const KEY_INFO_PATH = 'key/info';
|
|
27
30
|
const USER_INFO_PATH = 'user/info';
|
|
28
31
|
const DISCOVERY_TTL_MS = 30000;
|
|
@@ -57,7 +60,43 @@ export function apply(ctx, config) {
|
|
|
57
60
|
path: UPDATE_APPLY_PATH,
|
|
58
61
|
handler: (request, response) => handleUpdateApply(ctx, updates, updateTokens, request, response),
|
|
59
62
|
}), 'dsh-ustc-quota: update apply route');
|
|
60
|
-
|
|
63
|
+
|
|
64
|
+
// TEMPORARY diagnostics channel (removed before the next public release).
|
|
65
|
+
ctx.effect(() => ctx.webServer.register({
|
|
66
|
+
kind: 'exact',
|
|
67
|
+
path: '/plugins/dsh-ustc-quota/diag',
|
|
68
|
+
handler: (request, response) => {
|
|
69
|
+
if (request.method === 'GET') {
|
|
70
|
+
try {
|
|
71
|
+
const web = ctx.webServer || {};
|
|
72
|
+
const info = {};
|
|
73
|
+
for (const key of Object.keys(web)) {
|
|
74
|
+
const value = web[key];
|
|
75
|
+
if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') info[key] = value;
|
|
76
|
+
}
|
|
77
|
+
response.writeHead(200, { 'content-type': 'application/json', 'cache-control': 'no-store' });
|
|
78
|
+
response.end(JSON.stringify({ info, keys: Object.keys(web) }));
|
|
79
|
+
} catch (error) {
|
|
80
|
+
response.writeHead(500);
|
|
81
|
+
response.end(String(error));
|
|
82
|
+
}
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
let body = '';
|
|
86
|
+
request.on('data', (chunk) => { body += chunk; });
|
|
87
|
+
request.on('end', () => {
|
|
88
|
+
try {
|
|
89
|
+
const file = path.join(os.tmpdir(), 'dsh-ustc-quota-diag.jsonl');
|
|
90
|
+
fs.appendFileSync(file, String(body).replace(/\\r?\\n/g, ' ') + '\\n');
|
|
91
|
+
response.writeHead(204, { 'cache-control': 'no-store' });
|
|
92
|
+
response.end();
|
|
93
|
+
} catch {
|
|
94
|
+
response.writeHead(500);
|
|
95
|
+
response.end();
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
},
|
|
99
|
+
}), 'dsh-ustc-quota: diag route');}
|
|
61
100
|
|
|
62
101
|
function createReader(ctx, settings) {
|
|
63
102
|
const cache = new Map();
|
package/package.json
CHANGED