dsh-pick 0.7.2 → 0.7.3
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 +6 -1
- package/package.json +1 -1
- package/web/panel.html +49 -21
- package/web/panel.js +217 -33
package/README.md
CHANGED
|
@@ -90,7 +90,12 @@ dsh plugin --profile web add dsh-pick
|
|
|
90
90
|
|
|
91
91
|
**比较清单**:搜索结果之外的插件也能比较。在「选插件」底部输入插件名,边输边提示,回车或点选加入;AI 精选的结果也能一键加入比较。不在每日去噪范围(周下载前 300 多名)里的插件,加入比较时自动从 npm 实时算出日常基线、环比、版本节奏、健康度、累计下载。
|
|
92
92
|
|
|
93
|
-
|
|
93
|
+
**我的监控**:盯自家产品和竞品。点「+ 添加」输入插件名、npm 包名或 GitHub 地址直接加;点 ☆ 把自家产品标成「我的」。下面的「监控详情」:
|
|
94
|
+
- **这次的变化**:和至少 12 小时前的那次刷新比,只列明显的(发了新版、下载涨跌两成以上、星标、名次变化),我的产品排前面
|
|
95
|
+
- **按指标排**:选一个指标(周下载、日常基线、环比、星标、综合榜名次、npm 总榜、最近发版…),每个插件一行横条按名次排;我的产品写出第几、落后第 1 名多少、领先下一名多少
|
|
96
|
+
- **全部数据**:侧栏够宽时是完整表格(每个插件一列);窄的时候点哪个插件,下面列出它的全部数据(30 天走势、下载、版本、GitHub、市场位置)
|
|
97
|
+
|
|
98
|
+
每次刷新在本机存一份快照,显示「较上次」的涨跌(排名写成升 / 降几名);打开时数据超过 6 小时会自动刷新。
|
|
94
99
|
|
|
95
100
|
**综合榜(默认)**:把几个插件市场合成一个榜,一个插件只出现一次,在榜上就能直接安装,不用再去各个市场翻:
|
|
96
101
|
|
package/package.json
CHANGED
package/web/panel.html
CHANGED
|
@@ -242,20 +242,49 @@ table.cmp.wd .ch{display:block;font-size:10.5px;font-weight:600}
|
|
|
242
242
|
table.cmp.wd .ch.up{color:var(--ok)}table.cmp.wd .ch.down{color:var(--bad)}table.cmp.wd .ch.flat{color:var(--t3);font-weight:400}
|
|
243
243
|
table.cmp.wd .grp td{background:var(--soft);color:var(--t3);font-size:10.5px;font-weight:700;padding:4px 9px;text-align:left}
|
|
244
244
|
table.cmp.wd svg.spark{display:block;margin-left:auto}
|
|
245
|
-
/*
|
|
246
|
-
.
|
|
247
|
-
.
|
|
248
|
-
.
|
|
249
|
-
.
|
|
250
|
-
.
|
|
251
|
-
.
|
|
252
|
-
.
|
|
253
|
-
.
|
|
254
|
-
.
|
|
255
|
-
.
|
|
256
|
-
.
|
|
257
|
-
.
|
|
258
|
-
.
|
|
245
|
+
/* 监控详情:变化提醒 · 指标选单 · 我的产品和对手的差距 · 排名横条 · 单个插件的全部数据(窄屏) */
|
|
246
|
+
.wdch{margin:0 0 12px;padding:9px 11px;border-radius:9px;background:var(--accent-bg);font-size:12px;line-height:1.7;color:var(--text)}
|
|
247
|
+
.wdch b{font-weight:650}
|
|
248
|
+
.wdch .ln{margin-top:3px}
|
|
249
|
+
.wdch .it{display:inline-block;margin-left:8px;white-space:nowrap}
|
|
250
|
+
.wdch .it + .it::before{content:'·';margin-right:8px;color:var(--t3)}
|
|
251
|
+
.wdch .it .up{color:var(--ok)}.wdch .it .down{color:var(--bad)}
|
|
252
|
+
.wdch.quiet{background:var(--soft);color:var(--t3)}
|
|
253
|
+
.wdm{display:flex;flex-wrap:wrap;gap:6px;margin:2px 0 10px}
|
|
254
|
+
.wdm button{appearance:none;border:1px solid var(--line);background:var(--panel);color:var(--t2);font-family:inherit;font-size:11.5px;padding:3px 9px;border-radius:12px;cursor:pointer}
|
|
255
|
+
.wdm button.on{background:var(--accent);border-color:var(--accent);color:#fff}
|
|
256
|
+
.wdmine{margin:0 0 8px;font-size:12px;line-height:1.7;color:var(--t2)}
|
|
257
|
+
.wdmine div{padding:6px 10px;border-radius:8px;background:color-mix(in srgb,var(--warn,#f5a623) 12%,var(--panel));margin-bottom:4px}
|
|
258
|
+
.wdmine b{color:var(--text)}
|
|
259
|
+
.wdbars .wb{padding:6px 6px 7px;border-radius:8px;cursor:pointer}
|
|
260
|
+
.wdbars .wb:hover{background:var(--row-hover)}
|
|
261
|
+
.wdbars .wb.sel{background:var(--soft)}
|
|
262
|
+
.wdbars .wb.mine{box-shadow:inset 3px 0 0 #f5a623}
|
|
263
|
+
.wdbars .wbt{display:flex;align-items:center;gap:6px;font-size:12px;min-width:0}
|
|
264
|
+
.wdbars .wbr{flex:none;width:22px;color:var(--t3);font-variant-numeric:tabular-nums;font-size:11px}
|
|
265
|
+
.wdbars .wbn{flex:1;min-width:0;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;color:var(--text);font-weight:600}
|
|
266
|
+
.wdbars .wbn i{display:inline-block;width:8px;height:8px;border-radius:2px;margin-right:6px}
|
|
267
|
+
.wdbars .wbv{flex:none;font-variant-numeric:tabular-nums;font-weight:650;color:var(--text)}
|
|
268
|
+
.wdbars .wbv .ch{font-size:10.5px;font-weight:600;margin-left:5px}
|
|
269
|
+
.wdbars .wbb{margin:4px 0 0 28px;height:6px;border-radius:3px;background:var(--soft)}
|
|
270
|
+
.wdbars .wbb i{display:block;height:100%;border-radius:3px}
|
|
271
|
+
.wdbars .none .wbv{color:var(--t3);font-weight:400}
|
|
272
|
+
.ch.up{color:var(--ok)}.ch.down{color:var(--bad)}.ch.flat{color:var(--t3);font-weight:400}
|
|
273
|
+
.mtag{display:inline-block;font-size:10px;font-weight:700;color:#b26b00;background:color-mix(in srgb,#f5a623 22%,transparent);border-radius:4px;padding:0 4px;margin-left:5px;vertical-align:1px}
|
|
274
|
+
button.star{appearance:none;border:none;background:none;padding:0 3px 0 0;margin:0;font-size:13px;line-height:1;cursor:pointer;color:var(--mute);font-family:inherit}
|
|
275
|
+
button.star.on{color:#f5a623}
|
|
276
|
+
.wdnote{margin-top:6px}
|
|
277
|
+
.wdone{border-top:1px solid var(--line);margin-top:6px;padding-top:10px}
|
|
278
|
+
.wdone .hd{display:flex;align-items:center;gap:6px;font-size:13.5px;font-weight:700;color:var(--text);margin-bottom:6px}
|
|
279
|
+
.wdone .hd i{display:inline-block;width:9px;height:9px;border-radius:2px}
|
|
280
|
+
.wdone .grp{margin:10px 0 2px;padding:3px 8px;border-radius:6px;background:var(--soft);color:var(--t3);font-size:10.5px;font-weight:700}
|
|
281
|
+
.wdone .kv{display:flex;justify-content:space-between;align-items:center;gap:10px;padding:5px 2px;border-bottom:1px solid var(--soft);font-size:12px}
|
|
282
|
+
.wdone .kv:last-child{border-bottom:none}
|
|
283
|
+
.wdone .k{color:var(--t3);flex:none}
|
|
284
|
+
.wdone .v{text-align:right;color:var(--text);display:flex;flex-wrap:wrap;justify-content:flex-end;align-items:center;gap:4px 6px}
|
|
285
|
+
.wdone .v .ch{font-size:10.5px;font-weight:600}
|
|
286
|
+
.wdone .v .up{color:var(--ok)}.wdone .v .down{color:var(--bad)}
|
|
287
|
+
table.cmp.wd th.sel,table.cmp.wd td.sel{background:var(--soft)}
|
|
259
288
|
td.best{color:var(--ok);font-weight:700}
|
|
260
289
|
td.best::after{content:' ★';font-size:9px}
|
|
261
290
|
.miss{color:var(--mute)}
|
|
@@ -534,14 +563,13 @@ td.down{color:var(--bad);font-weight:600}
|
|
|
534
563
|
</div>
|
|
535
564
|
<div class="section" id="secWatchDetail">
|
|
536
565
|
<h2>监控详情 <span style="font-size:11.5px;color:var(--t3);font-weight:500" id="wdAsOf"></span></h2>
|
|
537
|
-
<
|
|
566
|
+
<div id="wdChanges" class="wdch hidden"></div>
|
|
567
|
+
<div id="wdMetrics" class="wdm" role="tablist" aria-label="按哪一项排"></div>
|
|
568
|
+
<div id="wdMine" class="wdmine hidden"></div>
|
|
569
|
+
<div id="wdBars" class="wdbars"></div>
|
|
570
|
+
<p class="cap wdnote">横条按名次比长短,数值差太大时(下载量)用对数刻度。点 ☆ 把自家产品标成「我的」,排名时算出和对手的差距。「较上次」和上一次刷新比:每次刷新都在本机存一份快照。</p>
|
|
538
571
|
<div class="tblwrap" id="wdTable"><table class="cmp wd"><thead id="wdHead"></thead><tbody id="wdBody"></tbody></table></div>
|
|
539
|
-
<div id="
|
|
540
|
-
</div>
|
|
541
|
-
<div class="section">
|
|
542
|
-
<h2>对比图</h2>
|
|
543
|
-
<p class="cap">对数刻度,否则头部插件会把其余压成一条线。</p>
|
|
544
|
-
<div id="watchChart"></div>
|
|
572
|
+
<div id="wdOne" class="wdone hidden"></div>
|
|
545
573
|
</div>
|
|
546
574
|
</div>
|
|
547
575
|
|
package/web/panel.js
CHANGED
|
@@ -455,6 +455,8 @@ function bindEvents() {
|
|
|
455
455
|
document.addEventListener('click', e => {
|
|
456
456
|
const b = e.target.closest('[data-watch]')
|
|
457
457
|
if (b) toggleWatch(b.dataset.watch)
|
|
458
|
+
const st = e.target.closest('[data-mine]')
|
|
459
|
+
if (st) toggleMine(st.dataset.mine)
|
|
458
460
|
const un = e.target.closest('[data-unpick]')
|
|
459
461
|
if (un) togglePick(un.dataset.unpick)
|
|
460
462
|
const pk = e.target.closest('#aiList [data-pick]')
|
|
@@ -1287,17 +1289,27 @@ function saveSnapshots(at) {
|
|
|
1287
1289
|
for (const n of watch()) {
|
|
1288
1290
|
const r = watchRec(n)
|
|
1289
1291
|
if (!r || !r.live) continue
|
|
1290
|
-
const snap = { t: at, w: r.w ?? null, base: r.deep ? r.deep.base : null, s: r.gh ? r.gh.s : null, rank: r.rank ?? null, sc: r.sc ?? null }
|
|
1292
|
+
const snap = { t: at, v: r.v || null, w: r.w ?? null, base: r.deep ? r.deep.base : null, s: r.gh ? r.gh.s : null, rank: r.rank ?? null, sc: r.sc ?? null, orank: angleRank(n, 'rec') }
|
|
1291
1293
|
const list = (hist[n] || []).filter(x => x.t !== at)
|
|
1292
1294
|
list.push(snap)
|
|
1293
1295
|
hist[n] = list.slice(-30)
|
|
1294
1296
|
}
|
|
1295
1297
|
try { localStorage.setItem(HIST_KEY, JSON.stringify(hist)) } catch { /* 存不下就不记 */ }
|
|
1296
1298
|
}
|
|
1297
|
-
/**
|
|
1299
|
+
/**
|
|
1300
|
+
* 拿哪一份快照当「上次」:最新一份往前、至少早 12 小时的那份(连点两次刷新,比的不是几分钟前的);
|
|
1301
|
+
* 没有那么早的,就用倒数第二份
|
|
1302
|
+
*/
|
|
1303
|
+
const BASE_GAP_MS = 12 * 3600 * 1000
|
|
1304
|
+
function baseSnap(list) {
|
|
1305
|
+
if (list.length < 2) return null
|
|
1306
|
+
const cur = Date.parse(list[list.length - 1].t)
|
|
1307
|
+
for (let i = list.length - 2; i >= 0; i--) if (cur - Date.parse(list[i].t) >= BASE_GAP_MS) return list[i]
|
|
1308
|
+
return list[list.length - 2]
|
|
1309
|
+
}
|
|
1310
|
+
/** 和「上次」的快照比:返回「较上次」的小字 */
|
|
1298
1311
|
function changeOf(n, key, now, { lowerIsBetter = false, asPct = true } = {}) {
|
|
1299
|
-
const
|
|
1300
|
-
const prev = list.length >= 2 ? list[list.length - 2] : null
|
|
1312
|
+
const prev = baseSnap(loadHistory()[n] || [])
|
|
1301
1313
|
if (!prev || prev[key] == null || now == null) return ''
|
|
1302
1314
|
const diff = now - prev[key]
|
|
1303
1315
|
const when = new Date(prev.t).toLocaleDateString()
|
|
@@ -1326,7 +1338,6 @@ function sparkSvg(daily, color) {
|
|
|
1326
1338
|
segs.map(p => (p.length === 1 ? `<circle cx="${p[0].split(',')[0]}" cy="${p[0].split(',')[1]}" r="1.5" fill="${color}"/>` : `<polyline points="${p.join(' ')}" fill="none" stroke="${color}" stroke-width="1.6" stroke-linejoin="round"/>`)).join('') +
|
|
1327
1339
|
'</svg>'
|
|
1328
1340
|
}
|
|
1329
|
-
/** 在综合榜某个角度里排第几(只在存下来的头部里找) */
|
|
1330
1341
|
// 综合榜每个角度的完整名次(和排行榜同一套排法),算一次存着,监控详情重画时清掉
|
|
1331
1342
|
let ANGLE_ORDER = new Map()
|
|
1332
1343
|
function angleRank(key, angle) {
|
|
@@ -1341,15 +1352,73 @@ function angleRank(key, angle) {
|
|
|
1341
1352
|
return ANGLE_ORDER.get(angle).get(key) || null
|
|
1342
1353
|
}
|
|
1343
1354
|
|
|
1355
|
+
/* ---------- 我的产品:在我的监控里标成自家的,排名时和对手比 ---------- */
|
|
1356
|
+
const MINE_KEY = 'dsh-pick-mine-v1'
|
|
1357
|
+
function mine() {
|
|
1358
|
+
try { return JSON.parse(localStorage.getItem(MINE_KEY)) || [] } catch { return [] }
|
|
1359
|
+
}
|
|
1360
|
+
function toggleMine(n) {
|
|
1361
|
+
const list = mine()
|
|
1362
|
+
const on = !list.includes(n)
|
|
1363
|
+
try { localStorage.setItem(MINE_KEY, JSON.stringify(on ? [...list, n] : list.filter(x => x !== n))) } catch { /* 存不下就只这次有效 */ }
|
|
1364
|
+
toast(on ? `已标成我的产品:${watchName(n)}` : `取消了「我的产品」:${watchName(n)}`)
|
|
1365
|
+
renderWatch()
|
|
1366
|
+
}
|
|
1367
|
+
const starBtn = n => {
|
|
1368
|
+
const on = mine().includes(n)
|
|
1369
|
+
return `<button class="star${on ? ' on' : ''}" data-mine="${esc(n)}" title="${on ? '是我的产品,点一下取消' : '标成我的产品(排名时算出和对手的差距)'}" aria-label="${on ? '取消我的产品' : '标成我的产品'}">${on ? '★' : '☆'}</button>`
|
|
1370
|
+
}
|
|
1371
|
+
|
|
1372
|
+
/*
|
|
1373
|
+
* 监控详情:
|
|
1374
|
+
* 顶部「这次的变化」(和上一次刷新比,只列明显的)
|
|
1375
|
+
* 选一个指标 → 每个插件一行横条,按名次排;我的产品标出第几、和第 1 名 / 下一名差多少
|
|
1376
|
+
* 宽屏:下面是完整表格(每个插件一列);窄屏:点哪个插件,下面列出它的全部数据
|
|
1377
|
+
*/
|
|
1378
|
+
const WD_METRIC_KEY = 'dsh-pick-wd-metric-v1'
|
|
1379
|
+
let WD_METRIC = (() => { try { return localStorage.getItem(WD_METRIC_KEY) || 'w' } catch { return 'w' } })()
|
|
1380
|
+
let WD_SEL = null
|
|
1381
|
+
let WD = null // { recs, rows }:这次画的数据,切指标、点插件时不用重算
|
|
1382
|
+
|
|
1383
|
+
// kind:count 数量(对数刻度、差距按比例说)· pct 百分比(差距按百分点)· rank 名次 · days 天数(都是越小越好)
|
|
1384
|
+
const WD_METRICS = [
|
|
1385
|
+
{ k: 'w', label: '周下载', get: r => r.w, fmt: num, snap: 'w' },
|
|
1386
|
+
{ k: 'base', label: '日常基线', get: r => (r.deep ? r.deep.base : null), fmt: v => `${num(v)}/天`, snap: 'base' },
|
|
1387
|
+
{ k: 'growth', label: '环比', get: r => (r.deep ? r.deep.growth : null), fmt: pct, kind: 'pct' },
|
|
1388
|
+
{ k: 'm', label: '月下载', get: r => r.m, fmt: num },
|
|
1389
|
+
{ k: 'tot', label: '累计下载', get: r => r.total, fmt: num },
|
|
1390
|
+
{ k: 's', label: '星标', get: r => (r.gh ? r.gh.s : null), fmt: num, snap: 's', abs: true },
|
|
1391
|
+
{ k: 'orank', label: '综合榜名次', get: (r, n) => angleRank(n, 'rec'), fmt: v => `#${num(v)}`, kind: 'rank', snap: 'orank' },
|
|
1392
|
+
{ k: 'rank', label: 'npm 总榜', get: r => r.rank, fmt: v => `#${num(v)}`, kind: 'rank', snap: 'rank' },
|
|
1393
|
+
{ k: 'age', label: '最近发版', get: r => releaseAge(r), fmt: ageText, kind: 'days' },
|
|
1394
|
+
]
|
|
1395
|
+
const lowerBetter = m => m.kind === 'rank' || m.kind === 'days'
|
|
1396
|
+
|
|
1397
|
+
/** 距离最近一次发版几天:有去噪数据用它的,没有用目录里最新版的发布时间 */
|
|
1398
|
+
function releaseAge(r) {
|
|
1399
|
+
if (r.deep && r.deep.age != null) return r.deep.age
|
|
1400
|
+
return r.t ? daysSince(String(r.t).slice(0, 10)) : null
|
|
1401
|
+
}
|
|
1402
|
+
|
|
1403
|
+
/** a 比 b:差多少(给「落后第 1 名 …」「领先下一名 …」用) */
|
|
1404
|
+
function gapText(m, a, b) {
|
|
1405
|
+
const d = Math.abs(a - b)
|
|
1406
|
+
if (m.kind === 'rank') return `${num(d)} 名`
|
|
1407
|
+
if (m.kind === 'days') return `${num(d)} 天`
|
|
1408
|
+
if (m.kind === 'pct') return `${Math.round(d * 100)} 个百分点`
|
|
1409
|
+
if (!b) return num(d)
|
|
1410
|
+
const ratio = a / b
|
|
1411
|
+
if (ratio >= 2) return `是它的 ${ratio >= 10 ? Math.round(ratio) : ratio.toFixed(1)} 倍`
|
|
1412
|
+
return ratio >= 1 ? `多 ${Math.round((ratio - 1) * 100)}%` : `少 ${Math.round((1 - ratio) * 100)}%`
|
|
1413
|
+
}
|
|
1414
|
+
|
|
1344
1415
|
function renderWatchDetail(list) {
|
|
1345
1416
|
const sec = $('#secWatchDetail')
|
|
1346
|
-
if (!list.length) { sec.classList.add('hidden'); return }
|
|
1417
|
+
if (!list.length) { sec.classList.add('hidden'); WD = null; return }
|
|
1347
1418
|
sec.classList.remove('hidden')
|
|
1348
|
-
$('#wdAsOf').textContent = LIVE.at ? `· ${new Date(LIVE.at).toLocaleString()} 刷新` : '· 还没刷新过,先显示目录数据'
|
|
1349
1419
|
ANGLE_ORDER = new Map()
|
|
1420
|
+
$('#wdAsOf').textContent = LIVE.at ? `· ${new Date(LIVE.at).toLocaleString()} 刷新` : '· 还没刷新过,先显示目录数据'
|
|
1350
1421
|
const recs = list.map(n => ({ n, r: watchRec(n) }))
|
|
1351
|
-
$('#wdHead').innerHTML = '<tr><th>指标</th>' + recs.map(({ n, r }, i) =>
|
|
1352
|
-
`<th><i style="background:${colorOf(i)}"></i>${esc((r && r.label) || n)}</th>`).join('') + '</tr>'
|
|
1353
1422
|
const ANG = { rec: '综合', use: '使用', rep: '口碑', stable: '稳定', rise: '增速' }
|
|
1354
1423
|
const cell = (r, fn) => (r ? fn(r) : '—')
|
|
1355
1424
|
const rows = [
|
|
@@ -1380,27 +1449,138 @@ function renderWatchDetail(list) {
|
|
|
1380
1449
|
['分类排名', ({ r }) => cell(r, x => (x.crank ? `${esc(x.cat)} #${num(x.crank)}` : '—'))],
|
|
1381
1450
|
['综合榜排名', ({ n, r }) => cell(r, () => {
|
|
1382
1451
|
const parts = Object.entries(ANG).map(([a, label]) => [label, angleRank(n, a)]).filter(([, v]) => v)
|
|
1383
|
-
|
|
1452
|
+
const ch = changeOf(n, 'orank', angleRank(n, 'rec'), { lowerIsBetter: true, asPct: false })
|
|
1453
|
+
return parts.length ? parts.map(([l, v]) => `${l} #${num(v)}`).join('<br>') + ch : '<span style="color:var(--t3)">没进综合榜</span>'
|
|
1384
1454
|
})],
|
|
1385
1455
|
['综合推荐分', ({ n, r }) => cell(r, x => (x.sc != null ? `${x.sc}${changeOf(n, 'sc', x.sc, { asPct: false })}` : '—'))],
|
|
1386
1456
|
['收录于', ({ r }) => cell(r, x => (x.src && x.src.length ? srcChips(x.src, { short: true }) : '—'))],
|
|
1387
1457
|
]
|
|
1458
|
+
WD = { recs, rows }
|
|
1459
|
+
const mineNow = mine()
|
|
1460
|
+
if (!list.includes(WD_SEL)) WD_SEL = list.find(n => mineNow.includes(n)) || list[0]
|
|
1461
|
+
if (!WD_METRICS.some(m => m.k === WD_METRIC)) WD_METRIC = 'w'
|
|
1462
|
+
renderWdChanges(list)
|
|
1463
|
+
paintWd()
|
|
1464
|
+
}
|
|
1465
|
+
|
|
1466
|
+
/** 选中的指标、选中的插件变了:重画横条、单个插件、表格(数据不重算) */
|
|
1467
|
+
function paintWd() {
|
|
1468
|
+
if (!WD) return
|
|
1469
|
+
const { recs, rows } = WD
|
|
1470
|
+
const mineNow = mine()
|
|
1471
|
+
const nameOf = ({ n, r }) => (r && r.label) || watchName(n)
|
|
1472
|
+
const selIdx = recs.findIndex(x => x.n === WD_SEL)
|
|
1473
|
+
|
|
1474
|
+
// 指标选单
|
|
1475
|
+
$('#wdMetrics').innerHTML = WD_METRICS.map(m => `<button data-wdm="${m.k}" class="${m.k === WD_METRIC ? 'on' : ''}" role="tab" aria-selected="${m.k === WD_METRIC}">${m.label}</button>`).join('')
|
|
1476
|
+
|
|
1477
|
+
// 排名横条
|
|
1478
|
+
const m = WD_METRICS.find(x => x.k === WD_METRIC)
|
|
1479
|
+
const items = recs.map((x, i) => ({ ...x, i, v: x.r ? m.get(x.r, x.n) : null }))
|
|
1480
|
+
const has = items.filter(x => x.v != null && Number.isFinite(x.v))
|
|
1481
|
+
.sort((a, b) => (lowerBetter(m) ? a.v - b.v : b.v - a.v))
|
|
1482
|
+
const none = items.filter(x => !has.includes(x))
|
|
1483
|
+
// 横条长短:数量用对数(差几个数量级),名次、天数越小越长,百分比按原值;归一到 8%~100%
|
|
1484
|
+
const score = v => (m.kind === 'pct' ? v : lowerBetter(m) ? -Math.log1p(v) : Math.log1p(Math.max(v, 0)))
|
|
1485
|
+
const ss = has.map(x => score(x.v))
|
|
1486
|
+
const lo = Math.min(...ss), hi = Math.max(...ss)
|
|
1487
|
+
const len = v => (hi === lo ? 100 : 8 + (score(v) - lo) / (hi - lo) * 92)
|
|
1488
|
+
const row = (x, k) => {
|
|
1489
|
+
const isMine = mineNow.includes(x.n)
|
|
1490
|
+
// 横条里只标有变化的(「持平」每行都写太吵)
|
|
1491
|
+
const raw = m.snap ? changeOf(x.n, m.snap, x.v, { lowerIsBetter: lowerBetter(m), asPct: !(m.abs || m.kind === 'rank') }) : ''
|
|
1492
|
+
const ch = raw.includes('flat') ? '' : raw.replace('较上次 ', '')
|
|
1493
|
+
return `<div class="wb${x.n === WD_SEL ? ' sel' : ''}${isMine ? ' mine' : ''}${x.v == null ? ' none' : ''}" data-wd="${esc(x.n)}" role="button" tabindex="0" title="点一下看 ${esc(nameOf(x))} 的全部数据">` +
|
|
1494
|
+
`<div class="wbt"><span class="wbr">${k != null ? k + 1 : '—'}</span>` +
|
|
1495
|
+
`<span class="wbn"><i style="background:${colorOf(x.i)}"></i>${esc(nameOf(x))}${isMine ? '<span class="mtag">我的</span>' : ''}</span>` +
|
|
1496
|
+
`<span class="wbv">${x.v != null ? m.fmt(x.v) : '—'}${ch}</span></div>` +
|
|
1497
|
+
(x.v != null ? `<div class="wbb"><i style="width:${len(x.v).toFixed(1)}%;background:${colorOf(x.i)}"></i></div>` : '') + '</div>'
|
|
1498
|
+
}
|
|
1499
|
+
$('#wdBars').innerHTML = has.map((x, k) => row(x, k)).join('') + none.map(x => row(x, null)).join('')
|
|
1500
|
+
|
|
1501
|
+
// 我的产品:第几、落后第 1 名多少、领先下一名多少
|
|
1502
|
+
const mineLines = has.map((x, k) => ({ x, k })).filter(({ x }) => mineNow.includes(x.n)).map(({ x, k }) => {
|
|
1503
|
+
const top = has[0]
|
|
1504
|
+
const next = has[k + 1]
|
|
1505
|
+
const parts = [`<b>★ ${esc(nameOf(x))}</b> ${m.label}排第 <b>${k + 1}</b> / ${has.length}`]
|
|
1506
|
+
if (k > 0) parts.push(`落后第 1 名 ${esc(nameOf(top))} ${gapText(m, x.v, top.v)}`)
|
|
1507
|
+
else if (has.length > 1) parts.push('在你监控的插件里最好')
|
|
1508
|
+
if (next) parts.push(`领先下一名 ${esc(nameOf(next))} ${gapText(m, x.v, next.v)}`)
|
|
1509
|
+
return `<div>${parts.join(';')}</div>`
|
|
1510
|
+
})
|
|
1511
|
+
$('#wdMine').innerHTML = mineLines.join('')
|
|
1512
|
+
$('#wdMine').classList.toggle('hidden', !mineLines.length)
|
|
1513
|
+
|
|
1514
|
+
// 宽屏的表格:每个插件一列,选中的那列高亮
|
|
1515
|
+
const sel = i => (i === selIdx ? ' class="sel"' : '')
|
|
1516
|
+
$('#wdHead').innerHTML = '<tr><th>指标</th>' + recs.map((x, i) =>
|
|
1517
|
+
`<th${sel(i)}>${starBtn(x.n)}<i style="background:${colorOf(i)}"></i>${esc(nameOf(x))}</th>`).join('') + '</tr>'
|
|
1388
1518
|
$('#wdBody').innerHTML = rows.map(([label, fn]) => (fn
|
|
1389
|
-
? `<tr><td>${label}</td>${recs.map((x, i) => `<td>${fn(x, i)}</td>`).join('')}</tr>`
|
|
1519
|
+
? `<tr><td>${label}</td>${recs.map((x, i) => `<td${sel(i)}>${fn(x, i)}</td>`).join('')}</tr>`
|
|
1390
1520
|
: `<tr class="grp"><td colspan="${recs.length + 1}">${label}</td></tr>`)).join('')
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1521
|
+
|
|
1522
|
+
// 窄屏:选中的那个插件的全部数据
|
|
1523
|
+
if (selIdx >= 0) {
|
|
1524
|
+
const x = recs[selIdx]
|
|
1525
|
+
$('#wdOne').innerHTML = `<div class="hd">${starBtn(x.n)}<i style="background:${colorOf(selIdx)}"></i>${esc(nameOf(x))}` +
|
|
1526
|
+
`<span style="color:var(--t3);font-size:11px;font-weight:500;margin-left:auto">点上面的插件换一个看</span></div>` +
|
|
1527
|
+
rows.map(([label, fn]) => (fn ? `<div class="kv"><span class="k">${label}</span><span class="v">${fn(x, selIdx)}</span></div>` : `<div class="grp">${label}</div>`)).join('')
|
|
1528
|
+
}
|
|
1396
1529
|
WD_COUNT = recs.length
|
|
1397
1530
|
layoutWatchDetail()
|
|
1398
1531
|
}
|
|
1399
1532
|
|
|
1533
|
+
/** 「这次的变化」:最近两次刷新的快照比,只列明显的(发了新版、下载涨跌两成以上、星标、名次变化),我的产品排前面 */
|
|
1534
|
+
function renderWdChanges(list) {
|
|
1535
|
+
const box = $('#wdChanges')
|
|
1536
|
+
const hist = loadHistory()
|
|
1537
|
+
const mineNow = mine()
|
|
1538
|
+
const items = []
|
|
1539
|
+
let since = null
|
|
1540
|
+
for (const n of list) {
|
|
1541
|
+
const h = hist[n] || []
|
|
1542
|
+
const prev = baseSnap(h)
|
|
1543
|
+
if (!prev) continue
|
|
1544
|
+
const cur = h[h.length - 1]
|
|
1545
|
+
since = since == null || prev.t < since ? prev.t : since
|
|
1546
|
+
const who = `<b>${esc(watchName(n))}</b>${mineNow.includes(n) ? '<span class="mtag">我的</span>' : ''}`
|
|
1547
|
+
const its = []
|
|
1548
|
+
const add = (text, good) => its.push(`<span class="it">${text.replace('{c}', good == null ? '' : good ? 'up' : 'down')}</span>`)
|
|
1549
|
+
if (prev.v && cur.v && prev.v !== cur.v) add(`发了新版 v${esc(cur.v)}`)
|
|
1550
|
+
const pctCh = (key, label) => {
|
|
1551
|
+
if (!prev[key] || cur[key] == null) return
|
|
1552
|
+
const r = (cur[key] - prev[key]) / prev[key]
|
|
1553
|
+
if (Math.abs(r) >= 0.2) add(`${label} <span class="{c}">${r > 0 ? '+' : ''}${Math.round(r * 100)}%</span>`, r > 0)
|
|
1554
|
+
}
|
|
1555
|
+
pctCh('w', '周下载')
|
|
1556
|
+
pctCh('base', '日常基线')
|
|
1557
|
+
if (prev.s != null && cur.s != null && cur.s !== prev.s) add(`星标 <span class="{c}">${cur.s > prev.s ? '+' : ''}${num(cur.s - prev.s)}</span>`, cur.s > prev.s)
|
|
1558
|
+
const rankCh = (key, label, min) => {
|
|
1559
|
+
if (prev[key] == null || cur[key] == null) return
|
|
1560
|
+
const d = cur[key] - prev[key]
|
|
1561
|
+
if (Math.abs(d) >= min) add(`${label} <span class="{c}">${d < 0 ? '升' : '降'} ${num(Math.abs(d))} 名</span>`, d < 0)
|
|
1562
|
+
}
|
|
1563
|
+
rankCh('orank', '综合榜', 3)
|
|
1564
|
+
rankCh('rank', 'npm 总榜', 5)
|
|
1565
|
+
// 一个插件一行
|
|
1566
|
+
if (its.length) items.push({ mine: mineNow.includes(n), n: its.length, html: `<div class="ln">${who}:${its.join('')}</div>` })
|
|
1567
|
+
}
|
|
1568
|
+
if (since == null) { box.classList.add('hidden'); return }
|
|
1569
|
+
box.classList.remove('hidden')
|
|
1570
|
+
const when = new Date(since).toLocaleString()
|
|
1571
|
+
if (!items.length) {
|
|
1572
|
+
box.className = 'wdch quiet'
|
|
1573
|
+
box.innerHTML = `和上次刷新(${esc(when)})比,没有明显变化。`
|
|
1574
|
+
return
|
|
1575
|
+
}
|
|
1576
|
+
box.className = 'wdch'
|
|
1577
|
+
items.sort((a, b) => b.mine - a.mine)
|
|
1578
|
+
box.innerHTML = `<b>这次的变化</b><span style="color:var(--t3)">(和 ${esc(when)} 的数据比)</span>` + items.map(x => x.html).join('')
|
|
1579
|
+
}
|
|
1580
|
+
|
|
1400
1581
|
/**
|
|
1401
|
-
*
|
|
1402
|
-
*
|
|
1403
|
-
* 拖动侧栏宽度时跟着切换
|
|
1582
|
+
* 监控详情选版式:右侧栏放得下整张表(每个插件一列)就用表格,放不下就在横条下面列出选中插件的全部数据。
|
|
1583
|
+
* 直接量表格的实际宽度:插件名长短、有没有「较上次」都会影响列宽,估不准。拖动侧栏宽度时跟着切换
|
|
1404
1584
|
*/
|
|
1405
1585
|
let WD_COUNT = 0
|
|
1406
1586
|
function layoutWatchDetail() {
|
|
@@ -1409,7 +1589,7 @@ function layoutWatchDetail() {
|
|
|
1409
1589
|
wrap.classList.remove('hidden')
|
|
1410
1590
|
const fits = wrap.scrollWidth <= wrap.clientWidth + 1
|
|
1411
1591
|
wrap.classList.toggle('hidden', !fits)
|
|
1412
|
-
$('#
|
|
1592
|
+
$('#wdOne').classList.toggle('hidden', fits)
|
|
1413
1593
|
}
|
|
1414
1594
|
if (typeof ResizeObserver !== 'undefined') {
|
|
1415
1595
|
let lastW = 0
|
|
@@ -1420,6 +1600,22 @@ if (typeof ResizeObserver !== 'undefined') {
|
|
|
1420
1600
|
}
|
|
1421
1601
|
// 保险:有的环境(后台页、老内核)不触发 ResizeObserver,窗口大小变了也量一次;切到「我的监控」时也会量
|
|
1422
1602
|
window.addEventListener('resize', () => layoutWatchDetail())
|
|
1603
|
+
$('#secWatchDetail').addEventListener('click', e => {
|
|
1604
|
+
const mt = e.target.closest('[data-wdm]')
|
|
1605
|
+
if (mt) {
|
|
1606
|
+
WD_METRIC = mt.dataset.wdm
|
|
1607
|
+
try { localStorage.setItem(WD_METRIC_KEY, WD_METRIC) } catch { /* 记不住就算了 */ }
|
|
1608
|
+
paintWd()
|
|
1609
|
+
return
|
|
1610
|
+
}
|
|
1611
|
+
if (e.target.closest('[data-mine]')) return // 星标由 document 上的委托处理
|
|
1612
|
+
const row = e.target.closest('[data-wd]')
|
|
1613
|
+
if (row) { WD_SEL = row.dataset.wd; paintWd() }
|
|
1614
|
+
})
|
|
1615
|
+
$('#secWatchDetail').addEventListener('keydown', e => {
|
|
1616
|
+
const row = e.target.closest('[data-wd]')
|
|
1617
|
+
if (row && (e.key === 'Enter' || e.key === ' ')) { e.preventDefault(); WD_SEL = row.dataset.wd; paintWd() }
|
|
1618
|
+
})
|
|
1423
1619
|
|
|
1424
1620
|
/**
|
|
1425
1621
|
* 用户输入 → 监控名:目录里的包名直接用;GitHub 地址或 owner/repo:目录里有发到 npm 的就记包名,
|
|
@@ -1503,7 +1699,6 @@ function renderWatch() {
|
|
|
1503
1699
|
if (!list.length) {
|
|
1504
1700
|
$('#watchAdd').classList.remove('hidden') // 空的时候直接摆出输入框
|
|
1505
1701
|
host.innerHTML = '<div class="empty">还没有监控的插件。点上面的「+ 添加」输入插件名,或在「选插件」、排行榜里点彩色的 +。</div>'
|
|
1506
|
-
$('#watchChart').innerHTML = ''
|
|
1507
1702
|
return
|
|
1508
1703
|
}
|
|
1509
1704
|
|
|
@@ -1520,7 +1715,7 @@ function renderWatch() {
|
|
|
1520
1715
|
const name = r ? esc(r.label || n) : esc(n)
|
|
1521
1716
|
const ver = r && r.v ? ` <span class="ver">v${esc(r.v)}</span>` : ''
|
|
1522
1717
|
const live = r && r.live ? '<i class="livedot" title="实时数据:刚从 npm / GitHub 查的"></i>' : ''
|
|
1523
|
-
const nameCell = `<span class="mc nm" title="${name}${r && r.v ? ' v' + esc(r.v) : ''}">${live}${name}${ver}</span>`
|
|
1718
|
+
const nameCell = `<span class="mc nm" title="${name}${r && r.v ? ' v' + esc(r.v) : ''}">${starBtn(n)}${live}${name}${ver}</span>`
|
|
1524
1719
|
const acts = `<span class="mc acts">${r ? linkBtns(r, { icon: true }) : ''}<button class="x" data-rm="${esc(n)}" title="从我的监控移除" aria-label="移除 ${name}">×</button></span>`
|
|
1525
1720
|
if (!r) return `<div class="mrow">${nameCell}<span class="mc span">不在目录中,点「刷新」去 npm 查</span>${acts}</div>`
|
|
1526
1721
|
const d = r.deep
|
|
@@ -1545,17 +1740,6 @@ function renderWatch() {
|
|
|
1545
1740
|
b.addEventListener('click', () => saveWatch(watch().filter(x => x !== b.dataset.rm)) || renderWatch()))
|
|
1546
1741
|
|
|
1547
1742
|
renderWatchDetail(list)
|
|
1548
|
-
|
|
1549
|
-
// 对数刻度横条图
|
|
1550
|
-
const rows = list.map(watchRec).filter(r => r && r.w != null)
|
|
1551
|
-
const max = Math.max(...rows.map(r => r.w), 1)
|
|
1552
|
-
$('#watchChart').innerHTML = rows.map((r, i) => {
|
|
1553
|
-
const w = Math.max(Math.log10(r.w + 1) / Math.log10(max + 1) * 100, 1.5)
|
|
1554
|
-
return `<div class="hrow" style="display:grid;grid-template-columns:minmax(80px,38%) 1fr auto;align-items:center;gap:10px;padding:6px 0">` +
|
|
1555
|
-
`<div style="font-size:12px;color:var(--t2);text-align:right;white-space:nowrap;overflow:hidden;text-overflow:ellipsis"><i style="display:inline-block;width:8px;height:8px;border-radius:2px;background:${colorOf(i)};margin-right:6px"></i>${esc(r.n)}${r.rank ? ` <span style="color:var(--t3);font-size:10px">#${num(r.rank)}</span>` : ''}</div>` +
|
|
1556
|
-
`<div style="height:14px;background:var(--soft);border-radius:4px"><div style="height:100%;width:${w}%;background:${colorOf(i)};border-radius:4px"></div></div>` +
|
|
1557
|
-
`<div style="font-size:12px;font-weight:650;text-align:right">${num(r.w)}</div></div>`
|
|
1558
|
-
}).join('')
|
|
1559
1743
|
}
|
|
1560
1744
|
|
|
1561
1745
|
/* ---------------- 导出结论(网页版) ---------------- */
|