dsh-ustc-quota 1.1.28 → 1.1.30

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.
Files changed (3) hide show
  1. package/client.js +53 -29
  2. package/index.js +2 -2
  3. package/package.json +1 -1
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.28';
14
+ const CLIENT_VERSION = '1.1.30';
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`;
@@ -1157,6 +1157,36 @@ window.__ModuleLoader__.load({
1157
1157
  // diagnostics are best-effort
1158
1158
  }
1159
1159
  }
1160
+ let reservedColumn = null;
1161
+ let reservedSaved = null;
1162
+ let reservedSavedPriority = '';
1163
+
1164
+ function applyReservedPadding(reserve) {
1165
+ const holder = document.querySelector('[data-slot="main.conversation"]');
1166
+ const column = holder ? (holder.firstElementChild || holder) : null;
1167
+ if (!column) return false;
1168
+ if (reservedColumn !== column) {
1169
+ releaseReservedPadding();
1170
+ reservedColumn = column;
1171
+ reservedSaved = column.style.getPropertyValue('padding-right');
1172
+ reservedSavedPriority = column.style.getPropertyPriority('padding-right');
1173
+ }
1174
+ const wanted = reserve + 'px';
1175
+ if (column.style.getPropertyValue('padding-right') !== wanted) {
1176
+ column.style.setProperty('padding-right', wanted, 'important');
1177
+ }
1178
+ return true;
1179
+ }
1180
+
1181
+ function releaseReservedPadding() {
1182
+ if (!reservedColumn) return;
1183
+ if (reservedSaved) reservedColumn.style.setProperty('padding-right', reservedSaved, reservedSavedPriority);
1184
+ else reservedColumn.style.removeProperty('padding-right');
1185
+ reservedColumn = null;
1186
+ reservedSaved = null;
1187
+ reservedSavedPriority = '';
1188
+ }
1189
+
1160
1190
  function measureRightDock() {
1161
1191
  const holder = document.querySelector('[data-slot="main.conversation"]');
1162
1192
  const column = holder ? (holder.firstElementChild || holder) : null;
@@ -1231,6 +1261,16 @@ window.__ModuleLoader__.load({
1231
1261
  return { count, left: min === null ? null : Math.round(min) };
1232
1262
  })(),
1233
1263
  dock: { width, reserve, top: contentTop, railInset },
1264
+ position: (() => { try { return window.localStorage.getItem(POSITION_KEY); } catch { return null; } })(),
1265
+ dockRect: (() => {
1266
+ const el = document.querySelector('[data-ustc-quota-dock]');
1267
+ if (!el) return null;
1268
+ const r = el.getBoundingClientRect();
1269
+ return { x: Math.round(r.left), w: Math.round(r.width), display: getComputedStyle(el).display };
1270
+ })(),
1271
+ railButtons: [...document.querySelectorAll('button[aria-label]')]
1272
+ .filter((b) => /右侧边栏/.test(b.getAttribute('aria-label') || ''))
1273
+ .map((b) => ({ label: b.getAttribute('aria-label'), r: rectOf(b) })),
1234
1274
  viewport: window.innerWidth,
1235
1275
  });
1236
1276
  return {
@@ -1246,6 +1286,8 @@ window.__ModuleLoader__.load({
1246
1286
  const position = usePanelPosition();
1247
1287
  const active = position === 'right';
1248
1288
  const [box, setBox] = React.useState(null);
1289
+ const activeRef = React.useRef(active);
1290
+ activeRef.current = active;
1249
1291
  React.useEffect(() => {
1250
1292
  let frame = 0;
1251
1293
  let observer = null;
@@ -1260,7 +1302,12 @@ window.__ModuleLoader__.load({
1260
1302
  observer = new ResizeObserver(schedule);
1261
1303
  observer.observe(column);
1262
1304
  }
1263
- setBox(measureRightDock());
1305
+ const next = measureRightDock();
1306
+ setBox(next);
1307
+ // Apply the reserved padding from the same loop that measured it; a React
1308
+ // effect can be skipped when DSH re-renders the column behind our back.
1309
+ if (activeRef.current && next) applyReservedPadding(next.reserve);
1310
+ else releaseReservedPadding();
1264
1311
  };
1265
1312
  function schedule() {
1266
1313
  if (!frame) frame = window.requestAnimationFrame(measure);
@@ -1275,34 +1322,11 @@ window.__ModuleLoader__.load({
1275
1322
  if (frame) window.cancelAnimationFrame(frame);
1276
1323
  };
1277
1324
  }, []);
1278
- const reserve = box ? box.reserve : 0;
1325
+ React.useEffect(() => () => { releaseReservedPadding(); }, []);
1279
1326
  React.useEffect(() => {
1280
- if (!active || !reserve) return undefined;
1281
- const holder = document.querySelector('[data-slot="main.conversation"]');
1282
- const column = holder ? (holder.firstElementChild || holder) : null;
1283
- if (!column) return undefined;
1284
- const saved = column.style.getPropertyValue('padding-right');
1285
- const priority = column.style.getPropertyPriority('padding-right');
1286
- const wanted = reserve + 'px';
1287
- const apply = () => {
1288
- if (column.style.getPropertyValue('padding-right') !== wanted) {
1289
- column.style.setProperty('padding-right', wanted, 'important');
1290
- }
1291
- };
1292
- apply();
1293
- // DSH re-renders the column and rewrites its style attribute, so watch it.
1294
- const observer = typeof MutationObserver === 'function'
1295
- ? new MutationObserver(apply)
1296
- : null;
1297
- if (observer) observer.observe(column, { attributes: true, attributeFilter: ['style'] });
1298
- const timer = window.setInterval(apply, 1000);
1299
- return () => {
1300
- if (observer) observer.disconnect();
1301
- window.clearInterval(timer);
1302
- if (saved) column.style.setProperty('padding-right', saved, priority);
1303
- else column.style.removeProperty('padding-right');
1304
- };
1305
- }, [active, reserve]);
1327
+ if (!active) releaseReservedPadding();
1328
+ }, [active]);
1329
+
1306
1330
  const shown = active && box !== null;
1307
1331
  return h('div', {
1308
1332
  'data-ustc-quota-dock': 'right',
package/index.js CHANGED
@@ -25,7 +25,7 @@ const ROUTE_PATH = '/plugins/dsh-ustc-quota/snapshot';
25
25
  const UPDATE_PATH = '/plugins/dsh-ustc-quota/update';
26
26
  const UPDATE_APPLY_PATH = '/plugins/dsh-ustc-quota/update/apply';
27
27
  const UPDATE_TOKEN_TTL_MS = 30 * 60 * 1000;
28
- const PLUGIN_VERSION = '1.1.28';
28
+ const PLUGIN_VERSION = '1.1.30';
29
29
  const KEY_INFO_PATH = 'key/info';
30
30
  const USER_INFO_PATH = 'user/info';
31
31
  const DISCOVERY_TTL_MS = 30000;
@@ -87,7 +87,7 @@ export function apply(ctx, config) {
87
87
  request.on('end', () => {
88
88
  try {
89
89
  const file = path.join(os.tmpdir(), 'dsh-ustc-quota-diag.jsonl');
90
- fs.appendFileSync(file, String(body).replace(/\\r?\\n/g, ' ') + '\\n');
90
+ fs.appendFileSync(file, String(body).replace(/[\r\n]+/g, ' ') + String.fromCharCode(10));
91
91
  response.writeHead(204, { 'cache-control': 'no-store' });
92
92
  response.end();
93
93
  } catch {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-ustc-quota",
3
- "version": "1.1.28",
3
+ "version": "1.1.30",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "description": "Live 3h/12h/24h USTC token quota card in the DSH sidebar (works with the USTC TokenWorks distribution).",