dsh-ustc-quota 1.1.21 → 1.1.22
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 +3 -4
- package/client.js +134 -59
- package/index.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -107,10 +107,9 @@ key-c 8.7/30 29% 8.7/70 12% 11.1/100 11%
|
|
|
107
107
|
|
|
108
108
|
## 面板位置
|
|
109
109
|
|
|
110
|
-
-
|
|
111
|
-
-
|
|
112
|
-
-
|
|
113
|
-
|
|
110
|
+
- 卡片默认在左侧边栏底部。**鼠标移到卡片上时,标题左边的品牌图标会变成方向图标**(`→` 移到右侧、`←` 移回左侧),点一下即可换边;移开鼠标图标复原。选择会记住,重启后保持。
|
|
111
|
+
- 右侧位置停在**对话列里、聊天内容与轮次导航条之间的空白**:左右各留 24px,宽度随空白自适应,不遮挡右侧原生按钮,也不侵入轮次导航条。拖动对话边界或开关任一侧边栏时,卡片跟着走。
|
|
112
|
+
- 换边不重新加载:两处卡片共用同一份已取到的数据,切换时直接显示,之后在后台刷新。
|
|
114
113
|
## 更新
|
|
115
114
|
|
|
116
115
|
- 标题「USTC 词元额度」右侧显示灰色小字版本号;点击版本号可手动检查更新;
|
package/client.js
CHANGED
|
@@ -11,14 +11,12 @@ 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.22';
|
|
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`;
|
|
18
18
|
const HOST_VERSION_KEY = `${NS}:host-version-reload`;
|
|
19
19
|
const POSITION_KEY = `${NS}:position`;
|
|
20
|
-
const RIGHT_DOCK_WIDTH = 300;
|
|
21
|
-
const RIGHT_DOCK_GAP = 12;
|
|
22
20
|
|
|
23
21
|
function readDshVersion() {
|
|
24
22
|
try {
|
|
@@ -383,6 +381,19 @@ window.__ModuleLoader__.load({
|
|
|
383
381
|
letterSpacing: '-0.01em',
|
|
384
382
|
whiteSpace: 'nowrap',
|
|
385
383
|
},
|
|
384
|
+
brandButton: {
|
|
385
|
+
display: 'inline-flex',
|
|
386
|
+
alignItems: 'center',
|
|
387
|
+
justifyContent: 'center',
|
|
388
|
+
margin: 0,
|
|
389
|
+
padding: 0,
|
|
390
|
+
border: 0,
|
|
391
|
+
background: 'transparent',
|
|
392
|
+
color: 'var(--dsw-alias-label-primary)',
|
|
393
|
+
cursor: 'pointer',
|
|
394
|
+
lineHeight: 0,
|
|
395
|
+
flex: '0 0 auto',
|
|
396
|
+
},
|
|
386
397
|
brandMark: {
|
|
387
398
|
display: 'inline-flex',
|
|
388
399
|
alignItems: 'center',
|
|
@@ -1013,9 +1024,12 @@ window.__ModuleLoader__.load({
|
|
|
1013
1024
|
return provider;
|
|
1014
1025
|
}
|
|
1015
1026
|
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1027
|
+
// Resting state: the TokenWorks brand mark (five rounded tiles forming a T),
|
|
1028
|
+
// redrawn as a 24-viewBox monochrome line icon. Hovering the card swaps it for
|
|
1029
|
+
// the dock switch glyph so the header keeps a single 13 px seat.
|
|
1030
|
+
function TokenWorksMark(props) {
|
|
1031
|
+
const showSwitch = props && props.showSwitch === true;
|
|
1032
|
+
const targetRight = !props || props.target !== 'left';
|
|
1019
1033
|
const tile = (x, y) => h('rect', {
|
|
1020
1034
|
key: x + '-' + y,
|
|
1021
1035
|
x,
|
|
@@ -1026,14 +1040,29 @@ window.__ModuleLoader__.load({
|
|
|
1026
1040
|
stroke: 'currentColor',
|
|
1027
1041
|
strokeWidth: 1.6,
|
|
1028
1042
|
});
|
|
1043
|
+
const frame = (children) => h('svg', {
|
|
1044
|
+
width: 13,
|
|
1045
|
+
height: 13,
|
|
1046
|
+
viewBox: '0 0 24 24',
|
|
1047
|
+
fill: 'none',
|
|
1048
|
+
style: { display: 'block' },
|
|
1049
|
+
'data-ustc-mark-glyph': showSwitch ? 'switch' : 'brand',
|
|
1050
|
+
}, children);
|
|
1051
|
+
const switchGlyph = targetRight
|
|
1052
|
+
? [
|
|
1053
|
+
h('rect', { key: 'f', x: 2.4, y: 4.6, width: 19.2, height: 14.8, rx: 2.6, stroke: 'currentColor', strokeWidth: 1.5 }),
|
|
1054
|
+
h('path', { key: 'a', d: 'M7.4 12h7.4', stroke: 'currentColor', strokeWidth: 1.6, strokeLinecap: 'round' }),
|
|
1055
|
+
h('path', { key: 'b', d: 'M12.2 9.1 15.4 12l-3.2 2.9', stroke: 'currentColor', strokeWidth: 1.6, strokeLinecap: 'round', strokeLinejoin: 'round' }),
|
|
1056
|
+
]
|
|
1057
|
+
: [
|
|
1058
|
+
h('rect', { key: 'f', x: 2.4, y: 4.6, width: 19.2, height: 14.8, rx: 2.6, stroke: 'currentColor', strokeWidth: 1.5 }),
|
|
1059
|
+
h('path', { key: 'a', d: 'M16.6 12H9.2', stroke: 'currentColor', strokeWidth: 1.6, strokeLinecap: 'round' }),
|
|
1060
|
+
h('path', { key: 'b', d: 'M11.8 9.1 8.6 12l3.2 2.9', stroke: 'currentColor', strokeWidth: 1.6, strokeLinecap: 'round', strokeLinejoin: 'round' }),
|
|
1061
|
+
];
|
|
1029
1062
|
return h('span', { style: STYLE.brandMark, 'aria-hidden': true, 'data-ustc-mark': '' },
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
tile(9.25, 3.5),
|
|
1033
|
-
tile(16.25, 3.5),
|
|
1034
|
-
tile(9.25, 10.5),
|
|
1035
|
-
tile(9.25, 17.5)
|
|
1036
|
-
)
|
|
1063
|
+
frame(showSwitch
|
|
1064
|
+
? switchGlyph
|
|
1065
|
+
: [tile(2.25, 3.5), tile(9.25, 3.5), tile(16.25, 3.5), tile(9.25, 10.5), tile(9.25, 17.5)])
|
|
1037
1066
|
);
|
|
1038
1067
|
}
|
|
1039
1068
|
|
|
@@ -1065,91 +1094,123 @@ window.__ModuleLoader__.load({
|
|
|
1065
1094
|
return React.useSyncExternalStore(subscribePanelPosition, readPanelPosition, readPanelPosition);
|
|
1066
1095
|
}
|
|
1067
1096
|
|
|
1068
|
-
//
|
|
1097
|
+
// Both seats stay mounted so switching dock position keeps the fetched data:
|
|
1098
|
+
// the hidden seat only stops polling, it never unmounts.
|
|
1069
1099
|
function LeftDock(props) {
|
|
1070
1100
|
const position = usePanelPosition();
|
|
1071
|
-
|
|
1072
|
-
|
|
1101
|
+
const active = position === 'left';
|
|
1102
|
+
// No wrapper element: DSH's footer layout normalisation rewrites display on
|
|
1103
|
+
// ancestors, which would unhide a wrapper we hid ourselves. The card stays
|
|
1104
|
+
// mounted (state preserved) and returns null while the other seat is active.
|
|
1105
|
+
return h(QuotaStrip, Object.assign({}, props, { placement: 'left', active, visible: active }));
|
|
1073
1106
|
}
|
|
1074
1107
|
|
|
1075
1108
|
// DSH exposes no plugin seat for the conversation's right column: 'rightbar'
|
|
1076
1109
|
// is a single seat owned by the shipped right sidebar. The dock therefore
|
|
1077
|
-
// measures the conversation column and pins itself
|
|
1078
|
-
//
|
|
1110
|
+
// measures the conversation column and pins itself into the blank strip
|
|
1111
|
+
// between the chat content and the turn navigator, so it follows the
|
|
1112
|
+
// conversation when either side is dragged or toggled.
|
|
1113
|
+
const DOCK_GAP = 24;
|
|
1114
|
+
const DOCK_MIN_WIDTH = 220;
|
|
1115
|
+
const DOCK_MAX_WIDTH = 420;
|
|
1116
|
+
|
|
1117
|
+
function measureRightDock() {
|
|
1118
|
+
const holder = document.querySelector('[data-slot="main.conversation"]');
|
|
1119
|
+
const column = holder ? (holder.firstElementChild || holder) : null;
|
|
1120
|
+
if (!column) return null;
|
|
1121
|
+
const columnRect = column.getBoundingClientRect();
|
|
1122
|
+
if (columnRect.width < 240 || columnRect.height < 160) return null;
|
|
1123
|
+
|
|
1124
|
+
const flowHolder = document.querySelector('[data-slot="conversation.chat.flow"]');
|
|
1125
|
+
const flow = flowHolder ? (flowHolder.firstElementChild || flowHolder) : null;
|
|
1126
|
+
const flowRect = flow ? flow.getBoundingClientRect() : null;
|
|
1127
|
+
|
|
1128
|
+
// The turn navigator is a rail of per-turn buttons at the column's right edge.
|
|
1129
|
+
let navLeft = null;
|
|
1130
|
+
for (const button of document.querySelectorAll('button[aria-label]')) {
|
|
1131
|
+
const label = button.getAttribute('aria-label') || '';
|
|
1132
|
+
if (!/turnNavigation|轮次|跳转/i.test(label)) continue;
|
|
1133
|
+
const rect = button.getBoundingClientRect();
|
|
1134
|
+
if (rect.width > 0 && rect.height > 0) navLeft = navLeft === null ? rect.left : Math.min(navLeft, rect.left);
|
|
1135
|
+
}
|
|
1136
|
+
if (navLeft === null) navLeft = columnRect.right - 26;
|
|
1137
|
+
|
|
1138
|
+
let width = DOCK_MAX_WIDTH;
|
|
1139
|
+
if (flowRect && flowRect.width > 0 && flowRect.right < navLeft) {
|
|
1140
|
+
const available = navLeft - flowRect.right - DOCK_GAP * 2;
|
|
1141
|
+
width = Math.min(DOCK_MAX_WIDTH, Math.max(DOCK_MIN_WIDTH, Math.round(available)));
|
|
1142
|
+
}
|
|
1143
|
+
width = Math.max(DOCK_MIN_WIDTH, Math.min(width, Math.round(columnRect.width - DOCK_GAP * 2)));
|
|
1144
|
+
|
|
1145
|
+
return {
|
|
1146
|
+
top: Math.max(8, Math.round(columnRect.top) + 16),
|
|
1147
|
+
right: Math.max(8, Math.round(window.innerWidth - navLeft) + DOCK_GAP),
|
|
1148
|
+
width,
|
|
1149
|
+
maxHeight: Math.max(160, Math.round(columnRect.height) - 32),
|
|
1150
|
+
};
|
|
1151
|
+
}
|
|
1152
|
+
|
|
1079
1153
|
function RightDock(props) {
|
|
1080
1154
|
const position = usePanelPosition();
|
|
1155
|
+
const active = position === 'right';
|
|
1081
1156
|
const [box, setBox] = React.useState(null);
|
|
1082
1157
|
React.useEffect(() => {
|
|
1083
|
-
if (position !== 'right') {
|
|
1084
|
-
setBox(null);
|
|
1085
|
-
return undefined;
|
|
1086
|
-
}
|
|
1087
1158
|
let frame = 0;
|
|
1088
1159
|
let observer = null;
|
|
1089
1160
|
let observed = null;
|
|
1090
1161
|
const measure = () => {
|
|
1091
1162
|
frame = 0;
|
|
1092
|
-
// The slot wrapper renders with display: contents, so it has no box of
|
|
1093
|
-
// its own; the column is its first element child.
|
|
1094
1163
|
const holder = document.querySelector('[data-slot="main.conversation"]');
|
|
1095
1164
|
const column = holder ? (holder.firstElementChild || holder) : null;
|
|
1096
|
-
if (
|
|
1097
|
-
setBox(null);
|
|
1098
|
-
return;
|
|
1099
|
-
}
|
|
1100
|
-
if (observed !== column && typeof ResizeObserver === 'function') {
|
|
1165
|
+
if (column && column !== observed && typeof ResizeObserver === 'function') {
|
|
1101
1166
|
if (observer) observer.disconnect();
|
|
1102
1167
|
observed = column;
|
|
1103
1168
|
observer = new ResizeObserver(schedule);
|
|
1104
1169
|
observer.observe(column);
|
|
1105
1170
|
}
|
|
1106
|
-
|
|
1107
|
-
if (rect.width < 200 || rect.height < 120) {
|
|
1108
|
-
setBox(null);
|
|
1109
|
-
return;
|
|
1110
|
-
}
|
|
1111
|
-
setBox({
|
|
1112
|
-
top: Math.max(8, Math.round(rect.top) + RIGHT_DOCK_GAP),
|
|
1113
|
-
right: Math.max(8, Math.round(window.innerWidth - rect.right) + RIGHT_DOCK_GAP),
|
|
1114
|
-
maxHeight: Math.max(160, Math.round(rect.height) - RIGHT_DOCK_GAP * 2),
|
|
1115
|
-
});
|
|
1171
|
+
setBox(measureRightDock());
|
|
1116
1172
|
};
|
|
1117
1173
|
function schedule() {
|
|
1118
1174
|
if (!frame) frame = window.requestAnimationFrame(measure);
|
|
1119
1175
|
}
|
|
1120
1176
|
measure();
|
|
1121
|
-
const
|
|
1177
|
+
const timer = window.setInterval(measure, 2000);
|
|
1122
1178
|
window.addEventListener('resize', schedule);
|
|
1123
1179
|
return () => {
|
|
1124
1180
|
window.removeEventListener('resize', schedule);
|
|
1125
|
-
window.clearInterval(
|
|
1181
|
+
window.clearInterval(timer);
|
|
1126
1182
|
if (observer) observer.disconnect();
|
|
1127
1183
|
if (frame) window.cancelAnimationFrame(frame);
|
|
1128
1184
|
};
|
|
1129
|
-
}, [
|
|
1130
|
-
|
|
1185
|
+
}, []);
|
|
1186
|
+
const shown = active && box !== null;
|
|
1131
1187
|
return h('div', {
|
|
1132
1188
|
'data-ustc-quota-dock': 'right',
|
|
1133
1189
|
style: {
|
|
1134
1190
|
position: 'fixed',
|
|
1135
|
-
top: box.top,
|
|
1136
|
-
right: box.right,
|
|
1137
|
-
width:
|
|
1138
|
-
maxHeight: box.maxHeight,
|
|
1191
|
+
top: box ? box.top : 0,
|
|
1192
|
+
right: box ? box.right : 0,
|
|
1193
|
+
width: box ? box.width : DOCK_MAX_WIDTH,
|
|
1194
|
+
maxHeight: box ? box.maxHeight : 0,
|
|
1139
1195
|
overflowY: 'auto',
|
|
1140
|
-
display: 'flex',
|
|
1196
|
+
display: shown ? 'flex' : 'none',
|
|
1141
1197
|
flexDirection: 'column',
|
|
1142
1198
|
gap: 6,
|
|
1143
1199
|
pointerEvents: 'auto',
|
|
1144
1200
|
zIndex: 5,
|
|
1145
1201
|
},
|
|
1146
|
-
}, h(QuotaStrip, Object.assign({}, props, { placement: 'right', wide: true })));
|
|
1202
|
+
}, h(QuotaStrip, Object.assign({}, props, { placement: 'right', wide: true, active, visible: active })));
|
|
1147
1203
|
}
|
|
1148
1204
|
|
|
1149
1205
|
function QuotaStrip(props) {
|
|
1150
1206
|
const t = typeof props.t === 'function' ? props.t : fallbackT;
|
|
1151
1207
|
const placement = props.placement === 'right' ? 'right' : 'left';
|
|
1152
1208
|
const position = usePanelPosition();
|
|
1209
|
+
const active = props.active !== false;
|
|
1210
|
+
const [cardHovered, setCardHovered] = React.useState(false);
|
|
1211
|
+
const [markHovered, setMarkHovered] = React.useState(false);
|
|
1212
|
+
const activeRef = React.useRef(active);
|
|
1213
|
+
activeRef.current = active;
|
|
1153
1214
|
const [snapshot, setSnapshot] = React.useState(null);
|
|
1154
1215
|
const [error, setError] = React.useState(null);
|
|
1155
1216
|
const [loading, setLoading] = React.useState(true);
|
|
@@ -1290,6 +1351,12 @@ window.__ModuleLoader__.load({
|
|
|
1290
1351
|
}
|
|
1291
1352
|
|
|
1292
1353
|
async function run() {
|
|
1354
|
+
if (!activeRef.current) {
|
|
1355
|
+
// The card is mounted in the other seat right now: keep the last data,
|
|
1356
|
+
// skip the request, and try again on the next tick.
|
|
1357
|
+
schedule(15000);
|
|
1358
|
+
return;
|
|
1359
|
+
}
|
|
1293
1360
|
const body = await load(false);
|
|
1294
1361
|
if (disposed) return;
|
|
1295
1362
|
schedule(body && Number.isFinite(body.pollAfterMs) ? body.pollAfterMs : 15000);
|
|
@@ -1331,7 +1398,7 @@ window.__ModuleLoader__.load({
|
|
|
1331
1398
|
if (!root) return undefined;
|
|
1332
1399
|
// The right dock is not inside DSH's footer row; rewriting ancestors there
|
|
1333
1400
|
// would fight the dock container instead of the sidebar layout.
|
|
1334
|
-
if (placement === 'right') return undefined;
|
|
1401
|
+
if (placement === 'right' || props.visible === false) return undefined;
|
|
1335
1402
|
return installFooterLayout(root);
|
|
1336
1403
|
}, [props.wide, placement]);
|
|
1337
1404
|
|
|
@@ -1342,6 +1409,8 @@ window.__ModuleLoader__.load({
|
|
|
1342
1409
|
const tokenworksNotReady = warnings.includes('tokenworks-not-ready');
|
|
1343
1410
|
|
|
1344
1411
|
if (props.wide === false) return null;
|
|
1412
|
+
// Hidden seat: keep the component (and its data) mounted, render no DOM.
|
|
1413
|
+
if (props.visible === false) return null;
|
|
1345
1414
|
|
|
1346
1415
|
function handleVersionClick() {
|
|
1347
1416
|
if (updateInfo && updateInfo.updateAvailable) {
|
|
@@ -1666,7 +1735,18 @@ window.__ModuleLoader__.load({
|
|
|
1666
1735
|
? t('updateChecking')
|
|
1667
1736
|
: t('versionCheck');
|
|
1668
1737
|
const header = h('div', { style: STYLE.header },
|
|
1669
|
-
h(
|
|
1738
|
+
h('button', {
|
|
1739
|
+
type: 'button',
|
|
1740
|
+
'data-ustc-position-toggle': '',
|
|
1741
|
+
'aria-label': position === 'right' ? t('moveToLeft') : t('moveToRight'),
|
|
1742
|
+
title: position === 'right' ? t('moveToLeft') : t('moveToRight'),
|
|
1743
|
+
onClick: () => { writePanelPosition(position === 'right' ? 'left' : 'right'); },
|
|
1744
|
+
onMouseEnter: () => { setMarkHovered(true); },
|
|
1745
|
+
onMouseLeave: () => { setMarkHovered(false); },
|
|
1746
|
+
onFocus: () => { setMarkHovered(true); },
|
|
1747
|
+
onBlur: () => { setMarkHovered(false); },
|
|
1748
|
+
style: STYLE.brandButton,
|
|
1749
|
+
}, h(TokenWorksMark, { showSwitch: markHovered || cardHovered, target: position === 'right' ? 'left' : 'right' })),
|
|
1670
1750
|
h('span', { style: STYLE.title, 'data-ustc-title': '' }, t('title')),
|
|
1671
1751
|
h('button', {
|
|
1672
1752
|
type: 'button',
|
|
@@ -1687,14 +1767,7 @@ window.__ModuleLoader__.load({
|
|
|
1687
1767
|
: null,
|
|
1688
1768
|
error && snapshot ? h('span', { style: STYLE.warn, title: error }, '!') : null,
|
|
1689
1769
|
h('span', { style: STYLE.meta }, updated ? `${t('updatedLabel')} ${updated}` : ''),
|
|
1690
|
-
|
|
1691
|
-
type: 'button',
|
|
1692
|
-
'data-ustc-position-toggle': '',
|
|
1693
|
-
'aria-label': position === 'right' ? t('moveToLeft') : t('moveToRight'),
|
|
1694
|
-
title: position === 'right' ? t('moveToLeft') : t('moveToRight'),
|
|
1695
|
-
onClick: () => { writePanelPosition(position === 'right' ? 'left' : 'right'); },
|
|
1696
|
-
style: STYLE.refresh,
|
|
1697
|
-
}, position === 'right' ? '⇤' : '⇥'),
|
|
1770
|
+
|
|
1698
1771
|
h('button', {
|
|
1699
1772
|
type: 'button',
|
|
1700
1773
|
'aria-label': t('refresh'),
|
|
@@ -1836,6 +1909,8 @@ window.__ModuleLoader__.load({
|
|
|
1836
1909
|
role: 'group',
|
|
1837
1910
|
'aria-label': t('title'),
|
|
1838
1911
|
'data-ustc-quota-root': '',
|
|
1912
|
+
onMouseEnter: () => { setCardHovered(true); },
|
|
1913
|
+
onMouseLeave: () => { setCardHovered(false); setMarkHovered(false); },
|
|
1839
1914
|
},
|
|
1840
1915
|
header,
|
|
1841
1916
|
restartBanner,
|
package/index.js
CHANGED
|
@@ -22,7 +22,7 @@ const ROUTE_PATH = '/plugins/dsh-ustc-quota/snapshot';
|
|
|
22
22
|
const UPDATE_PATH = '/plugins/dsh-ustc-quota/update';
|
|
23
23
|
const UPDATE_APPLY_PATH = '/plugins/dsh-ustc-quota/update/apply';
|
|
24
24
|
const UPDATE_TOKEN_TTL_MS = 30 * 60 * 1000;
|
|
25
|
-
const PLUGIN_VERSION = '1.1.
|
|
25
|
+
const PLUGIN_VERSION = '1.1.22';
|
|
26
26
|
const KEY_INFO_PATH = 'key/info';
|
|
27
27
|
const USER_INFO_PATH = 'user/info';
|
|
28
28
|
const DISCOVERY_TTL_MS = 30000;
|
package/package.json
CHANGED