@gruu6y/page-clean-login 0.2.5 → 0.2.7

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/ui/index.html CHANGED
@@ -105,6 +105,16 @@
105
105
  spellcheck="false" placeholder="Name, id or plugin" aria-describedby="providers-search-status" />
106
106
  <span class="search-status" id="providers-search-status" role="status"></span>
107
107
  </div>
108
+ <label class="providers-category-field" for="providers-category">
109
+ <span class="search-label" id="providers-category-label">Category</span>
110
+ <select class="test-target-select" id="providers-category">
111
+ <option value="all" id="providers-cat-all">All</option>
112
+ <option value="signable" id="providers-cat-signable">Signable</option>
113
+ <option value="hasAccounts" id="providers-cat-has-accounts">Has accounts</option>
114
+ <option value="catalog" id="providers-cat-catalog">Catalog</option>
115
+ </select>
116
+ </label>
117
+ <button class="button" id="providers-refresh" type="button">Refresh</button>
108
118
  </div>
109
119
  </div>
110
120
  <div class="setup-card" id="environment-setup" hidden>
@@ -170,6 +180,9 @@
170
180
  <span class="test-target-label" id="test-target-label">Test target</span>
171
181
  <select class="test-target-select" id="proxy-test-target"></select>
172
182
  </label>
183
+ <button class="button" id="proxies-test-all" type="button">Test all</button>
184
+ <button class="button quiet" id="proxies-test-cancel" type="button" hidden>Cancel tests</button>
185
+ <button class="button" id="proxies-bulk-open" type="button">Bulk import</button>
173
186
  <button class="button primary" id="add-proxy" type="button">
174
187
  <span aria-hidden="true">+</span>
175
188
  <span id="add-proxy-label">Add Proxy</span>
@@ -201,6 +214,38 @@
201
214
  inputmode="numeric" placeholder="Max" aria-label="Maximum latency">
202
215
  </div>
203
216
  </div>
217
+ <div class="filter-group">
218
+ <label class="filter-label" id="filter-search-label" for="filter-search">Search</label>
219
+ <input class="filter-input filter-search-input" id="filter-search" type="search" autocomplete="off"
220
+ spellcheck="false" placeholder="Search proxies" aria-label="Search proxies">
221
+ </div>
222
+ <div class="filter-group">
223
+ <label class="filter-label" id="filter-status-label" for="filter-status">Status</label>
224
+ <select class="filter-select" id="filter-status">
225
+ <option value="all" id="filter-status-all">All</option>
226
+ <option value="ok" id="filter-status-ok">Available</option>
227
+ <option value="error" id="filter-status-error">Failed</option>
228
+ <option value="untested" id="filter-status-untested">Untested</option>
229
+ </select>
230
+ </div>
231
+ <div class="filter-group">
232
+ <label class="filter-label" id="filter-usage-label" for="filter-usage">Usage</label>
233
+ <select class="filter-select" id="filter-usage">
234
+ <option value="all" id="filter-usage-all">All</option>
235
+ <option value="used" id="filter-usage-used">In use</option>
236
+ <option value="unused" id="filter-usage-unused">Unused</option>
237
+ </select>
238
+ </div>
239
+ <div class="filter-group">
240
+ <label class="filter-label" id="proxy-sort-label" for="proxy-sort">Sort</label>
241
+ <select class="filter-select" id="proxy-sort">
242
+ <option value="default" id="proxy-sort-default">Default</option>
243
+ <option value="latency" id="proxy-sort-latency">Latency</option>
244
+ <option value="score" id="proxy-sort-score">Trust score</option>
245
+ <option value="usage" id="proxy-sort-usage">In use</option>
246
+ <option value="name" id="proxy-sort-name">Name</option>
247
+ </select>
248
+ </div>
204
249
  <div class="filter-actions">
205
250
  <span class="filter-count" id="filter-count"></span>
206
251
  <button class="button quiet" id="filter-reset" type="button">Reset</button>
@@ -301,6 +346,10 @@
301
346
  data-account-filter="signedIn" aria-pressed="false"><span id="account-filter-signed-in-label">Signed in</span> <span class="filter-chip-count" id="account-filter-signed-in-count">0</span></button>
302
347
  <button class="filter-chip" id="account-filter-signed-out" type="button"
303
348
  data-account-filter="signedOut" aria-pressed="false"><span id="account-filter-signed-out-label">Signed out</span> <span class="filter-chip-count" id="account-filter-signed-out-count">0</span></button>
349
+ <button class="filter-chip" id="account-filter-hosting-paused" type="button"
350
+ data-account-filter="hostingPaused" aria-pressed="false"><span id="account-filter-hosting-paused-label">Renewal paused</span> <span class="filter-chip-count" id="account-filter-hosting-paused-count">0</span></button>
351
+ <button class="filter-chip" id="account-filter-expiring-soon" type="button"
352
+ data-account-filter="expiringSoon" aria-pressed="false"><span id="account-filter-expiring-soon-label">Expiring soon</span> <span class="filter-chip-count" id="account-filter-expiring-soon-count">0</span></button>
304
353
  </div>
305
354
  </div>
306
355
  <div class="filter-actions">
@@ -463,6 +512,10 @@
463
512
  <input id="proxy-password" name="password" type="password"
464
513
  autocomplete="new-password" spellcheck="false" maxlength="255">
465
514
  <p class="field-hint" id="proxy-password-hint" hidden></p>
515
+ <label class="checkbox-field" id="proxy-clear-password-field" for="proxy-clear-password" hidden>
516
+ <input id="proxy-clear-password" type="checkbox">
517
+ <span id="proxy-clear-password-label">Clear saved password</span>
518
+ </label>
466
519
  </div>
467
520
  </div>
468
521
  </div>
@@ -484,6 +537,43 @@
484
537
  </form>
485
538
  </dialog>
486
539
 
540
+ <dialog id="proxy-bulk-dialog" class="dialog">
541
+ <div class="dialog-head">
542
+ <div>
543
+ <h3 id="proxy-bulk-title">Bulk import proxies</h3>
544
+ <p id="proxy-bulk-copy">Paste one proxy per line. Existing connections are skipped automatically.</p>
545
+ </div>
546
+ <button class="dialog-close" id="proxy-bulk-close" type="button" aria-label="Close">×</button>
547
+ </div>
548
+ <div class="dialog-body">
549
+ <div class="form-row">
550
+ <div class="field">
551
+ <label for="proxy-bulk-type" id="proxy-bulk-type-label">Default type</label>
552
+ <select id="proxy-bulk-type">
553
+ <option value="http">HTTP</option>
554
+ <option value="https">HTTPS</option>
555
+ <option value="socks5">SOCKS5</option>
556
+ </select>
557
+ </div>
558
+ <div class="field">
559
+ <label for="proxy-bulk-prefix" id="proxy-bulk-prefix-label">Name prefix</label>
560
+ <input id="proxy-bulk-prefix" type="text" autocomplete="off" maxlength="40" placeholder="SG">
561
+ </div>
562
+ </div>
563
+ <div class="field">
564
+ <label for="proxy-bulk-input" id="proxy-bulk-input-label">Proxy list</label>
565
+ <textarea id="proxy-bulk-input" rows="8" autocomplete="off" spellcheck="false"
566
+ placeholder="127.0.0.1:7890"></textarea>
567
+ <p class="field-hint" id="proxy-bulk-summary" role="status"></p>
568
+ </div>
569
+ <p class="form-error" id="proxy-bulk-error" role="alert" hidden></p>
570
+ </div>
571
+ <div class="dialog-footer">
572
+ <button class="button" id="proxy-bulk-cancel" type="button">Cancel</button>
573
+ <button class="button primary" id="proxy-bulk-submit" type="button">Import</button>
574
+ </div>
575
+ </dialog>
576
+
487
577
  <dialog id="signin-dialog" class="dialog signin-dialog">
488
578
  <div class="dialog-head">
489
579
  <div>
@@ -258,3 +258,25 @@ export function filterProviders(items, query, lang = "en") {
258
258
  if (words.length === 0) return list;
259
259
  return list.filter((provider) => providerMatchesQuery(provider, query, lang));
260
260
  }
261
+
262
+ export function countAccountsByProvider(accounts = []) {
263
+ const counts = {};
264
+ for (const account of Array.isArray(accounts) ? accounts : []) {
265
+ if (!account || typeof account !== "object") continue;
266
+ const provider = typeof account.provider === "string" ? account.provider.trim() : "";
267
+ if (!provider) continue;
268
+ counts[provider] = (counts[provider] || 0) + 1;
269
+ }
270
+ return counts;
271
+ }
272
+
273
+ export function filterProvidersByCategory(items = [], category = "all", accountCounts = {}) {
274
+ const list = Array.isArray(items) ? items : [];
275
+ if (!category || category === "all") return list;
276
+ if (category === "signable") return list.filter((item) => providerCanSignIn(item));
277
+ if (category === "hasAccounts") {
278
+ return list.filter((item) => item && accountCountOf(accountCounts, item.id) > 0);
279
+ }
280
+ if (category === "catalog") return list.filter((item) => item?.presence === "catalog");
281
+ return list;
282
+ }
@@ -87,13 +87,42 @@ export function distinctKeywords(proxies = [], keywords = KEYWORD_TAGS) {
87
87
 
88
88
  export function filterProxies(
89
89
  proxies = [],
90
- { regions = [], keywords = [], minLatency = null, maxLatency = null, latencyOf = null } = {},
90
+ {
91
+ regions = [],
92
+ keywords = [],
93
+ minLatency = null,
94
+ maxLatency = null,
95
+ latencyOf = null,
96
+ search = "",
97
+ status = "all",
98
+ usage = "all",
99
+ usedIds = null,
100
+ statusOf = null,
101
+ } = {},
91
102
  ) {
92
103
  const selected = selectionOf(regions);
93
104
  const chosen = selectionOf(keywords);
94
105
  const min = latencyBound(minLatency);
95
106
  const max = latencyBound(maxLatency);
96
107
  const latencyFilter = min !== null || max !== null;
108
+ const searchWords =
109
+ typeof search === "string"
110
+ ? search
111
+ .trim()
112
+ .toLowerCase()
113
+ .split(/\s+/)
114
+ .filter(Boolean)
115
+ : [];
116
+ const wantedStatus =
117
+ status === "ok" || status === "error" || status === "untested" ? status : "all";
118
+ const wantedUsage = usage === "used" || usage === "unused" ? usage : "all";
119
+ const usedSet =
120
+ usedIds instanceof Set
121
+ ? usedIds
122
+ : Array.isArray(usedIds)
123
+ ? new Set(usedIds)
124
+ : EMPTY_SELECTION;
125
+
97
126
  return (Array.isArray(proxies) ? proxies : []).filter((proxy) => {
98
127
  if (!proxy) return false;
99
128
  if (selected.size > 0 && !selected.has(regionKey(proxy))) return false;
@@ -102,6 +131,30 @@ export function filterProxies(
102
131
  if (chosen.size > 0 && ![...chosen].some((keyword) => hasKeyword(proxy, keyword))) {
103
132
  return false;
104
133
  }
134
+ if (wantedStatus !== "all") {
135
+ const actualStatus =
136
+ typeof statusOf === "function" ? statusOf(proxy) : proxy.status || "untested";
137
+ if (actualStatus !== wantedStatus) return false;
138
+ }
139
+ if (wantedUsage !== "all") {
140
+ const isUsed = Boolean(proxy.id && usedSet.has(proxy.id));
141
+ if (wantedUsage === "used" && !isUsed) return false;
142
+ if (wantedUsage === "unused" && isUsed) return false;
143
+ }
144
+ if (searchWords.length > 0) {
145
+ const haystack = [
146
+ proxy.name,
147
+ proxy.host,
148
+ proxy.port != null ? String(proxy.port) : "",
149
+ proxy.region,
150
+ proxy.exitIp,
151
+ proxy.type,
152
+ ]
153
+ .filter((part) => typeof part === "string" && part)
154
+ .join(" ")
155
+ .toLowerCase();
156
+ if (!searchWords.every((word) => haystack.includes(word))) return false;
157
+ }
105
158
  if (latencyFilter) {
106
159
  // A selected probe target can supply its own latency. Without one this is
107
160
  // exactly the record's own number, so the historical filter is unchanged.
@@ -114,4 +167,60 @@ export function filterProxies(
114
167
  }
115
168
  return true;
116
169
  });
170
+ }
171
+
172
+ const proxySortCollator = new Intl.Collator("zh-Hans", {
173
+ numeric: true,
174
+ sensitivity: "base",
175
+ });
176
+
177
+ function usageCountFor(proxy, usageCounts) {
178
+ if (!usageCounts || !proxy?.id) return 0;
179
+ const raw =
180
+ typeof usageCounts.get === "function" ? usageCounts.get(proxy.id) : usageCounts[proxy.id];
181
+ return typeof raw === "number" && Number.isFinite(raw) && raw > 0 ? raw : 0;
182
+ }
183
+
184
+ export function sortProxies(
185
+ proxies = [],
186
+ sort = "default",
187
+ { latencyOf = null, usageCounts = null } = {},
188
+ ) {
189
+ const list = Array.isArray(proxies) ? [...proxies] : [];
190
+ if (!sort || sort === "default") return list;
191
+
192
+ return list.sort((a, b) => {
193
+ const aName = proxyName(a) || String(a?.id ?? "");
194
+ const bName = proxyName(b) || String(b?.id ?? "");
195
+
196
+ if (sort === "name") {
197
+ return proxySortCollator.compare(aName, bName);
198
+ }
199
+
200
+ if (sort === "latency") {
201
+ const aLat = typeof latencyOf === "function" ? latencyOf(a) : a?.latency;
202
+ const bLat = typeof latencyOf === "function" ? latencyOf(b) : b?.latency;
203
+ const aValid = typeof aLat === "number" && Number.isFinite(aLat);
204
+ const bValid = typeof bLat === "number" && Number.isFinite(bLat);
205
+ if (aValid && bValid && aLat !== bLat) return aLat - bLat;
206
+ if (aValid !== bValid) return aValid ? -1 : 1;
207
+ return proxySortCollator.compare(aName, bName);
208
+ }
209
+
210
+ if (sort === "score") {
211
+ const aScore = typeof a?.score === "number" && Number.isFinite(a.score) ? a.score : null;
212
+ const bScore = typeof b?.score === "number" && Number.isFinite(b.score) ? b.score : null;
213
+ if (aScore !== null && bScore !== null && aScore !== bScore) return bScore - aScore;
214
+ if ((aScore !== null) !== (bScore !== null)) return aScore !== null ? -1 : 1;
215
+ return proxySortCollator.compare(aName, bName);
216
+ }
217
+
218
+ if (sort === "usage") {
219
+ const diff = usageCountFor(b, usageCounts) - usageCountFor(a, usageCounts);
220
+ if (diff !== 0) return diff;
221
+ return proxySortCollator.compare(aName, bName);
222
+ }
223
+
224
+ return 0;
225
+ });
117
226
  }
package/ui/proxy-state.js CHANGED
@@ -96,3 +96,262 @@ export function createConfirmController() {
96
96
  },
97
97
  };
98
98
  }
99
+
100
+ export const PROXY_BULK_LIMIT = 200;
101
+
102
+ const BULK_TYPES = ["http", "https", "socks5"];
103
+ const BULK_LIMITS = {
104
+ name: 80,
105
+ host: 255,
106
+ username: 255,
107
+ password: 255,
108
+ };
109
+
110
+ function cleanBulkLabel(value) {
111
+ return String(value ?? "").replace(/[<>\u0000-\u001f\u007f]/g, "").trim();
112
+ }
113
+
114
+ function safeDecode(value) {
115
+ if (!value) return "";
116
+ try {
117
+ return decodeURIComponent(value);
118
+ } catch {
119
+ return value;
120
+ }
121
+ }
122
+
123
+ export function proxyConnectionKey(proxy = {}) {
124
+ const type = typeof proxy?.type === "string" ? proxy.type.trim().toLowerCase() : "";
125
+ let host = typeof proxy?.host === "string" ? proxy.host.trim().toLowerCase() : "";
126
+ if (host.startsWith("[") && host.endsWith("]")) host = host.slice(1, -1);
127
+ const port = Number(proxy?.port);
128
+ const username = typeof proxy?.username === "string" ? proxy.username.trim() : "";
129
+ return `${type}|${host}|${Number.isFinite(port) ? port : ""}|${username}`;
130
+ }
131
+
132
+ function splitBulkLabel(line) {
133
+ const match = /^(\S+)(?:\s+(.+))?$/.exec(line);
134
+ if (!match) return { spec: line, label: "" };
135
+ return { spec: match[1], label: cleanBulkLabel(match[2] ?? "") };
136
+ }
137
+
138
+ function normalizeDefaultType(raw) {
139
+ const lower = String(raw ?? "http").trim().toLowerCase();
140
+ return BULK_TYPES.includes(lower) ? lower : "http";
141
+ }
142
+
143
+ function parseBulkHostPortAndAuth(spec, fallbackType) {
144
+ const atIndex = spec.lastIndexOf("@");
145
+ let user = "";
146
+ let pass = "";
147
+ let target = spec;
148
+ if (atIndex >= 0) {
149
+ const authPart = spec.slice(0, atIndex);
150
+ target = spec.slice(atIndex + 1);
151
+ const colon = authPart.indexOf(":");
152
+ if (colon < 0) return { ok: false, reason: "invalid_auth" };
153
+ user = safeDecode(authPart.slice(0, colon));
154
+ pass = safeDecode(authPart.slice(colon + 1));
155
+ }
156
+
157
+ if (target.startsWith("[")) {
158
+ const bracket = /^\[([^\]]+)\]:(\d{1,5})(?::([^:]*):(.*))?$/.exec(target);
159
+ if (!bracket) return { ok: false, reason: "invalid_port" };
160
+ return {
161
+ ok: true,
162
+ type: fallbackType,
163
+ host: bracket[1],
164
+ port: bracket[2],
165
+ username: atIndex >= 0 ? user : bracket[3] ?? "",
166
+ password: atIndex >= 0 ? pass : bracket[4] ?? "",
167
+ };
168
+ }
169
+
170
+ const parts = target.split(":");
171
+ if (parts.length === 2) {
172
+ return { ok: true, type: fallbackType, host: parts[0], port: parts[1], username: user, password: pass };
173
+ }
174
+ if (atIndex < 0 && parts.length >= 4 && /^\d{1,5}$/.test(parts[1])) {
175
+ if (parts.length > 4 && !parts[0].includes(".")) {
176
+ return { ok: false, reason: "invalid_host" };
177
+ }
178
+ return {
179
+ ok: true,
180
+ type: fallbackType,
181
+ host: parts[0],
182
+ port: parts[1],
183
+ username: parts[2],
184
+ password: parts.slice(3).join(":"),
185
+ };
186
+ }
187
+ return { ok: false, reason: parts.length === 1 ? "invalid_port" : "invalid_format" };
188
+ }
189
+
190
+ function parseSingleBulkLine(line, fallbackType) {
191
+ let working = line;
192
+ let pipedLabel = "";
193
+ const piped = /^([^|\s]+)\|([a-z][a-z0-9+.-]*:\/\/.+)$/i.exec(working);
194
+ if (piped) {
195
+ pipedLabel = cleanBulkLabel(piped[1]);
196
+ working = piped[2];
197
+ }
198
+
199
+ if (/^[a-z][a-z0-9+.-]*:\/\//i.test(working)) {
200
+ const { spec, label: trailingLabel } = splitBulkLabel(working);
201
+ let parsed;
202
+ try {
203
+ parsed = new URL(spec);
204
+ } catch {
205
+ return { ok: false, reason: "invalid_url" };
206
+ }
207
+ const rawScheme = parsed.protocol.slice(0, -1).toLowerCase();
208
+ const type = rawScheme === "socks5h" ? "socks5" : rawScheme;
209
+ if (!BULK_TYPES.includes(type)) return { ok: false, reason: "invalid_type" };
210
+ if (!parsed.port) return { ok: false, reason: "invalid_port" };
211
+ const hashLabel = cleanBulkLabel(safeDecode(parsed.hash.replace(/^#/, "")));
212
+ return {
213
+ ok: true,
214
+ type,
215
+ host: parsed.hostname,
216
+ port: parsed.port,
217
+ username: safeDecode(parsed.username),
218
+ password: safeDecode(parsed.password),
219
+ label: pipedLabel || trailingLabel || hashLabel,
220
+ };
221
+ }
222
+
223
+ const hashIdx = working.indexOf(" #");
224
+ let body = working;
225
+ let hashLabel = "";
226
+ if (hashIdx >= 0) {
227
+ body = working.slice(0, hashIdx).trim();
228
+ hashLabel = cleanBulkLabel(working.slice(hashIdx + 2));
229
+ }
230
+ const { spec, label: spaceLabel } = splitBulkLabel(body);
231
+ const parsed = parseBulkHostPortAndAuth(spec, fallbackType);
232
+ if (!parsed.ok) return parsed;
233
+ return { ...parsed, label: pipedLabel || spaceLabel || hashLabel };
234
+ }
235
+
236
+ function validateBulkItem(parsed) {
237
+ let host = String(parsed.host ?? "").trim();
238
+ if (host.startsWith("[") && host.endsWith("]")) host = host.slice(1, -1).trim();
239
+ if (!host || host.length > BULK_LIMITS.host || /[<>\s\u0000-\u001f\u007f]/.test(host)) {
240
+ return { ok: false, reason: "invalid_host" };
241
+ }
242
+ const port = Number(parsed.port);
243
+ if (!Number.isInteger(port) || port < 1 || port > 65535) {
244
+ return { ok: false, reason: "invalid_port" };
245
+ }
246
+ const username = String(parsed.username ?? "").trim();
247
+ const password = String(parsed.password ?? "");
248
+ if (username.length > BULK_LIMITS.username || /[\u0000-\u001f\u007f]/.test(username)) {
249
+ return { ok: false, reason: "invalid_username" };
250
+ }
251
+ if (password.length > BULK_LIMITS.password || /\u0000/.test(password)) {
252
+ return { ok: false, reason: "invalid_password" };
253
+ }
254
+ if (!BULK_TYPES.includes(parsed.type)) {
255
+ return { ok: false, reason: "invalid_type" };
256
+ }
257
+ return {
258
+ ok: true,
259
+ item: {
260
+ name: "",
261
+ type: parsed.type,
262
+ host,
263
+ port,
264
+ username,
265
+ password,
266
+ },
267
+ };
268
+ }
269
+
270
+ function uniqueBulkName(base, usedNames) {
271
+ const clean = cleanBulkLabel(base).slice(0, BULK_LIMITS.name) || "proxy";
272
+ if (!usedNames.has(clean)) {
273
+ usedNames.add(clean);
274
+ return clean;
275
+ }
276
+ for (let suffix = 2; suffix < 100_000; suffix += 1) {
277
+ const tag = `-${suffix}`;
278
+ const candidate = `${clean.slice(0, Math.max(1, BULK_LIMITS.name - tag.length))}${tag}`;
279
+ if (!usedNames.has(candidate)) {
280
+ usedNames.add(candidate);
281
+ return candidate;
282
+ }
283
+ }
284
+ return clean;
285
+ }
286
+
287
+ export function parseBulkProxies(
288
+ text,
289
+ {
290
+ defaultType = "http",
291
+ prefix = "",
292
+ existingNames = [],
293
+ existingKeys = [],
294
+ limit = PROXY_BULK_LIMIT,
295
+ } = {},
296
+ ) {
297
+ const fallbackType = normalizeDefaultType(defaultType);
298
+ const maxItems = Number.isInteger(limit) && limit > 0 ? limit : PROXY_BULK_LIMIT;
299
+ const safePrefix = cleanBulkLabel(prefix);
300
+ const usedNames = new Set(
301
+ (Array.isArray(existingNames) ? existingNames : [])
302
+ .filter((name) => typeof name === "string")
303
+ .map((name) => name.trim())
304
+ .filter(Boolean),
305
+ );
306
+ const seenKeys = new Set(
307
+ (Array.isArray(existingKeys) ? existingKeys : []).filter(
308
+ (key) => typeof key === "string" && key,
309
+ ),
310
+ );
311
+ const items = [];
312
+ const duplicates = [];
313
+ const invalid = [];
314
+ let truncated = 0;
315
+
316
+ const lines = typeof text === "string" ? text.split(/\r?\n/) : [];
317
+ for (let index = 0; index < lines.length; index += 1) {
318
+ const raw = lines[index].trim();
319
+ if (!raw || raw.startsWith("#") || raw.startsWith("//")) continue;
320
+ const line = index + 1;
321
+ if (items.length >= maxItems) {
322
+ truncated += 1;
323
+ continue;
324
+ }
325
+ const parsed = parseSingleBulkLine(raw, fallbackType);
326
+ if (!parsed.ok) {
327
+ invalid.push({ line, reason: parsed.reason || "invalid_format" });
328
+ continue;
329
+ }
330
+ const validated = validateBulkItem(parsed);
331
+ if (!validated.ok) {
332
+ invalid.push({ line, reason: validated.reason });
333
+ continue;
334
+ }
335
+ const key = proxyConnectionKey(validated.item);
336
+ if (seenKeys.has(key)) {
337
+ duplicates.push({ line, reason: "duplicate" });
338
+ continue;
339
+ }
340
+ seenKeys.add(key);
341
+ const hostDisplay =
342
+ validated.item.host.includes(":") && !validated.item.host.startsWith("[")
343
+ ? `[${validated.item.host}]`
344
+ : validated.item.host;
345
+ const baseLabel = parsed.label
346
+ ? safePrefix
347
+ ? `${safePrefix} ${parsed.label}`
348
+ : parsed.label
349
+ : safePrefix
350
+ ? `${safePrefix}-${hostDisplay}:${validated.item.port}`
351
+ : `${hostDisplay}:${validated.item.port}`;
352
+ validated.item.name = uniqueBulkName(baseLabel, usedNames);
353
+ items.push(validated.item);
354
+ }
355
+
356
+ return { items, duplicates, invalid, truncated };
357
+ }
@@ -89,6 +89,14 @@ export function providerLatency(proxy, provider) {
89
89
  return measured;
90
90
  }
91
91
 
92
+ export function genericProxyView(proxy) {
93
+ if (!proxy || typeof proxy !== "object") return proxy;
94
+ if (proxy.exitStatus === "ok" && proxy.status === "error") {
95
+ return { ...proxy, status: "ok", error: "", errorCode: "" };
96
+ }
97
+ return proxy;
98
+ }
99
+
92
100
  // The row and the sign-in dropdown render through statusView(), which reads
93
101
  // `proxy.latency`. Decorating a shallow copy means the stored record keeps its
94
102
  // generic measurement while the chosen target sees its own number. With a
@@ -99,17 +107,49 @@ export function proxyForTarget(proxy, provider, catalogue) {
99
107
  const target = findTarget(catalogue, provider);
100
108
  if (!target) return proxy;
101
109
  const measured = providerLatency(proxy, provider);
102
- return {
110
+ const probe =
111
+ proxy.probeByProvider &&
112
+ typeof proxy.probeByProvider === "object" &&
113
+ !Array.isArray(proxy.probeByProvider)
114
+ ? (proxy.probeByProvider[provider] ?? null)
115
+ : null;
116
+
117
+ const decorated = {
103
118
  ...proxy,
104
119
  latency: measured ? measured.ms : null,
105
120
  latencyTarget: {
106
121
  id: target.id,
107
122
  name: target.name,
108
- host: measured?.host || target.host,
109
- at: measured?.at || "",
110
- ...(measured?.handshake ? { handshake: true } : {}),
123
+ host: measured?.host || probe?.host || target.host,
124
+ at: measured?.at || probe?.at || "",
125
+ ...(measured?.handshake || probe?.handshake ? { handshake: true } : {}),
111
126
  },
112
127
  };
128
+
129
+ if (probe && probe.ok === false) {
130
+ decorated.status = "error";
131
+ decorated.error = short(probe.error, 240);
132
+ decorated.errorCode = short(probe.errorCode, 48);
133
+ decorated.latency = null;
134
+ decorated.targetProbe = probe;
135
+ } else if (probe && probe.ok === true) {
136
+ decorated.status = "ok";
137
+ decorated.error = "";
138
+ decorated.errorCode = "";
139
+ decorated.latency = measured
140
+ ? measured.ms
141
+ : typeof probe.ms === "number" && Number.isFinite(probe.ms)
142
+ ? Math.round(probe.ms)
143
+ : null;
144
+ decorated.targetProbe = probe;
145
+ } else if (!probe && !measured && proxy.exitStatus === "ok" && proxy.status === "error") {
146
+ decorated.status = "untested";
147
+ decorated.error = "";
148
+ decorated.errorCode = "";
149
+ decorated.latency = null;
150
+ }
151
+
152
+ return decorated;
113
153
  }
114
154
 
115
155
  export function targetStatusSuffix(proxy) {
@@ -58,7 +58,9 @@ export function orderSignInProxies(proxies = [], accounts = [], provider) {
58
58
  const rank = (proxy) => {
59
59
  const id = typeof proxy.id === "string" ? proxy.id.trim() : "";
60
60
  const name = proxyName(proxy).trim().toLowerCase();
61
- if (used.ids.has(id) || (name && used.names.has(name))) return 3;
61
+ const isUsed = used.ids.has(id) || (name && used.names.has(name));
62
+ if (proxy.status === "error") return isUsed ? 5 : 4;
63
+ if (isUsed) return 3;
62
64
  if (hasKeyword(proxy, "静态")) return 0;
63
65
  if (hasKeyword(proxy, "家宽")) return 1;
64
66
  return 2;
@@ -80,15 +82,19 @@ export function formatSignInProxyOption(proxy = {}, labels = {}, testing = false
80
82
  const base = `${name} · ${formatAddress(proxy)}`;
81
83
  const view = statusView(proxy, labels, testing);
82
84
  if (view.state === "testing") return `${base} · ${view.label}`;
85
+ const scoreSuffix =
86
+ typeof proxy?.score === "number" && Number.isFinite(proxy.score)
87
+ ? ` · ${Math.round(proxy.score)}`
88
+ : "";
83
89
  if (view.state === "ok") {
84
90
  // When the row was decorated for a provider target, the number belongs to
85
91
  // that provider. Name it so a generic measurement can never be mistaken
86
92
  // for a provider-specific one. Undecorated rows keep the exact old text.
87
93
  const target = targetStatusSuffix(proxy);
88
- return `${base} · ${view.detail || view.label}${target}`;
94
+ return `${base} · ${view.detail || view.label}${target}${scoreSuffix}`;
89
95
  }
90
- if (view.state === "error") return `${base} · ${view.label}`;
91
- return base;
96
+ if (view.state === "error") return `${base} · ${view.label}${scoreSuffix}`;
97
+ return `${base}${scoreSuffix}`;
92
98
  }
93
99
 
94
100
  // Probes the candidate exits in display order with a small worker pool. The