dsh-pick 0.4.4 → 0.5.1
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 +21 -2
- package/bin/dsh-pick.js +2 -3
- package/data/catalog.json +1 -1
- package/lib/boards.js +156 -0
- package/lib/engine.js +124 -14
- package/lib/github.js +123 -0
- package/lib/metrics.js +12 -8
- package/package.json +1 -1
- package/plugin/client.js +1 -1
- package/plugin/index.js +10 -12
- package/plugin/tools.js +33 -13
- package/web/panel.html +49 -16
- package/web/panel.js +251 -41
package/web/panel.js
CHANGED
|
@@ -61,13 +61,14 @@ function askAI(text) {
|
|
|
61
61
|
function factLine(r) {
|
|
62
62
|
const d = r.deep
|
|
63
63
|
return [
|
|
64
|
-
`周下载 ${num(r.w)}
|
|
65
|
-
d ? `日常基线 ${num(d.base)}` : '无去噪指标(周下载 Top 之外)',
|
|
64
|
+
r.w != null ? `周下载 ${num(r.w)}` : '',
|
|
65
|
+
d ? `日常基线 ${num(d.base)}` : (r.w != null ? '无去噪指标(周下载 Top 之外)' : '只在 GitHub,没有 npm 数据'),
|
|
66
66
|
d ? `近 7 日环比 ${pct(d.growth)}` : '',
|
|
67
67
|
d && d.cadence != null ? `${d.cadence} 天/版` : '',
|
|
68
68
|
d && d.age != null ? `${d.age} 天前更新` : '',
|
|
69
69
|
d ? `健康度 ${d.s}` : '',
|
|
70
70
|
r.rank ? `总榜 #${r.rank}` : '',
|
|
71
|
+
r.gh ? [`GitHub ★${r.gh.s}`, r.gh.f != null ? `Fork ${r.gh.f}` : '', r.gh.i != null ? `未关闭 issue/PR ${r.gh.i}` : '', r.gh.p ? `最近提交 ${r.gh.p}` : '', r.gh.a ? '已归档' : ''].filter(Boolean).join('、') : '',
|
|
71
72
|
].filter(Boolean).join(' · ')
|
|
72
73
|
}
|
|
73
74
|
const needLine = () => {
|
|
@@ -112,6 +113,7 @@ function askVerdict() {
|
|
|
112
113
|
|
|
113
114
|
function askWatch() {
|
|
114
115
|
const rows = watch().map(watchRec).filter(Boolean)
|
|
116
|
+
rows.forEach(r => { if (r.label) r.n = r.label })
|
|
115
117
|
const live = LIVE.at ? `(npm 实时数据,${new Date(LIVE.at).toLocaleString()} 刷新;下载量含 CI / 镜像流量,不等于用户数)` : dataAsOf()
|
|
116
118
|
return [
|
|
117
119
|
`帮我看看我关注的这些 DSH 插件最近怎么样${live}:`,
|
|
@@ -183,6 +185,8 @@ function installCheck(r) {
|
|
|
183
185
|
// 已经装不了(没 bundle、终端版)就不说「兼容」:版本对得上不等于装得上,两句放一起让人困惑
|
|
184
186
|
good.push(`兼容你的 DSH${HOST_VERSION ? ' ' + HOST_VERSION : ''}`)
|
|
185
187
|
}
|
|
188
|
+
if (r.gh && r.gh.a) warn.push('GitHub 仓库已归档,作者不再维护')
|
|
189
|
+
else if (r.gh && daysSince(r.gh.p) > 180) warn.push(`仓库 ${Math.round(daysSince(r.gh.p) / 30)} 个月没有提交`)
|
|
186
190
|
const same = sameKindInstalled(r)
|
|
187
191
|
if (same.length) warn.push(`你已装同类:${same.join('、')}`)
|
|
188
192
|
return { ok, warn, good }
|
|
@@ -266,7 +270,7 @@ function linkBtns(rec, { icon = false } = {}) {
|
|
|
266
270
|
if (rec.ghUrl) {
|
|
267
271
|
h += `<a class="${cls}" href="${esc(rec.ghUrl)}" target="_blank" rel="noopener" title="GitHub:${esc(rec.ghUrl)}" aria-label="GitHub">${GH_SVG}${icon ? '' : 'GitHub'}</a>`
|
|
268
272
|
}
|
|
269
|
-
h += `<a class="${cls}" href="${esc(npm)}" target="_blank" rel="noopener" title="npm:${esc(npm)}" aria-label="npm">${NPM_SVG}${icon ? '' : 'npm'}</a>`
|
|
273
|
+
if (rec.n) h += `<a class="${cls}" href="${esc(npm)}" target="_blank" rel="noopener" title="npm:${esc(npm)}" aria-label="npm">${NPM_SVG}${icon ? '' : 'npm'}</a>`
|
|
270
274
|
return h
|
|
271
275
|
}
|
|
272
276
|
|
|
@@ -322,14 +326,18 @@ async function boot() {
|
|
|
322
326
|
const deepN = Object.values(CAT.packages).filter(p => p.deep).length
|
|
323
327
|
$('#meta').innerHTML =
|
|
324
328
|
`目录 <b>${num(CAT.total)}</b> 个插件 · 去噪指标 <b>${num(deepN)}</b> 个<br>` +
|
|
325
|
-
`数据截止 <b>${CAT.anchor}</b>(npm
|
|
329
|
+
`数据截止 <b>${CAT.anchor}</b>(npm 最近有数据的一天)`
|
|
326
330
|
|
|
331
|
+
const gapNote = CAT.gaps && CAT.gaps.length
|
|
332
|
+
? `<br><b>npm 缺数据的日子:</b>${CAT.gaps.map(esc).join('、')}(那几天全 npm 的下载统计都是 0,是 npm 自己没出数据),不参与日常基线和环比的计算。`
|
|
333
|
+
: ''
|
|
327
334
|
$('#foot').innerHTML =
|
|
328
335
|
`<b>口径:</b>下载量含 CI、镜像、爬虫等非人类流量,不等于用户数;<b>日常基线</b>= 扣掉版本发布日与次日后的每日中位数,比原始下载量更接近真实使用量。<br>` +
|
|
329
336
|
`<b>覆盖范围:</b>npm 上带 <code>dsh-plugin</code> 关键字的 ${num(CAT.total)} 个包;去噪指标只算了周下载 Top ${num(deepN)}。目录每天重建一次,重跑 <code>dsh-pick build</code> 即可。<br>` +
|
|
330
337
|
(IN_DSH
|
|
331
338
|
? `<b>当前结论由本地规则生成</b>(依据就是对比表里的数字)。点各处的「+AI」,把数据发到对话里让 AI 结合你的场景分析;在对话里也可以直接问「哪个插件能做某某」,AI 会自己查这份目录。`
|
|
332
|
-
: `<b>当前结论由本地规则生成</b>(依据就是对比表里的数字)。装上 DSH 插件版后,可以一键交给 AI,结合你的具体场景解释取舍。`)
|
|
339
|
+
: `<b>当前结论由本地规则生成</b>(依据就是对比表里的数字)。装上 DSH 插件版后,可以一键交给 AI,结合你的具体场景解释取舍。`) +
|
|
340
|
+
gapNote
|
|
333
341
|
|
|
334
342
|
await loadInstalled()
|
|
335
343
|
if (IN_DSH) {
|
|
@@ -367,9 +375,16 @@ function bindEvents() {
|
|
|
367
375
|
})
|
|
368
376
|
})
|
|
369
377
|
|
|
378
|
+
document.querySelectorAll('#rankBoard button').forEach(bt => {
|
|
379
|
+
bt.addEventListener('click', () => {
|
|
380
|
+
document.querySelectorAll('#rankBoard button').forEach(x => x.classList.toggle('on', x === bt))
|
|
381
|
+
document.querySelectorAll('#rankFilters .chip').forEach(c => c.classList.toggle('hidden', c.dataset.board !== bt.dataset.b))
|
|
382
|
+
renderRank()
|
|
383
|
+
})
|
|
384
|
+
})
|
|
370
385
|
document.querySelectorAll('#rankFilters .chip').forEach(c => {
|
|
371
386
|
c.addEventListener('click', () => {
|
|
372
|
-
document.querySelectorAll(
|
|
387
|
+
document.querySelectorAll(`#rankFilters .chip[data-board="${c.dataset.board}"]`).forEach(x => x.classList.toggle('on', x === c))
|
|
373
388
|
renderRank()
|
|
374
389
|
})
|
|
375
390
|
})
|
|
@@ -379,6 +394,10 @@ function bindEvents() {
|
|
|
379
394
|
$('#aiVerdict').addEventListener('click', () => picked.length >= 2 && askAI(askVerdict()))
|
|
380
395
|
$('#aiWatch').addEventListener('click', () => watch().length && askAI(askWatch()))
|
|
381
396
|
$('#btnWatchRefresh').addEventListener('click', refreshWatch)
|
|
397
|
+
document.addEventListener('click', e => {
|
|
398
|
+
const b = e.target.closest('[data-watch]')
|
|
399
|
+
if (b) toggleWatch(b.dataset.watch)
|
|
400
|
+
})
|
|
382
401
|
|
|
383
402
|
$('#btnExport').addEventListener('click', exportHtml)
|
|
384
403
|
$('#btnWatch').addEventListener('click', addPickedToWatch)
|
|
@@ -420,9 +439,10 @@ function renderCands(need, { keepCompat = false } = {}) {
|
|
|
420
439
|
`<span>周 <b>${num(rec.w)}</b></span>` +
|
|
421
440
|
`<span>月 <b>${num(rec.m)}</b></span>` +
|
|
422
441
|
(d ? `<span>基线 <b>${num(d.base)}</b></span><span>环比 <b>${pct(d.growth)}</b></span>` : '') +
|
|
442
|
+
(rec.gh ? `<span title="GitHub 星标 · 最近提交 ${esc(rec.gh.p || '—')}">★ <b>${short(rec.gh.s)}</b></span>` : '') +
|
|
423
443
|
`</div>` +
|
|
424
444
|
checkRow(rec) +
|
|
425
|
-
`<div class="links">${linkBtns(rec)}<span class="sp"></span>${installArea(rec)}` +
|
|
445
|
+
`<div class="links">${watchBtn(rec.n)}${linkBtns(rec)}<span class="sp"></span>${installArea(rec)}` +
|
|
426
446
|
(IN_DSH ? `<button class="ai" data-ask title="把这个插件的数据发到对话里问 AI">+AI</button>` : '') +
|
|
427
447
|
`</div>` +
|
|
428
448
|
`</div>`
|
|
@@ -432,7 +452,7 @@ function renderCands(need, { keepCompat = false } = {}) {
|
|
|
432
452
|
if (ask) { e.stopPropagation(); askAI(askCard(rec)); return }
|
|
433
453
|
const inst = e.target.closest('[data-install]')
|
|
434
454
|
if (inst) { e.stopPropagation(); onInstallClick(inst); return }
|
|
435
|
-
if (e.target.closest('a')) return
|
|
455
|
+
if (e.target.closest('a, [data-watch]')) return
|
|
436
456
|
togglePick(rec.n)
|
|
437
457
|
})
|
|
438
458
|
host.appendChild(el)
|
|
@@ -462,6 +482,8 @@ const ROWS = [
|
|
|
462
482
|
{ k: 'cad', label: '版本节奏', get: r => r.deep && r.deep.cadence, fmt: r => r == null ? '—' : r + ' 天/版', best: 'min' },
|
|
463
483
|
{ k: 'age', label: '最近更新', get: r => r.deep && r.deep.age, fmt: r => r == null ? '—' : r + ' 天前', best: 'min' },
|
|
464
484
|
{ k: 's', label: '健康度', get: r => r.deep && r.deep.s, fmt: num, best: 'max' },
|
|
485
|
+
{ k: 'gs', label: 'GitHub 星标', get: r => r.gh && r.gh.s, fmt: num, best: 'max' },
|
|
486
|
+
{ k: 'gp', label: '最近提交', get: r => r.gh && daysSince(r.gh.p), fmt: r => r == null ? '—' : ageText(r), best: 'min' },
|
|
465
487
|
]
|
|
466
488
|
|
|
467
489
|
function renderCompare() {
|
|
@@ -571,31 +593,148 @@ function buildCategoryFilter() {
|
|
|
571
593
|
sel.innerHTML = '<option value="">全部分类</option>' + cats.map(c => `<option>${esc(c)}</option>`).join('')
|
|
572
594
|
}
|
|
573
595
|
|
|
596
|
+
/** 距今几天(ISO 日期);没有日期返回 null */
|
|
597
|
+
function daysSince(iso) {
|
|
598
|
+
if (!iso) return null
|
|
599
|
+
return Math.max(0, Math.floor((Date.now() - Date.parse(iso + 'T00:00:00Z')) / 86400000))
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
/** 1234 → 1.2k:星标、Fork 这种数放在窄列里 */
|
|
603
|
+
const short = n => (n == null ? '—' : n >= 10000 ? Math.round(n / 1000) + 'k' : n >= 1000 ? (n / 1000).toFixed(1).replace(/\.0$/, '') + 'k' : String(n))
|
|
604
|
+
|
|
605
|
+
function rankBoard() {
|
|
606
|
+
return document.querySelector('#rankBoard button.on').dataset.b
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
/** 官方 / 社区 / 商店榜:数据来自别人维护的目录,每个榜只存头部 */
|
|
610
|
+
function renderOuterBoard(board) {
|
|
611
|
+
const data = CAT.boards && CAT.boards[board]
|
|
612
|
+
const CAPS = {
|
|
613
|
+
official: '来自 DeepSeek 官方包 dsh-official-bundles:官方提供的可选、按需插件。按周下载排,数字含 DSH 安装时的自动拉取,不等于主动选择的人数。',
|
|
614
|
+
community: `来自社区目录 awesome-dsh-plugin${data ? `(共 ${num(data.total)} 个${data.updated ? `,${esc(data.updated)} 更新` : ''})` : ''},不是 DeepSeek 官方。下载是近 30 天。`,
|
|
615
|
+
shop: `来自第三方插件商店 dsh-plugin-shop${data ? `(共 ${num(data.total)} 个)` : ''},不是 DeepSeek 官方,商店不提供下载量。`,
|
|
616
|
+
}
|
|
617
|
+
$('#rankCap').textContent = CAPS[board]
|
|
618
|
+
const empty = text => {
|
|
619
|
+
$('#rankHead').innerHTML = ''
|
|
620
|
+
$('#rankBody').innerHTML = `<tr><td class="empty">${text}</td></tr>`
|
|
621
|
+
}
|
|
622
|
+
if (!data || !data.rows.length) return empty('还没有这个榜单的数据(每日更新取到后就有)。')
|
|
623
|
+
|
|
624
|
+
const nameCell = r => `<td class="nm">${esc(r.t || r.n || r.name)}${r.v ? ` <span style="color:var(--t3);font-weight:400;font-size:11px">v${esc(r.v)}</span>` : ''}` +
|
|
625
|
+
(r.t ? `<div class="sub">${esc(r.n)}</div>` : '') +
|
|
626
|
+
(!r.n ? '<div class="sub">只在 GitHub,没发到 npm</div>' : '') +
|
|
627
|
+
(r.d ? `<div class="sub desc" title="${esc(r.d)}">${esc(r.d)}</div>` : '') + `</td>`
|
|
628
|
+
const actions = r => `<td class="lks">${watchBtn(watchKey(r))}${linkBtns({ n: r.n || '', ghUrl: r.repo || '' }, { icon: true })}</td>`
|
|
629
|
+
|
|
630
|
+
if (board === 'official') {
|
|
631
|
+
const rows = data.rows.slice().sort((x, y) => (y.w || 0) - (x.w || 0))
|
|
632
|
+
$('#rankHead').innerHTML = '<tr><th style="width:44px">#</th><th>插件</th><th class="r">周下载</th><th></th></tr>'
|
|
633
|
+
$('#rankBody').innerHTML = rows.map((r, i) => `<tr><td style="color:var(--t3)">${i + 1}</td>${nameCell(r)}<td class="r"><b>${num(r.w)}</b></td>${actions(r)}</tr>`).join('')
|
|
634
|
+
return
|
|
635
|
+
}
|
|
636
|
+
|
|
637
|
+
const metric = document.querySelector(`#rankFilters .chip.on[data-board="${board}"]`).dataset.m
|
|
638
|
+
let rows = data.rows.filter(r => r[metric] != null)
|
|
639
|
+
.sort((x, y) => (y[metric] > x[metric] ? 1 : y[metric] < x[metric] ? -1 : 0))
|
|
640
|
+
// 按星标排时一个仓库只留一行(优先留发到 npm 的那条),不然同仓库的条目数字一样、刷屏
|
|
641
|
+
if (metric === 's') {
|
|
642
|
+
const best = new Map()
|
|
643
|
+
for (const r of rows) {
|
|
644
|
+
const k = (r.repo || r.name).toLowerCase()
|
|
645
|
+
if (!best.has(k) || (!best.get(k).n && r.n)) best.set(k, r)
|
|
646
|
+
}
|
|
647
|
+
const keep = new Set(best.values())
|
|
648
|
+
rows = rows.filter(r => keep.has(r))
|
|
649
|
+
}
|
|
650
|
+
rows = rows.slice(0, 40)
|
|
651
|
+
const hasDl = board === 'community'
|
|
652
|
+
$('#rankHead').innerHTML = '<tr><th style="width:44px">#</th><th>插件</th><th class="r">★ 星标</th>' +
|
|
653
|
+
(hasDl ? '<th class="r" title="近 30 天">下载</th>' : '') + '<th class="r">收录</th><th></th></tr>'
|
|
654
|
+
const strong = (on, t) => (on ? `<b>${t}</b>` : t)
|
|
655
|
+
$('#rankBody').innerHTML = rows.map((r, i) => `<tr><td style="color:var(--t3)">${i + 1}</td>${nameCell(r)}` +
|
|
656
|
+
`<td class="r">${strong(metric === 's', num(r.s))}</td>` +
|
|
657
|
+
(hasDl ? `<td class="r">${strong(metric === 'dl', num(r.dl))}</td>` : '') +
|
|
658
|
+
`<td class="r">${strong(metric === 'added', r.added ? esc(r.added.slice(5)) : '—')}</td>${actions(r)}</tr>`).join('')
|
|
659
|
+
}
|
|
660
|
+
|
|
574
661
|
function renderRank() {
|
|
575
|
-
const
|
|
662
|
+
const board = rankBoard()
|
|
663
|
+
const onChip = document.querySelector(`#rankFilters .chip.on[data-board="${board}"]`)
|
|
664
|
+
const metric = onChip ? onChip.dataset.m : ''
|
|
576
665
|
const cat = $('#rankCat').value
|
|
577
|
-
const
|
|
666
|
+
const inCat = r => !cat || r.cat === cat
|
|
667
|
+
const nameCell = r => `<td class="nm">${esc(r.n)} <span style="color:var(--t3);font-weight:400;font-size:11px">v${esc(r.v)}</span></td>`
|
|
668
|
+
const b = (on, text) => (on ? `<b>${text}</b>` : text)
|
|
669
|
+
// 分类是 npm 目录自己算的,别的榜没有这个字段
|
|
670
|
+
$('#rankCat').classList.toggle('hidden', board !== 'npm' && board !== 'gh')
|
|
671
|
+
|
|
672
|
+
if (board === 'official' || board === 'community' || board === 'shop') {
|
|
673
|
+
renderOuterBoard(board)
|
|
674
|
+
return
|
|
675
|
+
}
|
|
578
676
|
|
|
579
|
-
|
|
677
|
+
if (board === 'gh') {
|
|
678
|
+
$('#rankCap').textContent = '按 GitHub 仓库数据:星标看关注度,最近提交看还有没有人在维护。一个仓库只列一行;仓库填成 DSH 本体的不算。'
|
|
679
|
+
const val = r => metric === 'gs' ? r.gh.s
|
|
680
|
+
: metric === 'gf' ? r.gh.f
|
|
681
|
+
: metric === 'gi' ? r.gh.i
|
|
682
|
+
: -(daysSince(r.gh.p) ?? 1e9) // 最近提交:越近越前
|
|
683
|
+
// 按仓库排:一个仓库只占一行(好些作者把一串插件放在一个仓库里,数据都一样),
|
|
684
|
+
// 用这个仓库里周下载最多的那个插件代表,注明共用的个数
|
|
685
|
+
const byRepo = new Map()
|
|
686
|
+
for (const r of Object.values(CAT.packages)) {
|
|
687
|
+
if (!r.gh || !inCat(r)) continue
|
|
688
|
+
const k = r.gh.repo.toLowerCase()
|
|
689
|
+
const cur = byRepo.get(k)
|
|
690
|
+
if (!cur) byRepo.set(k, { r, n: 1 })
|
|
691
|
+
else { cur.n++; if (r.w > cur.r.w) cur.r = r }
|
|
692
|
+
}
|
|
693
|
+
const shared = new Map([...byRepo.values()].map(x => [x.r.n, x.n]))
|
|
694
|
+
const rows = [...byRepo.values()].map(x => x.r).sort((x, y) => val(y) - val(x)).slice(0, 40)
|
|
695
|
+
$('#rankHead').innerHTML = '<tr><th style="width:44px">#</th><th>插件</th><th>分类</th>' +
|
|
696
|
+
'<th class="r">★ 星标</th><th class="r">Fork</th><th class="r" title="未关闭的 issue 与 PR">讨论</th>' +
|
|
697
|
+
'<th class="r" title="仓库最近一次提交">最近提交</th><th></th></tr>'
|
|
698
|
+
$('#rankBody').innerHTML = rows.length ? rows.map((r, i) => {
|
|
699
|
+
const age = daysSince(r.gh.p)
|
|
700
|
+
return `<tr>` +
|
|
701
|
+
`<td style="color:var(--t3)">${i + 1}</td>` +
|
|
702
|
+
`<td class="nm">${esc(r.n)} <span style="color:var(--t3);font-weight:400;font-size:11px">v${esc(r.v)}</span>` +
|
|
703
|
+
(shared.get(r.n) > 1 ? `<div class="sub" title="仓库 ${esc(r.gh.repo)} 里有 ${shared.get(r.n)} 个插件,数据相同,只列一行">等 ${shared.get(r.n)} 个插件共用这个仓库</div>` : '') +
|
|
704
|
+
`</td>` +
|
|
705
|
+
`<td><span class="catpill">${esc(r.cat)}</span></td>` +
|
|
706
|
+
`<td class="r">${b(metric === 'gs', num(r.gh.s))}</td>` +
|
|
707
|
+
`<td class="r">${b(metric === 'gf', num(r.gh.f))}</td>` +
|
|
708
|
+
`<td class="r">${b(metric === 'gi', num(r.gh.i))}</td>` +
|
|
709
|
+
`<td class="r" title="${esc(r.gh.p || '')}">${r.gh.a ? '<span class="arch">已归档</span>' : `<span${age != null && age > 90 ? ' class="stale"' : ''}>${b(metric === 'gp', ageText(age))}</span>`}</td>` +
|
|
710
|
+
`<td class="lks">${watchBtn(r.n)}${linkBtns(r, { icon: true })}</td>` +
|
|
711
|
+
`</tr>`
|
|
712
|
+
}).join('') : '<tr><td colspan="8" class="empty">目录里还没有 GitHub 数据(每日更新取到后就有)。</td></tr>'
|
|
713
|
+
return
|
|
714
|
+
}
|
|
715
|
+
|
|
716
|
+
$('#rankCap').textContent = '按 npm 下载数据:日常基线已扣掉发版拉取的虚高,最接近真实使用量;周下载含 CI、镜像流量。'
|
|
717
|
+
const onlyDeep = metric !== 'w'
|
|
580
718
|
const val = r => metric === 'base' ? r.deep.base
|
|
581
719
|
: metric === 'growth' ? (r.deep.growth === null ? -Infinity : r.deep.growth)
|
|
582
720
|
: metric === 's' ? r.deep.s
|
|
583
721
|
: r.w
|
|
584
|
-
rows.sort((
|
|
585
|
-
|
|
586
|
-
|
|
722
|
+
const rows = Object.values(CAT.packages).filter(r => inCat(r) && (!onlyDeep || r.deep)).sort((x, y) => val(y) - val(x)).slice(0, 40)
|
|
723
|
+
$('#rankHead').innerHTML = '<tr><th style="width:44px">#</th><th>插件</th><th>分类</th>' +
|
|
724
|
+
`<th class="r">基线</th><th class="r">周下载</th><th class="r">环比</th>${metric === 's' ? '<th class="r">健康度</th>' : ''}` +
|
|
725
|
+
'<th class="r" title="最近一次发版 · 平均几天发一个版本">更新</th><th></th></tr>'
|
|
587
726
|
$('#rankBody').innerHTML = rows.map((r, i) => {
|
|
588
727
|
const d = r.deep
|
|
589
728
|
const g = d ? d.growth : null
|
|
590
729
|
return `<tr>` +
|
|
591
|
-
`<td style="color:var(--t3)">${i + 1}</td>` +
|
|
592
|
-
`<td class="nm">${esc(r.n)} <span style="color:var(--t3);font-weight:400;font-size:11px">v${esc(r.v)}</span></td>` +
|
|
730
|
+
`<td style="color:var(--t3)">${i + 1}</td>` + nameCell(r) +
|
|
593
731
|
`<td><span class="catpill">${esc(r.cat)}</span></td>` +
|
|
594
|
-
`<td class="r"
|
|
595
|
-
`<td class="r">${num(r.w)}</td>` +
|
|
596
|
-
`<td class="r ${g === null ? '' : (g >= 0 ? 'up' : 'down')}">${pct(g)}</td>` +
|
|
732
|
+
`<td class="r">${b(metric === 'base', d ? num(d.base) : '—')}</td>` +
|
|
733
|
+
`<td class="r">${b(metric === 'w', num(r.w))}</td>` +
|
|
734
|
+
`<td class="r ${g === null ? '' : (g >= 0 ? 'up' : 'down')}">${metric === 'growth' ? `<b>${pct(g)}</b>` : pct(g)}</td>` +
|
|
735
|
+
(metric === 's' ? `<td class="r"><b>${d ? d.s : '—'}</b></td>` : '') +
|
|
597
736
|
maintCell(d) +
|
|
598
|
-
`<td class="lks">${linkBtns(r, { icon: true })}</td>` +
|
|
737
|
+
`<td class="lks">${watchBtn(r.n)}${linkBtns(r, { icon: true })}</td>` +
|
|
599
738
|
`</tr>`
|
|
600
739
|
}).join('')
|
|
601
740
|
}
|
|
@@ -606,6 +745,39 @@ function watch() {
|
|
|
606
745
|
}
|
|
607
746
|
function saveWatch(list) { localStorage.setItem(WATCH_KEY, JSON.stringify(list)) }
|
|
608
747
|
|
|
748
|
+
/** 监控列表里的名字:npm 包名;只在 GitHub 上的插件记成 gh:owner/repo */
|
|
749
|
+
function watchKey(r) {
|
|
750
|
+
if (r.n) return r.n
|
|
751
|
+
const m = /github\.com\/([^/]+\/[^/#]+)/.exec(r.repo || '')
|
|
752
|
+
return m ? 'gh:' + m[1] : ''
|
|
753
|
+
}
|
|
754
|
+
|
|
755
|
+
/** 彩色 + 号(已监控显示 ✓):点击由 document 上的委托统一处理 */
|
|
756
|
+
function watchBtn(key) {
|
|
757
|
+
if (!key) return ''
|
|
758
|
+
const on = watch().includes(key)
|
|
759
|
+
return `<button class="wadd${on ? ' on' : ''}" data-watch="${esc(key)}" title="${on ? '已在我的监控里,点一下移除' : '加入我的监控'}" aria-label="${on ? '移出我的监控' : '加入我的监控'}">${on ? '✓' : '+'}</button>`
|
|
760
|
+
}
|
|
761
|
+
|
|
762
|
+
function toggleWatch(key) {
|
|
763
|
+
const list = watch()
|
|
764
|
+
const on = list.includes(key)
|
|
765
|
+
if (!on && list.length >= 30) { toast('我的监控最多 30 个,先移除几个再加'); return }
|
|
766
|
+
saveWatch(on ? list.filter(x => x !== key) : [...list, key])
|
|
767
|
+
const now = !on
|
|
768
|
+
const shown = key.startsWith('gh:') ? key.slice(3) : key
|
|
769
|
+
toast(now ? `已加入我的监控:${shown}` : `已移出我的监控:${shown}`)
|
|
770
|
+
renderWatch()
|
|
771
|
+
// 同一个插件可能同时出现在搜索结果和排行榜里,一起更新
|
|
772
|
+
document.querySelectorAll('[data-watch]').forEach(b => {
|
|
773
|
+
if (b.dataset.watch !== key) return
|
|
774
|
+
b.classList.toggle('on', now)
|
|
775
|
+
b.textContent = now ? '✓' : '+'
|
|
776
|
+
b.title = now ? '已在我的监控里,点一下移除' : '加入我的监控'
|
|
777
|
+
b.setAttribute('aria-label', now ? '移出我的监控' : '加入我的监控')
|
|
778
|
+
})
|
|
779
|
+
}
|
|
780
|
+
|
|
609
781
|
function addPickedToWatch() {
|
|
610
782
|
const list = watch()
|
|
611
783
|
for (const n of picked) if (!list.includes(n)) list.push(n)
|
|
@@ -625,6 +797,16 @@ let LIVE = (() => {
|
|
|
625
797
|
* 否则用目录里的。目录里没有、也没刷新过的返回 null
|
|
626
798
|
*/
|
|
627
799
|
function watchRec(n) {
|
|
800
|
+
// 只在 GitHub 上的插件(gh:owner/repo):从榜单里找它的信息,有实时数据就用实时的
|
|
801
|
+
if (n.startsWith('gh:')) {
|
|
802
|
+
const repo = n.slice(3)
|
|
803
|
+
const url = 'https://github.com/' + repo
|
|
804
|
+
const inBoard = ['community', 'shop'].flatMap(k => (CAT.boards && CAT.boards[k] && CAT.boards[k].rows) || [])
|
|
805
|
+
.find(r => r.repo && r.repo.toLowerCase() === url.toLowerCase())
|
|
806
|
+
const live = LIVE.rows[n]
|
|
807
|
+
const gh = live && live.found ? live.gh : (inBoard && inBoard.s != null ? { repo, s: inBoard.s, f: null, i: null, p: null, a: false } : null)
|
|
808
|
+
return { n: '', label: repo, cat: '只在 GitHub', w: null, m: null, deep: null, ghUrl: url, gh, live: Boolean(live && live.found) }
|
|
809
|
+
}
|
|
628
810
|
const base = CAT.packages[n]
|
|
629
811
|
const live = LIVE.rows[n]
|
|
630
812
|
if (!live || !live.found) return base || null
|
|
@@ -635,7 +817,9 @@ function watchRec(n) {
|
|
|
635
817
|
v: live.latest || (base && base.v),
|
|
636
818
|
w: live.weekly,
|
|
637
819
|
m: live.monthly,
|
|
638
|
-
|
|
820
|
+
// npm 下载接口偶尔限流查不到:保留目录里的指标,别把有的数据冲掉
|
|
821
|
+
deep: d ? { base: d.baseline, growth: d.growth, cadence: d.cadence, age: d.ageDays, lastRelease: d.lastRelease, versions: d.versions, s: d.score } : (base && base.deep) || null,
|
|
822
|
+
gh: live.gh || (base && base.gh) || null,
|
|
639
823
|
live: true,
|
|
640
824
|
catalogW: base ? base.w : null,
|
|
641
825
|
}
|
|
@@ -654,7 +838,10 @@ async function refreshWatch() {
|
|
|
654
838
|
LIVE = { at: j.at, anchor: j.anchor, rows: Object.fromEntries(j.rows.map(x => [x.name, x])) }
|
|
655
839
|
try { localStorage.setItem(LIVE_KEY, JSON.stringify(LIVE)) } catch { /* 存不下就只这次有效 */ }
|
|
656
840
|
const miss = j.rows.filter(x => !x.found).map(x => x.name)
|
|
657
|
-
toast(
|
|
841
|
+
toast([
|
|
842
|
+
miss.length ? `已刷新;npm 上查不到:${miss.join('、')}` : `已刷新 ${j.rows.length} 个插件`,
|
|
843
|
+
j.githubError ? `(${j.githubError})` : '',
|
|
844
|
+
].join(''))
|
|
658
845
|
} catch (e) {
|
|
659
846
|
toast('刷新失败:' + e.message + '(检查网络后再试)')
|
|
660
847
|
}
|
|
@@ -663,6 +850,9 @@ async function refreshWatch() {
|
|
|
663
850
|
renderWatch()
|
|
664
851
|
}
|
|
665
852
|
|
|
853
|
+
/** 我的监控里展开着的插件(只在这次打开期间记住) */
|
|
854
|
+
const watchOpen = new Set()
|
|
855
|
+
|
|
666
856
|
function renderWatch() {
|
|
667
857
|
const list = watch()
|
|
668
858
|
$('#watchCount').textContent = list.length ? ` (${list.length})` : ''
|
|
@@ -679,31 +869,51 @@ function renderWatch() {
|
|
|
679
869
|
|
|
680
870
|
host.innerHTML = list.map(n => {
|
|
681
871
|
const r = watchRec(n)
|
|
682
|
-
|
|
683
|
-
const
|
|
684
|
-
|
|
685
|
-
let
|
|
686
|
-
if (r
|
|
687
|
-
const
|
|
688
|
-
|
|
872
|
+
const name = r ? esc(r.label || n) : esc(n)
|
|
873
|
+
const ver = r && r.v ? ` <span class="ver">v${esc(r.v)}</span>` : ''
|
|
874
|
+
const open = watchOpen.has(n)
|
|
875
|
+
let detail = '<span>不在目录中,点「刷新」去 npm 查</span>'
|
|
876
|
+
if (r) {
|
|
877
|
+
const d = r.deep
|
|
878
|
+
// 和目录数据比,周下载涨了还是跌了(只在刷新过、差得明显时标)
|
|
879
|
+
let delta = ''
|
|
880
|
+
if (r.live && r.catalogW) {
|
|
881
|
+
const ch = (r.w - r.catalogW) / Math.max(r.catalogW, 1)
|
|
882
|
+
if (Math.abs(ch) >= 0.05) delta = `<span class="delta ${ch > 0 ? 'up' : 'down'}" title="和目录数据(截止 ${esc(CAT.anchor)})相比">${ch > 0 ? '↑' : '↓'}${Math.round(Math.abs(ch) * 100)}%</span>`
|
|
883
|
+
}
|
|
884
|
+
detail = (r.live ? '<span class="live" title="刚从 npm / GitHub 查的">实时</span>' : '') +
|
|
885
|
+
`<span class="mrank">${rankText(r)}</span>` +
|
|
886
|
+
`<span>${esc(r.cat)}</span>` +
|
|
887
|
+
(r.w != null ? `<span><b>${num(r.w)}</b>/周${delta}</span>` : '') +
|
|
888
|
+
(r.w != null ? `<span>基线 ${d ? num(d.base) : '—'}</span>` : '') +
|
|
889
|
+
(r.gh ? `<span title="GitHub · 最近提交 ${esc(r.gh.p || '—')}">★ ${short(r.gh.s)}${r.gh.a ? ' · 已归档' : ''}</span>` : '') +
|
|
890
|
+
(d ? `<span>${ageText(d.age)}发版</span>` : '')
|
|
689
891
|
}
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
`<
|
|
699
|
-
|
|
892
|
+
// 一个插件一行:名字占满中间,最后是链接图标和移除;其余数据折叠,点这一行展开
|
|
893
|
+
return `<div class="mon${open ? ' open' : ''}">` +
|
|
894
|
+
`<div class="mhead" data-toggle="${esc(n)}">` +
|
|
895
|
+
`<button class="mtoggle" aria-expanded="${open}" aria-label="${open ? '收起' : '展开'} ${name} 的数据">${open ? '▾' : '▸'}</button>` +
|
|
896
|
+
`<span class="nm" title="${name}">${name}${ver}</span>` +
|
|
897
|
+
(r ? `<span class="mlinks">${linkBtns(r, { icon: true })}</span>` : '') +
|
|
898
|
+
`<button class="x" data-rm="${esc(n)}" title="从我的监控移除" aria-label="移除 ${name}">×</button>` +
|
|
899
|
+
`</div>` +
|
|
900
|
+
(open ? `<div class="mdetail">${detail}</div>` : '') +
|
|
901
|
+
`</div>`
|
|
700
902
|
}).join('')
|
|
701
903
|
|
|
702
904
|
host.querySelectorAll('[data-rm]').forEach(b =>
|
|
703
905
|
b.addEventListener('click', () => saveWatch(watch().filter(x => x !== b.dataset.rm)) || renderWatch()))
|
|
906
|
+
host.querySelectorAll('[data-toggle]').forEach(row =>
|
|
907
|
+
row.addEventListener('click', e => {
|
|
908
|
+
if (e.target.closest('a, [data-rm]')) return
|
|
909
|
+
const n = row.dataset.toggle
|
|
910
|
+
if (watchOpen.has(n)) watchOpen.delete(n)
|
|
911
|
+
else watchOpen.add(n)
|
|
912
|
+
renderWatch()
|
|
913
|
+
}))
|
|
704
914
|
|
|
705
915
|
// 对数刻度横条图
|
|
706
|
-
const rows = list.map(watchRec).filter(
|
|
916
|
+
const rows = list.map(watchRec).filter(r => r && r.w != null)
|
|
707
917
|
const max = Math.max(...rows.map(r => r.w), 1)
|
|
708
918
|
$('#watchChart').innerHTML = rows.map((r, i) => {
|
|
709
919
|
const w = Math.max(Math.log10(r.w + 1) / Math.log10(max + 1) * 100, 1.5)
|
|
@@ -746,7 +956,7 @@ ${ROWS.map(row => {
|
|
|
746
956
|
}).join('')}
|
|
747
957
|
</tbody></table>
|
|
748
958
|
<h2>结论</h2>${verdicts}
|
|
749
|
-
<div class="foot">数据来源 api.npmjs.org / registry.npmjs.org,截止 <b>${CAT.anchor}</b>(npm
|
|
959
|
+
<div class="foot">数据来源 api.npmjs.org / registry.npmjs.org,截止 <b>${CAT.anchor}</b>(npm 最近有数据的一天)。
|
|
750
960
|
下载量含 CI、镜像、爬虫等非人类流量,不等于用户数;<b>日常基线</b>=扣掉版本发布日与次日后的每日中位数。
|
|
751
961
|
本页由 dsh-pick 面板导出。</div>
|
|
752
962
|
</body></html>`
|