dsh-pick 0.7.0 → 0.7.2
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 +7 -3
- package/data/catalog.json +1 -1
- package/lib/boards.js +20 -3
- package/lib/engine.js +69 -14
- package/lib/overall.js +23 -1
- package/package.json +1 -1
- package/plugin/client.js +12 -3
- package/plugin/index.js +2 -0
- package/plugin/tools.js +1 -1
- package/web/panel.html +47 -1
- package/web/panel.js +470 -64
package/web/panel.js
CHANGED
|
@@ -99,7 +99,7 @@ function askCands() {
|
|
|
99
99
|
}
|
|
100
100
|
|
|
101
101
|
function askVerdict() {
|
|
102
|
-
const rows = picked.map(
|
|
102
|
+
const rows = picked.map(cmpRec).filter(Boolean)
|
|
103
103
|
const rule = $('#verdicts').innerText.trim().replace(/\n+/g, ' / ')
|
|
104
104
|
return [
|
|
105
105
|
`帮我在这几个 DSH 插件里做个选择${dataAsOf()}。`,
|
|
@@ -344,8 +344,13 @@ async function boot() {
|
|
|
344
344
|
CAT = await res.json()
|
|
345
345
|
|
|
346
346
|
const deepN = Object.values(CAT.packages).filter(p => p.deep).length
|
|
347
|
+
// 覆盖数:几个插件市场 + npm 合起来去重(每日目录用新代码构建后才有);旧目录只说 npm 上的包数
|
|
348
|
+
const cover = CAT.boards && CAT.boards.overall && CAT.boards.overall.cover
|
|
349
|
+
const MKT = { dshmarket: 'dshmarket', shop: 'dsh-plugin-shop 商店', 'dsh-m': 'dsh-m 精选', official: 'DeepSeek 官方' }
|
|
347
350
|
$('#meta').innerHTML =
|
|
348
|
-
|
|
351
|
+
(cover
|
|
352
|
+
? `收录 <b>${num(cover.all)}</b> 个插件(4 个市场 + npm 去重)· npm 上 <b>${num(cover.npm)}</b> 个 · 去噪指标 <b>${num(deepN)}</b> 个<br>`
|
|
353
|
+
: `npm 上 <b>${num(CAT.total)}</b> 个插件包 · 去噪指标 <b>${num(deepN)}</b> 个<br>`) +
|
|
349
354
|
`数据截止 <b>${CAT.anchor}</b>(npm 最近有数据的一天)`
|
|
350
355
|
|
|
351
356
|
const gapNote = CAT.gaps && CAT.gaps.length
|
|
@@ -353,7 +358,13 @@ async function boot() {
|
|
|
353
358
|
: ''
|
|
354
359
|
$('#foot').innerHTML =
|
|
355
360
|
`<b>口径:</b>下载量含 CI、镜像、爬虫等非人类流量,不等于用户数;<b>日常基线</b>= 扣掉版本发布日与次日后的每日中位数,比原始下载量更接近真实使用量。<br>` +
|
|
356
|
-
|
|
361
|
+
(cover
|
|
362
|
+
? `<b>覆盖范围:</b>把 ${Object.entries(cover.markets).map(([k, v]) => `${MKT[k] || esc(k)}(${num(v)} 条)`).join('、')}和 npm 上带 <code>dsh-plugin</code> 关键字的包合起来,` +
|
|
363
|
+
`按 npm 包名、GitHub 仓库去重,共 <b>${num(cover.all)}</b> 个插件:${num(cover.npm)} 个发布在 npm(能一键安装、有下载量),${num(cover.gh)} 个只在 GitHub。` +
|
|
364
|
+
`市场里一个仓库拆成好几条、几个市场互相重复收录,所以去重后比各市场条数相加少。` +
|
|
365
|
+
(cover.pending ? `其中 ${num(cover.pending)} 个 npm 包还没补进目录(每天补一批,几天补完),补进来之前不参与排名。` : '') +
|
|
366
|
+
`去噪指标只算了 npm 上周下载最多的 ${num(deepN)} 个。目录每天自动重建。<br>`
|
|
367
|
+
: `<b>覆盖范围:</b>npm 上带 <code>dsh-plugin</code> 关键字、或被插件市场收录的 ${num(CAT.total)} 个 npm 包;去噪指标只算了周下载最多的 ${num(deepN)} 个。目录每天自动重建。<br>`) +
|
|
357
368
|
(IN_DSH
|
|
358
369
|
? `<b>当前结论由本地规则生成</b>(依据就是对比表里的数字)。点各处的「+AI」,把数据发到对话里让 AI 结合你的场景分析;在对话里也可以直接问「哪个插件能做某某」,AI 会自己查这份目录。`
|
|
359
370
|
: `<b>当前结论由本地规则生成</b>(依据就是对比表里的数字)。装上 DSH 插件版后,可以一键交给 AI,结合你的具体场景解释取舍。`) +
|
|
@@ -383,20 +394,22 @@ function bindEvents() {
|
|
|
383
394
|
$('#btnFind').addEventListener('click', doSearch)
|
|
384
395
|
$('#btnAi').addEventListener('click', runAiPick)
|
|
385
396
|
// 比较清单:输入插件名加入
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
if (!sugItems.length) return
|
|
390
|
-
if (e.key === 'ArrowDown') { sugOn = (sugOn + 1) % sugItems.length; renderSug(); e.preventDefault() }
|
|
391
|
-
else if (e.key === 'ArrowUp') { sugOn = (sugOn - 1 + sugItems.length) % sugItems.length; renderSug(); e.preventDefault() }
|
|
392
|
-
else if (e.key === 'Enter' && sugOn >= 0) { addFromSug(sugItems[sugOn].n); e.preventDefault() }
|
|
393
|
-
else if (e.key === 'Escape') { sugItems = []; renderSug() }
|
|
397
|
+
bindSuggest({
|
|
398
|
+
input: $('#addCmp'), box: $('#addSug'), has: n => picked.includes(n), hasText: '已在清单里',
|
|
399
|
+
onPick: n => { if (!picked.includes(n)) togglePick(n); $('#secCmp').scrollIntoView({ block: 'nearest' }) },
|
|
394
400
|
})
|
|
395
|
-
|
|
396
|
-
$('#
|
|
397
|
-
|
|
398
|
-
|
|
401
|
+
// 我的监控:「+ 添加」打开输入框;选建议里的,或直接回车按输入的名字 / GitHub 地址加
|
|
402
|
+
const watchInput = $('#addWatch')
|
|
403
|
+
const watchSug = bindSuggest({
|
|
404
|
+
input: watchInput, box: $('#watchSug'), has: n => watch().includes(n), hasText: '已在监控里',
|
|
405
|
+
onPick: n => addToWatch(n), onEnter: text => addToWatch(text),
|
|
406
|
+
})
|
|
407
|
+
$('#btnWatchAdd').addEventListener('click', () => {
|
|
408
|
+
const open = $('#watchAdd').classList.toggle('hidden') === false
|
|
409
|
+
$('#btnWatchAdd').setAttribute('aria-expanded', String(open))
|
|
410
|
+
if (open) watchInput.focus()
|
|
399
411
|
})
|
|
412
|
+
$('#watchAddGo').addEventListener('click', () => watchSug.submit())
|
|
400
413
|
$('#need').addEventListener('keydown', e => { if (e.key === 'Enter') doSearch() })
|
|
401
414
|
|
|
402
415
|
document.querySelectorAll('.examples .chip').forEach(c => {
|
|
@@ -409,6 +422,9 @@ function bindEvents() {
|
|
|
409
422
|
const t = b.dataset.tab
|
|
410
423
|
// 每个标签一块内容:tab-pick / tab-rank / tab-watch
|
|
411
424
|
document.querySelectorAll('#tabs button').forEach(x => $('#tab-' + x.dataset.tab).classList.toggle('hidden', x.dataset.tab !== t))
|
|
425
|
+
if (t === 'watch') layoutWatchDetail() // 标签页隐藏时量不出宽度,显示出来再选版式
|
|
426
|
+
// 打开「我的监控」时,数据超过 6 小时没刷新就自动刷新一次
|
|
427
|
+
if (t === 'watch' && watch().length && (!LIVE.at || Date.now() - Date.parse(LIVE.at) > 6 * 3600 * 1000) && !$('#btnWatchRefresh').disabled) refreshWatch()
|
|
412
428
|
})
|
|
413
429
|
})
|
|
414
430
|
|
|
@@ -426,6 +442,11 @@ function bindEvents() {
|
|
|
426
442
|
})
|
|
427
443
|
})
|
|
428
444
|
$('#rankCat').addEventListener('change', renderRank)
|
|
445
|
+
$('#rankBody').addEventListener('click', e => {
|
|
446
|
+
if (!e.target.closest('[data-rank-more]')) return
|
|
447
|
+
RANK_LIMIT += RANK_STEP
|
|
448
|
+
renderRank()
|
|
449
|
+
})
|
|
429
450
|
|
|
430
451
|
$('#aiCands').addEventListener('click', () => cands.length && askAI(askCands()))
|
|
431
452
|
$('#aiVerdict').addEventListener('click', () => picked.length >= 2 && askAI(askVerdict()))
|
|
@@ -520,6 +541,7 @@ function togglePick(name) {
|
|
|
520
541
|
renderPickBar()
|
|
521
542
|
renderAi()
|
|
522
543
|
renderCompare()
|
|
544
|
+
fillCompareLive()
|
|
523
545
|
}
|
|
524
546
|
|
|
525
547
|
/* ---------------- 比较清单:搜索结果之外的插件也能加进来 ---------------- */
|
|
@@ -529,8 +551,6 @@ function renderPickBar() {
|
|
|
529
551
|
: '<span class="none">还没有,点候选卡片或在右边输入插件名</span>'
|
|
530
552
|
}
|
|
531
553
|
|
|
532
|
-
let sugItems = []
|
|
533
|
-
let sugOn = -1
|
|
534
554
|
/** 按名字找插件:名字开头吻合的优先,其次名字里包含、关键字吻合;同档按周下载 */
|
|
535
555
|
function suggest(q) {
|
|
536
556
|
q = q.trim().toLowerCase()
|
|
@@ -543,20 +563,41 @@ function suggest(q) {
|
|
|
543
563
|
}
|
|
544
564
|
return out.sort((a, b) => a[0] - b[0] || (b[1].w || 0) - (a[1].w || 0)).slice(0, 8).map(x => x[1])
|
|
545
565
|
}
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
566
|
+
/**
|
|
567
|
+
* 输入框 + 下拉建议(比较清单、我的监控共用):上下键选、回车加、Esc 收起。
|
|
568
|
+
* 没有建议、或没选中时回车:交给 onEnter(按输入的原文加),没有 onEnter 就不动
|
|
569
|
+
*/
|
|
570
|
+
function bindSuggest({ input, box, has, hasText, onPick, onEnter }) {
|
|
571
|
+
let items = []
|
|
572
|
+
let on = -1
|
|
573
|
+
const render = () => {
|
|
574
|
+
if (!items.length) { box.classList.add('hidden'); return }
|
|
575
|
+
box.innerHTML = items.map((r, i) => `<div class="opt${i === on ? ' on' : ''}" data-add="${esc(r.n)}" role="option">` +
|
|
576
|
+
`<b>${esc(r.n)}</b>${has(r.n) ? ` <em style="color:var(--ok-text);font-style:normal;font-size:11px">${hasText}</em>` : ''}` +
|
|
577
|
+
`<span>周下载 ${short(r.w)}${r.sc != null ? ` · 综合分 ${r.sc}` : ''} · ${esc(String(r.d || '').slice(0, 60))}</span></div>`).join('')
|
|
578
|
+
box.classList.remove('hidden')
|
|
579
|
+
}
|
|
580
|
+
const done = () => { input.value = ''; items = []; render() }
|
|
581
|
+
const pick = n => { onPick(n); done() }
|
|
582
|
+
const submit = () => {
|
|
583
|
+
if (items.length && on >= 0) return pick(items[on].n)
|
|
584
|
+
const text = input.value.trim()
|
|
585
|
+
if (text && onEnter && onEnter(text) !== false) done()
|
|
586
|
+
}
|
|
587
|
+
input.addEventListener('input', () => { items = suggest(input.value); on = items.length ? 0 : -1; render() })
|
|
588
|
+
input.addEventListener('keydown', e => {
|
|
589
|
+
if (e.key === 'Enter') { submit(); e.preventDefault(); return }
|
|
590
|
+
if (!items.length) return
|
|
591
|
+
if (e.key === 'ArrowDown') { on = (on + 1) % items.length; render(); e.preventDefault() }
|
|
592
|
+
else if (e.key === 'ArrowUp') { on = (on - 1 + items.length) % items.length; render(); e.preventDefault() }
|
|
593
|
+
else if (e.key === 'Escape') { items = []; render() }
|
|
594
|
+
})
|
|
595
|
+
input.addEventListener('blur', () => setTimeout(() => { items = []; render() }, 150))
|
|
596
|
+
box.addEventListener('mousedown', e => {
|
|
597
|
+
const o = e.target.closest('[data-add]')
|
|
598
|
+
if (o) { e.preventDefault(); pick(o.dataset.add) }
|
|
599
|
+
})
|
|
600
|
+
return { submit }
|
|
560
601
|
}
|
|
561
602
|
|
|
562
603
|
/* ---------------- AI 精选:用 DSH 当前的模型挑插件 ---------------- */
|
|
@@ -625,6 +666,7 @@ const ROWS = [
|
|
|
625
666
|
{ k: 'cad', label: '版本节奏', get: r => r.deep && r.deep.cadence, fmt: r => r == null ? '—' : r + ' 天/版', best: 'min' },
|
|
626
667
|
{ k: 'age', label: '最近更新', get: r => r.deep && r.deep.age, fmt: r => r == null ? '—' : r + ' 天前', best: 'min' },
|
|
627
668
|
{ k: 's', label: '健康度', get: r => r.deep && r.deep.s, fmt: num, best: 'max' },
|
|
669
|
+
{ k: 'tot', label: '累计下载', get: r => r.total, fmt: num, best: 'max' },
|
|
628
670
|
{ k: 'gs', label: 'GitHub 星标', get: r => r.gh && r.gh.s, fmt: num, best: 'max' },
|
|
629
671
|
{ k: 'gp', label: '最近提交', get: r => r.gh && daysSince(r.gh.p), fmt: r => r == null ? '—' : ageText(r), best: 'min' },
|
|
630
672
|
]
|
|
@@ -638,11 +680,11 @@ function renderCompare() {
|
|
|
638
680
|
return
|
|
639
681
|
}
|
|
640
682
|
|
|
641
|
-
const rows = picked.map(
|
|
683
|
+
const rows = picked.map(cmpRec).filter(Boolean)
|
|
642
684
|
const missingDeep = rows.filter(r => !r.deep).length
|
|
643
685
|
|
|
644
686
|
$('#cmpHead').innerHTML = '<tr><th>指标</th>' +
|
|
645
|
-
rows.map((r, i) => `<th><i style="background:${colorOf(picked.indexOf(r.n))}"></i>${esc(r.n)}</th>`).join('') +
|
|
687
|
+
rows.map((r, i) => `<th><i style="background:${colorOf(picked.indexOf(r.n))}"></i>${esc(r.n)}${r.live ? ' <span class="srcchip" title="指标是刚从 npm 实时算的">实时</span>' : ''}</th>`).join('') +
|
|
646
688
|
'</tr>'
|
|
647
689
|
|
|
648
690
|
let body = ''
|
|
@@ -662,7 +704,9 @@ function renderCompare() {
|
|
|
662
704
|
|
|
663
705
|
$('#cmpNote').innerHTML =
|
|
664
706
|
`健康度 = 日常基线 40% + 增速 25% + 新鲜度 20% + 版本节奏 15%,满分 100。` +
|
|
665
|
-
(
|
|
707
|
+
(rows.some(r => r.live) ? `<br>${rows.filter(r => r.live).map(r => esc(r.n)).join('、')} 不在每日构建的去噪范围(周下载前 300 多名)里,这些指标是刚从 npm 实时算的。` : '') +
|
|
708
|
+
(CMP_PENDING.size ? `<br><span style="color:var(--t3)">正在从 npm 实时计算 ${[...CMP_PENDING].map(esc).join('、')} 的指标…</span>` : '') +
|
|
709
|
+
(missingDeep && !CMP_PENDING.size ? `<br><span style="color:var(--warn-text)">${rows.filter(r => !r.deep).map(r => esc(r.n)).join('、')} 实时也没算出去噪指标(npm 上数据太少或这次没查到),无法参与健康度比较。</span>` : '')
|
|
666
710
|
|
|
667
711
|
sec.classList.remove('hidden')
|
|
668
712
|
renderVerdict()
|
|
@@ -670,7 +714,7 @@ function renderCompare() {
|
|
|
670
714
|
|
|
671
715
|
/* ---------------- 第 4 步:结论 ---------------- */
|
|
672
716
|
function renderVerdict() {
|
|
673
|
-
const rows = picked.map(
|
|
717
|
+
const rows = picked.map(cmpRec).filter(Boolean)
|
|
674
718
|
const withDeep = rows.filter(r => r.deep)
|
|
675
719
|
const noDeep = rows.filter(r => !r.deep)
|
|
676
720
|
|
|
@@ -749,7 +793,63 @@ function rankBoard() {
|
|
|
749
793
|
return document.querySelector('#rankBoard button.on').dataset.b
|
|
750
794
|
}
|
|
751
795
|
|
|
752
|
-
|
|
796
|
+
/* ---------- 排行榜统一出表 ---------- */
|
|
797
|
+
// 每个榜都先排出完整名次,只画前 RANK_LIMIT 名,下面「显示更多」再加一页
|
|
798
|
+
const RANK_STEP = 50
|
|
799
|
+
let RANK_LIMIT = RANK_STEP
|
|
800
|
+
let RANK_SIG = ''
|
|
801
|
+
|
|
802
|
+
/** 换了榜单、角度或分类:回到第一页 */
|
|
803
|
+
function rankSig(sig) {
|
|
804
|
+
if (sig !== RANK_SIG) { RANK_SIG = sig; RANK_LIMIT = RANK_STEP }
|
|
805
|
+
}
|
|
806
|
+
|
|
807
|
+
/** 名字:npm 包名,或 gh:owner/repo 的仓库名 */
|
|
808
|
+
function watchName(k) {
|
|
809
|
+
return k.startsWith('gh:') ? k.slice(3).split('/').pop() : k
|
|
810
|
+
}
|
|
811
|
+
|
|
812
|
+
/** 不在这个榜的通用原因:目录里没有、分类对不上 */
|
|
813
|
+
function missCommon(k, cat) {
|
|
814
|
+
const rec = CAT.packages[k]
|
|
815
|
+
if (!k.startsWith('gh:') && !rec) return '插件目录里没有它(还没被收录,或不是 DSH 插件)'
|
|
816
|
+
if (cat && rec && rec.cat !== cat) return `它的分类是「${rec.cat || '未分类'}」,不在「${cat}」里`
|
|
817
|
+
return ''
|
|
818
|
+
}
|
|
819
|
+
|
|
820
|
+
/**
|
|
821
|
+
* all:这个榜(当前角度、分类下)的完整排名;row(x, i, on) 画一行,i 是在完整排名里的下标。
|
|
822
|
+
* keysOf(x):这一行对应的监控名(GitHub 榜一行代表一个仓库,可能对应好几个插件)。
|
|
823
|
+
* 我的监控里的插件:在画出来的前几名里就高亮;不在就追加到最下面,标出它在完整排名里的名次;
|
|
824
|
+
* 完整排名里也没有的,写明为什么不在这个榜
|
|
825
|
+
*/
|
|
826
|
+
function paintRank({ all, row, keysOf, cols, empty, miss }) {
|
|
827
|
+
const watched = watch()
|
|
828
|
+
const wset = new Set(watched)
|
|
829
|
+
const shown = all.slice(0, RANK_LIMIT)
|
|
830
|
+
const isOn = x => keysOf(x).some(k => wset.has(k))
|
|
831
|
+
let html = all.length ? shown.map((x, i) => row(x, i, isOn(x))).join('') : `<tr><td colspan="${cols}" class="empty">${empty}</td></tr>`
|
|
832
|
+
if (all.length > shown.length) {
|
|
833
|
+
html += `<tr class="more"><td colspan="${cols}"><button class="btn ghost" data-rank-more>显示更多 · 还有 ${num(all.length - shown.length)} 个(共 ${num(all.length)})</button></td></tr>`
|
|
834
|
+
}
|
|
835
|
+
const shownKeys = new Set(shown.flatMap(keysOf))
|
|
836
|
+
const extra = watched.filter(k => !shownKeys.has(k))
|
|
837
|
+
if (extra.length) {
|
|
838
|
+
const seen = new Set()
|
|
839
|
+
const found = extra.map(k => ({ k, i: all.findIndex(x => keysOf(x).includes(k)) }))
|
|
840
|
+
.filter(({ i }) => i < 0 || (!seen.has(i) && seen.add(i)))
|
|
841
|
+
.sort((a, b) => (a.i < 0) - (b.i < 0) || a.i - b.i)
|
|
842
|
+
html += `<tr class="wsep"><td colspan="${cols}">我的监控 · 不在上面前 ${num(shown.length)} 名里的,排在这里</td></tr>`
|
|
843
|
+
html += found.map(({ k, i }) => (i >= 0 ? row(all[i], i, true)
|
|
844
|
+
: `<tr class="watched miss"><td class="rk">—</td><td class="nm" colspan="${cols - 2}">${esc(watchName(k))}` +
|
|
845
|
+
`<div class="sub">不在这个榜:${esc(miss(k) || '这个榜没收录它')}</div></td><td class="lks">${watchBtn(k)}</td></tr>`)).join('')
|
|
846
|
+
}
|
|
847
|
+
$('#rankBody').innerHTML = html
|
|
848
|
+
}
|
|
849
|
+
const trOpen = on => `<tr${on ? ' class="watched"' : ''}>`
|
|
850
|
+
const rankCell = i => `<td class="rk">${i + 1}</td>`
|
|
851
|
+
|
|
852
|
+
/** 官方 / 社区 / 商店榜:数据来自别人维护的目录 */
|
|
753
853
|
function renderOuterBoard(board) {
|
|
754
854
|
const data = CAT.boards && CAT.boards[board]
|
|
755
855
|
const CAPS = {
|
|
@@ -769,15 +869,27 @@ function renderOuterBoard(board) {
|
|
|
769
869
|
(!r.n ? '<div class="sub">只在 GitHub,没发到 npm</div>' : '') +
|
|
770
870
|
(r.d ? `<div class="sub desc" title="${esc(r.d)}">${esc(r.d)}</div>` : '') + `</td>`
|
|
771
871
|
const actions = r => `<td class="lks">${watchBtn(watchKey(r))}${linkBtns({ n: r.n || '', ghUrl: r.repo || '' }, { icon: true })}</td>`
|
|
872
|
+
const marketName = { official: 'DeepSeek 官方', community: '社区目录', shop: '这个商店' }[board]
|
|
873
|
+
const keysOf = r => [watchKey(r)].filter(Boolean)
|
|
874
|
+
// 社区目录、商店的榜只存了头部(比如社区一万多个只存前两百多):没存下来不等于没收录,
|
|
875
|
+
// 综合榜那边记着每个插件被哪些市场收录了(rec.src),用它分辨
|
|
876
|
+
const srcKey = { official: 'official', community: 'dshmarket', shop: 'shop' }[board]
|
|
877
|
+
const miss = k => {
|
|
878
|
+
const rec = CAT.packages[k]
|
|
879
|
+
if (rec && (rec.src || []).includes(srcKey)) return `${marketName}收录了它,但这个榜只存了前 ${num(data.rows.length)} 个(共 ${num(data.total || data.rows.length)}),它排在后面,具体名次没存`
|
|
880
|
+
return `${marketName}没收录它`
|
|
881
|
+
}
|
|
772
882
|
|
|
773
883
|
if (board === 'official') {
|
|
884
|
+
rankSig(board)
|
|
774
885
|
const rows = data.rows.slice().sort((x, y) => (y.w || 0) - (x.w || 0))
|
|
775
886
|
$('#rankHead').innerHTML = '<tr><th style="width:44px">#</th><th>插件</th><th class="r">周下载</th><th></th></tr>'
|
|
776
|
-
|
|
887
|
+
paintRank({ all: rows, keysOf, cols: 4, empty: '', miss, row: (r, i, on) => `${trOpen(on)}${rankCell(i)}${nameCell(r)}<td class="r"><b>${num(r.w)}</b></td>${actions(r)}</tr>` })
|
|
777
888
|
return
|
|
778
889
|
}
|
|
779
890
|
|
|
780
891
|
const metric = document.querySelector(`#rankFilters .chip.on[data-board="${board}"]`).dataset.m
|
|
892
|
+
rankSig(board + '|' + metric)
|
|
781
893
|
let rows = data.rows.filter(r => r[metric] != null)
|
|
782
894
|
.sort((x, y) => (y[metric] > x[metric] ? 1 : y[metric] < x[metric] ? -1 : 0))
|
|
783
895
|
// 按星标排时一个仓库只留一行(优先留发到 npm 的那条),不然同仓库的条目数字一样、刷屏
|
|
@@ -790,15 +902,20 @@ function renderOuterBoard(board) {
|
|
|
790
902
|
const keep = new Set(best.values())
|
|
791
903
|
rows = rows.filter(r => keep.has(r))
|
|
792
904
|
}
|
|
793
|
-
rows = rows.slice(0, 40)
|
|
794
905
|
const hasDl = board === 'community'
|
|
795
906
|
$('#rankHead').innerHTML = '<tr><th style="width:44px">#</th><th>插件</th><th class="r">★ 星标</th>' +
|
|
796
907
|
(hasDl ? '<th class="r" title="近 30 天">下载</th>' : '') + '<th class="r">收录</th><th></th></tr>'
|
|
797
908
|
const strong = (on, t) => (on ? `<b>${t}</b>` : t)
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
909
|
+
const metricName = { s: '星标', dl: '下载量', added: '收录日期' }[metric]
|
|
910
|
+
const inBoard = new Set(data.rows.flatMap(keysOf))
|
|
911
|
+
paintRank({
|
|
912
|
+
all: rows, keysOf, cols: hasDl ? 6 : 5, empty: '这个榜还没有数据。',
|
|
913
|
+
miss: k => (inBoard.has(k) ? `${marketName}收录了它,但它${metric === 's' ? '和同仓库的另一个条目只列一行,或' : ''}没有${metricName}数据` : miss(k)),
|
|
914
|
+
row: (r, i, on) => `${trOpen(on)}${rankCell(i)}${nameCell(r)}` +
|
|
915
|
+
`<td class="r">${strong(metric === 's', num(r.s))}</td>` +
|
|
916
|
+
(hasDl ? `<td class="r">${strong(metric === 'dl', num(r.dl))}</td>` : '') +
|
|
917
|
+
`<td class="r">${strong(metric === 'added', r.added ? esc(r.added.slice(5)) : '—')}</td>${actions(r)}</tr>`,
|
|
918
|
+
})
|
|
802
919
|
}
|
|
803
920
|
|
|
804
921
|
/** 「收录于」的市场名 */
|
|
@@ -826,6 +943,44 @@ const ANGLE_INFO = {
|
|
|
826
943
|
new: { label: '收录', cap: () => '新上架:最近 30 天才被插件市场收录的,越新越靠前,同一天的按使用量排。' },
|
|
827
944
|
}
|
|
828
945
|
|
|
946
|
+
const OV_ANGLES = ['rec', 'use', 'rep', 'stable', 'rise', 'new']
|
|
947
|
+
// 在综合榜里、但这个角度不参与的原因(规则见 lib/overall.js)
|
|
948
|
+
const OV_MISS = {
|
|
949
|
+
use: '没有去噪后的日常基线(下载太少,没进深挖),不参与「使用」',
|
|
950
|
+
rep: '没有 GitHub 星标,也没被精选或官方收录,不参与「口碑」',
|
|
951
|
+
stable: '上架不满 60 天,或很久没维护,不参与「稳定」',
|
|
952
|
+
rise: '日常基线不到每天 20 次,不参与「增速」',
|
|
953
|
+
new: '被收录超过 30 天,不算新上架',
|
|
954
|
+
}
|
|
955
|
+
let hasOA = false
|
|
956
|
+
|
|
957
|
+
/**
|
|
958
|
+
* 综合榜参与排名的全部插件:每日目录只把每个角度的头部存成完整的行,
|
|
959
|
+
* 其余 npm 插件的六个角度分数存在各自的记录上(rec.oa),这里补成行,分类筛选、算名次都在全部插件里排。
|
|
960
|
+
* 旧目录没有 rec.oa,就只有存下来的那些
|
|
961
|
+
*/
|
|
962
|
+
function overallPool(data) {
|
|
963
|
+
const angles = data.angles || OV_ANGLES
|
|
964
|
+
const seen = new Set(data.rows.map(r => r.k))
|
|
965
|
+
const pool = data.rows.slice()
|
|
966
|
+
hasOA = false
|
|
967
|
+
for (const rec of Object.values(CAT.packages)) {
|
|
968
|
+
if (!rec.oa) continue
|
|
969
|
+
hasOA = true
|
|
970
|
+
if (seen.has(rec.n)) continue
|
|
971
|
+
const d = rec.deep
|
|
972
|
+
const a = Object.fromEntries(angles.map((k, i) => [k, rec.oa[i] ?? null]))
|
|
973
|
+
const row = { k: rec.n, n: rec.n, sc: a.rec, a, src: rec.src || [] }
|
|
974
|
+
if (rec.ad) row.added = rec.ad
|
|
975
|
+
if (rec.gh && rec.gh.s != null) row.s = rec.gh.s
|
|
976
|
+
if (d && Number.isFinite(d.growth)) row.g = Math.round(d.growth * 100) / 100
|
|
977
|
+
const last = (d && d.lastRelease) || (rec.t ? String(rec.t).slice(0, 10) : '')
|
|
978
|
+
if (last) row.last = last
|
|
979
|
+
pool.push(row)
|
|
980
|
+
}
|
|
981
|
+
return pool
|
|
982
|
+
}
|
|
983
|
+
|
|
829
984
|
/**
|
|
830
985
|
* 综合榜:几个插件市场合成一个榜(每日构建时算好,见 lib/overall.js),一个插件一行。
|
|
831
986
|
* 顶部选角度;npm 上的插件能直接装,只在 GitHub 上的先只展示
|
|
@@ -847,22 +1002,32 @@ function renderOverall() {
|
|
|
847
1002
|
return
|
|
848
1003
|
}
|
|
849
1004
|
const cat = $('#rankCat').value
|
|
1005
|
+
rankSig(`overall|${angle}|${cat}`)
|
|
850
1006
|
const valueOf = r => (hasAngles ? r.a[angle] : r.sc)
|
|
851
|
-
|
|
1007
|
+
const pool = overallPool(data)
|
|
1008
|
+
const rows = pool
|
|
852
1009
|
.filter(r => valueOf(r) != null)
|
|
853
1010
|
.map(r => ({ r, rec: r.n ? CAT.packages[r.n] : null }))
|
|
854
1011
|
.filter(({ rec }) => !cat || (rec && rec.cat === cat))
|
|
855
1012
|
rows.sort((x, y) => angle === 'new'
|
|
856
1013
|
? String(y.r.added || '').localeCompare(String(x.r.added || '')) || valueOf(y.r) - valueOf(x.r)
|
|
857
|
-
: valueOf(y.r) - valueOf(x.r))
|
|
858
|
-
|
|
1014
|
+
: valueOf(y.r) - valueOf(x.r) || (y.rec ? y.rec.w || 0 : 0) - (x.rec ? x.rec.w || 0 : 0))
|
|
1015
|
+
const inPool = new Map(pool.map(r => [r.k, r]))
|
|
859
1016
|
// 固定列宽(table.ov):数字列和操作列宽度固定,插件名占剩下的;不然简介把名字一列撑得很宽,
|
|
860
1017
|
// 右边固定的操作列正好盖住数字
|
|
861
|
-
$('#rankHead').innerHTML = '<tr><th style="width:
|
|
1018
|
+
$('#rankHead').innerHTML = '<tr><th style="width:34px">#</th><th>插件</th>' +
|
|
862
1019
|
`<th class="r" style="width:38px" title="这个角度的分数 0~100">${info.label}</th><th class="r" style="width:44px">周下载</th>` +
|
|
863
1020
|
'<th class="r" style="width:38px" title="GitHub 星标">★</th><th class="r" style="width:46px" title="最近一次发版或提交">最近</th>' +
|
|
864
1021
|
'<th style="width:112px"></th></tr>'
|
|
865
|
-
|
|
1022
|
+
const miss = k => {
|
|
1023
|
+
const common = missCommon(k, cat)
|
|
1024
|
+
if (common) return common
|
|
1025
|
+
const r = inPool.get(k)
|
|
1026
|
+
if (r) return OV_MISS[angle] || '这个角度不参与'
|
|
1027
|
+
if (k.startsWith('gh:')) return '只在 GitHub 上、排名靠后的插件综合榜没有存'
|
|
1028
|
+
return CAT.packages[k].oa ? '' : hasOA ? '没进综合榜:仓库已归档、没声明 dsh.bundle,或是终端版插件' : '不在综合榜存下来的前列里(每日目录更新后能看到完整名次)'
|
|
1029
|
+
}
|
|
1030
|
+
paintRank({ all: rows, cols: 7, keysOf: ({ r }) => [r.k], miss, empty: '这个角度下没有插件(或这个分类里没有)。', row: ({ r, rec }, i, on) => {
|
|
866
1031
|
const name = r.n || r.name
|
|
867
1032
|
const v = rec ? rec.v : r.v
|
|
868
1033
|
const w = rec ? rec.w : r.w
|
|
@@ -878,7 +1043,7 @@ function renderOverall() {
|
|
|
878
1043
|
// 能装的:目录里的 npm 包按装前检查给按钮;官方插件不在目录里,名字核对过,也能装
|
|
879
1044
|
const inst = r.n ? installArea(rec || { n: r.n }, { icon: true }) : ''
|
|
880
1045
|
const links = linkBtns(rec || { n: r.n || '', ghUrl: r.repo || '' }, { icon: true })
|
|
881
|
-
return
|
|
1046
|
+
return `${trOpen(on)}${rankCell(i)}` +
|
|
882
1047
|
`<td class="nm"><div class="nmline" title="${esc(name)}${v ? ' v' + esc(v) : ''}">${esc(name)}${v ? ` <span style="color:var(--t3);font-weight:400;font-size:11px">v${esc(v)}</span>` : ''}</div>` +
|
|
883
1048
|
`<div class="chips">${srcChips(r.src, { short: true })}${r.n ? '' : '<span class="srcchip gh" title="只在 GitHub,没发到 npm">GitHub</span>'}</div>` +
|
|
884
1049
|
(desc ? `<div class="sub desc" title="${esc(desc)}">${esc(desc)}</div>` : '') + `</td>` +
|
|
@@ -887,7 +1052,7 @@ function renderOverall() {
|
|
|
887
1052
|
`<td class="r">${r.s != null ? short(r.s) : '—'}</td>` +
|
|
888
1053
|
`<td class="r" title="${esc(r.last || '')}"><span${age != null && age > 90 ? ' class="stale"' : ''}>${age != null ? ageText(age) : '—'}</span></td>` +
|
|
889
1054
|
`<td class="lks">${watchBtn(r.k)}${inst}${links}</td></tr>`
|
|
890
|
-
})
|
|
1055
|
+
} })
|
|
891
1056
|
}
|
|
892
1057
|
|
|
893
1058
|
function renderRank() {
|
|
@@ -913,6 +1078,7 @@ function renderRank() {
|
|
|
913
1078
|
return
|
|
914
1079
|
}
|
|
915
1080
|
|
|
1081
|
+
rankSig(`${board}|${metric}|${cat}`)
|
|
916
1082
|
if (board === 'gh') {
|
|
917
1083
|
$('#rankCap').textContent = '按 GitHub 仓库数据:星标看关注度,最近提交看还有没有人在维护。一个仓库只列一行;仓库填成 DSH 本体的不算。'
|
|
918
1084
|
const val = r => metric === 'gs' ? r.gh.s
|
|
@@ -930,14 +1096,25 @@ function renderRank() {
|
|
|
930
1096
|
else { cur.n++; if (r.w > cur.r.w) cur.r = r }
|
|
931
1097
|
}
|
|
932
1098
|
const shared = new Map([...byRepo.values()].map(x => [x.r.n, x.n]))
|
|
933
|
-
|
|
1099
|
+
// 一行代表一个仓库:这个仓库里的插件都算这一行(监控了其中任何一个,都高亮这一行)
|
|
1100
|
+
const repoKeys = new Map()
|
|
1101
|
+
for (const r of Object.values(CAT.packages)) {
|
|
1102
|
+
if (!r.gh) continue
|
|
1103
|
+
const k = r.gh.repo.toLowerCase()
|
|
1104
|
+
if (!repoKeys.has(k)) repoKeys.set(k, [])
|
|
1105
|
+
repoKeys.get(k).push(r.n)
|
|
1106
|
+
}
|
|
1107
|
+
const rows = [...byRepo.values()].map(x => x.r).sort((x, y) => val(y) - val(x))
|
|
934
1108
|
$('#rankHead').innerHTML = '<tr><th style="width:44px">#</th><th>插件</th><th>分类</th>' +
|
|
935
1109
|
'<th class="r">★ 星标</th><th class="r">Fork</th><th class="r" title="未关闭的 issue 与 PR">讨论</th>' +
|
|
936
1110
|
'<th class="r" title="仓库最近一次提交">最近提交</th><th></th></tr>'
|
|
937
|
-
|
|
1111
|
+
paintRank({
|
|
1112
|
+
all: rows, cols: 8, empty: '目录里还没有 GitHub 数据(每日更新取到后就有)。',
|
|
1113
|
+
keysOf: r => repoKeys.get(r.gh.repo.toLowerCase()) || [r.n],
|
|
1114
|
+
miss: k => missCommon(k, cat) || '目录里没有它的 GitHub 仓库数据(没填仓库地址,或仓库填成了 DSH 本体)',
|
|
1115
|
+
row: (r, i, on) => {
|
|
938
1116
|
const age = daysSince(r.gh.p)
|
|
939
|
-
return
|
|
940
|
-
`<td style="color:var(--t3)">${i + 1}</td>` +
|
|
1117
|
+
return trOpen(on) + rankCell(i) +
|
|
941
1118
|
`<td class="nm">${esc(r.n)} <span style="color:var(--t3);font-weight:400;font-size:11px">v${esc(r.v)}</span>` +
|
|
942
1119
|
(shared.get(r.n) > 1 ? `<div class="sub" title="仓库 ${esc(r.gh.repo)} 里有 ${shared.get(r.n)} 个插件,数据相同,只列一行">等 ${shared.get(r.n)} 个插件共用这个仓库</div>` : '') +
|
|
943
1120
|
`</td>` +
|
|
@@ -948,7 +1125,7 @@ function renderRank() {
|
|
|
948
1125
|
`<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>` +
|
|
949
1126
|
`<td class="lks">${watchBtn(r.n)}${linkBtns(r, { icon: true })}</td>` +
|
|
950
1127
|
`</tr>`
|
|
951
|
-
})
|
|
1128
|
+
} })
|
|
952
1129
|
return
|
|
953
1130
|
}
|
|
954
1131
|
|
|
@@ -958,15 +1135,17 @@ function renderRank() {
|
|
|
958
1135
|
: metric === 'growth' ? (r.deep.growth === null ? -Infinity : r.deep.growth)
|
|
959
1136
|
: metric === 's' ? r.deep.s
|
|
960
1137
|
: r.w
|
|
961
|
-
const rows = Object.values(CAT.packages).filter(r => inCat(r) && (!onlyDeep || r.deep)).sort((x, y) => val(y) - val(x))
|
|
1138
|
+
const rows = Object.values(CAT.packages).filter(r => inCat(r) && (!onlyDeep || r.deep)).sort((x, y) => val(y) - val(x))
|
|
962
1139
|
$('#rankHead').innerHTML = '<tr><th style="width:44px">#</th><th>插件</th><th>分类</th>' +
|
|
963
1140
|
`<th class="r">基线</th><th class="r">周下载</th><th class="r">环比</th>${metric === 's' ? '<th class="r">健康度</th>' : ''}` +
|
|
964
1141
|
'<th class="r" title="最近一次发版 · 平均几天发一个版本">更新</th><th></th></tr>'
|
|
965
|
-
|
|
1142
|
+
paintRank({
|
|
1143
|
+
all: rows, cols: metric === 's' ? 9 : 8, empty: '这个分类里没有插件。', keysOf: r => [r.n],
|
|
1144
|
+
miss: k => missCommon(k, cat) || (k.startsWith('gh:') ? '只在 GitHub 上,没发到 npm' : '没有去噪数据(下载太少,没进深挖),这一项排不了;切到「周下载」能看到它的名次'),
|
|
1145
|
+
row: (r, i, on) => {
|
|
966
1146
|
const d = r.deep
|
|
967
1147
|
const g = d ? d.growth : null
|
|
968
|
-
return
|
|
969
|
-
`<td style="color:var(--t3)">${i + 1}</td>` + nameCell(r) +
|
|
1148
|
+
return trOpen(on) + rankCell(i) + nameCell(r) +
|
|
970
1149
|
`<td><span class="catpill">${esc(r.cat)}</span></td>` +
|
|
971
1150
|
`<td class="r">${b(metric === 'base', d ? num(d.base) : '—')}</td>` +
|
|
972
1151
|
`<td class="r">${b(metric === 'w', num(r.w))}</td>` +
|
|
@@ -975,7 +1154,7 @@ function renderRank() {
|
|
|
975
1154
|
maintCell(d) +
|
|
976
1155
|
`<td class="lks">${watchBtn(r.n)}${linkBtns(r, { icon: true })}</td>` +
|
|
977
1156
|
`</tr>`
|
|
978
|
-
})
|
|
1157
|
+
} })
|
|
979
1158
|
}
|
|
980
1159
|
|
|
981
1160
|
/* ---------------- 我的监控 ---------------- */
|
|
@@ -1014,6 +1193,9 @@ function toggleWatch(key) {
|
|
|
1014
1193
|
b.textContent = now ? '✓' : '+'
|
|
1015
1194
|
b.title = now ? '已在我的监控里,点一下移除' : '加入我的监控'
|
|
1016
1195
|
b.setAttribute('aria-label', now ? '移出我的监控' : '加入我的监控')
|
|
1196
|
+
// 排行榜里这一行跟着高亮(不重画整张表,免得滚动位置跳走)
|
|
1197
|
+
const tr = b.closest('table.rank tr')
|
|
1198
|
+
if (tr) tr.classList.toggle('watched', now)
|
|
1017
1199
|
})
|
|
1018
1200
|
}
|
|
1019
1201
|
|
|
@@ -1046,24 +1228,244 @@ function watchRec(n) {
|
|
|
1046
1228
|
const gh = live && live.found ? live.gh : (inBoard && inBoard.s != null ? { repo, s: inBoard.s, f: null, i: null, p: null, a: false } : null)
|
|
1047
1229
|
return { n: '', label: repo, cat: '只在 GitHub', w: null, m: null, deep: null, ghUrl: url, gh, live: Boolean(live && live.found) }
|
|
1048
1230
|
}
|
|
1049
|
-
|
|
1050
|
-
|
|
1231
|
+
return mergeLive(CAT.packages[n], LIVE.rows[n], n)
|
|
1232
|
+
}
|
|
1233
|
+
|
|
1234
|
+
/**
|
|
1235
|
+
* 目录记录 + 实时查到的数据(/live 的一行)→ 一条记录,字段用目录的短名,后面的代码不用分两套。
|
|
1236
|
+
* 实时的覆盖目录的;npm 下载接口偶尔限流查不到时,保留目录里的指标,别把有的数据冲掉
|
|
1237
|
+
*/
|
|
1238
|
+
function mergeLive(base, live, n) {
|
|
1051
1239
|
if (!live || !live.found) return base || null
|
|
1052
1240
|
const d = live.deep
|
|
1053
1241
|
return {
|
|
1054
1242
|
...(base || { n, cat: '(目录外)' }),
|
|
1055
1243
|
n,
|
|
1056
1244
|
v: live.latest || (base && base.v),
|
|
1245
|
+
d: (base && base.d) || live.description || '',
|
|
1057
1246
|
w: live.weekly,
|
|
1058
1247
|
m: live.monthly,
|
|
1059
|
-
// npm 下载接口偶尔限流查不到:保留目录里的指标,别把有的数据冲掉
|
|
1060
1248
|
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,
|
|
1061
1249
|
gh: live.gh || (base && base.gh) || null,
|
|
1250
|
+
total: live.total ?? null,
|
|
1251
|
+
daily: live.daily || null,
|
|
1252
|
+
dailyStart: live.dailyStart || null,
|
|
1062
1253
|
live: true,
|
|
1063
1254
|
catalogW: base ? base.w : null,
|
|
1064
1255
|
}
|
|
1065
1256
|
}
|
|
1066
1257
|
|
|
1258
|
+
/* ---------------- 比较里的插件:没有去噪数据的,实时算一份 ---------------- */
|
|
1259
|
+
// 去噪指标每日构建时只给周下载前 300 多名算;自己加进比较的插件多半在这之外,就去 npm 当场算
|
|
1260
|
+
const CMP_LIVE = new Map() // 包名 → /live 的一行
|
|
1261
|
+
const CMP_PENDING = new Set()
|
|
1262
|
+
function cmpRec(n) {
|
|
1263
|
+
return CMP_LIVE.has(n) ? mergeLive(CAT.packages[n], CMP_LIVE.get(n), n) : CAT.packages[n]
|
|
1264
|
+
}
|
|
1265
|
+
async function fillCompareLive() {
|
|
1266
|
+
const need = picked.filter(n => CAT.packages[n] && !CAT.packages[n].deep && !CMP_LIVE.has(n) && !CMP_PENDING.has(n))
|
|
1267
|
+
if (!need.length) return
|
|
1268
|
+
need.forEach(n => CMP_PENDING.add(n))
|
|
1269
|
+
renderCompare()
|
|
1270
|
+
try {
|
|
1271
|
+
const r = await fetch(`${P.live}?names=${encodeURIComponent(need.join(','))}`, { cache: 'no-store' })
|
|
1272
|
+
const j = await r.json()
|
|
1273
|
+
if (r.ok) for (const row of j.rows || []) if (row.found) CMP_LIVE.set(row.name, row)
|
|
1274
|
+
} catch { /* 查不到就按目录里的显示 */ }
|
|
1275
|
+
need.forEach(n => CMP_PENDING.delete(n))
|
|
1276
|
+
renderCompare()
|
|
1277
|
+
}
|
|
1278
|
+
|
|
1279
|
+
/* ---------------- 监控详情:快照历史、走势图、各项数据 ---------------- */
|
|
1280
|
+
// 每次刷新在本机存一份快照(每个插件最多 30 份),「较上次」就是和上一份比
|
|
1281
|
+
const HIST_KEY = 'dsh-pick-watch-history-v1'
|
|
1282
|
+
function loadHistory() {
|
|
1283
|
+
try { return JSON.parse(localStorage.getItem(HIST_KEY)) || {} } catch { return {} }
|
|
1284
|
+
}
|
|
1285
|
+
function saveSnapshots(at) {
|
|
1286
|
+
const hist = loadHistory()
|
|
1287
|
+
for (const n of watch()) {
|
|
1288
|
+
const r = watchRec(n)
|
|
1289
|
+
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 }
|
|
1291
|
+
const list = (hist[n] || []).filter(x => x.t !== at)
|
|
1292
|
+
list.push(snap)
|
|
1293
|
+
hist[n] = list.slice(-30)
|
|
1294
|
+
}
|
|
1295
|
+
try { localStorage.setItem(HIST_KEY, JSON.stringify(hist)) } catch { /* 存不下就不记 */ }
|
|
1296
|
+
}
|
|
1297
|
+
/** 和上一份快照比:返回「较上次」的小字 */
|
|
1298
|
+
function changeOf(n, key, now, { lowerIsBetter = false, asPct = true } = {}) {
|
|
1299
|
+
const list = loadHistory()[n] || []
|
|
1300
|
+
const prev = list.length >= 2 ? list[list.length - 2] : null
|
|
1301
|
+
if (!prev || prev[key] == null || now == null) return ''
|
|
1302
|
+
const diff = now - prev[key]
|
|
1303
|
+
const when = new Date(prev.t).toLocaleDateString()
|
|
1304
|
+
if (diff === 0) return `<span class="ch flat" title="和 ${esc(when)} 刷新时一样">较上次持平</span>`
|
|
1305
|
+
const good = lowerIsBetter ? diff < 0 : diff > 0
|
|
1306
|
+
// 排名数字越小越好:用「升 / 降 几名」说,正负号容易看反
|
|
1307
|
+
const txt = lowerIsBetter ? `${diff < 0 ? '升' : '降'} ${num(Math.abs(diff))} 名`
|
|
1308
|
+
: asPct && prev[key] ? `${diff > 0 ? '+' : ''}${Math.round(diff / prev[key] * 100)}%` : `${diff > 0 ? '+' : ''}${num(diff)}`
|
|
1309
|
+
return `<span class="ch ${good ? 'up' : 'down'}" title="和 ${esc(when)} 刷新时相比">较上次 ${txt}</span>`
|
|
1310
|
+
}
|
|
1311
|
+
/** 30 天每日下载的走势小图(缺数据的日子断开) */
|
|
1312
|
+
function sparkSvg(daily, color) {
|
|
1313
|
+
if (!daily || !daily.some(v => v != null)) return ''
|
|
1314
|
+
const W = 120, H = 30
|
|
1315
|
+
const max = Math.max(1, ...daily.filter(v => v != null))
|
|
1316
|
+
const x = i => (i / (daily.length - 1)) * (W - 2) + 1
|
|
1317
|
+
const y = v => H - 2 - (v / max) * (H - 4)
|
|
1318
|
+
const segs = []
|
|
1319
|
+
let cur = []
|
|
1320
|
+
daily.forEach((v, i) => {
|
|
1321
|
+
if (v == null) { if (cur.length) segs.push(cur); cur = []; return }
|
|
1322
|
+
cur.push(`${x(i).toFixed(1)},${y(v).toFixed(1)}`)
|
|
1323
|
+
})
|
|
1324
|
+
if (cur.length) segs.push(cur)
|
|
1325
|
+
return `<svg class="spark" width="${W}" height="${H}" viewBox="0 0 ${W} ${H}" role="img" aria-label="30 天每日下载走势,最高 ${num(max)}">` +
|
|
1326
|
+
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
|
+
'</svg>'
|
|
1328
|
+
}
|
|
1329
|
+
/** 在综合榜某个角度里排第几(只在存下来的头部里找) */
|
|
1330
|
+
// 综合榜每个角度的完整名次(和排行榜同一套排法),算一次存着,监控详情重画时清掉
|
|
1331
|
+
let ANGLE_ORDER = new Map()
|
|
1332
|
+
function angleRank(key, angle) {
|
|
1333
|
+
const o = CAT.boards && CAT.boards.overall
|
|
1334
|
+
if (!o || !o.rows.length || !o.rows[0].a) return null
|
|
1335
|
+
if (!ANGLE_ORDER.has(angle)) {
|
|
1336
|
+
const w = r => (r.n && CAT.packages[r.n] ? CAT.packages[r.n].w || 0 : 0)
|
|
1337
|
+
const rows = overallPool(o).filter(r => r.a[angle] != null)
|
|
1338
|
+
.sort((x, y) => angle === 'new' ? String(y.added || '').localeCompare(String(x.added || '')) || y.a.new - x.a.new : y.a[angle] - x.a[angle] || w(y) - w(x))
|
|
1339
|
+
ANGLE_ORDER.set(angle, new Map(rows.map((r, i) => [r.k, i + 1])))
|
|
1340
|
+
}
|
|
1341
|
+
return ANGLE_ORDER.get(angle).get(key) || null
|
|
1342
|
+
}
|
|
1343
|
+
|
|
1344
|
+
function renderWatchDetail(list) {
|
|
1345
|
+
const sec = $('#secWatchDetail')
|
|
1346
|
+
if (!list.length) { sec.classList.add('hidden'); return }
|
|
1347
|
+
sec.classList.remove('hidden')
|
|
1348
|
+
$('#wdAsOf').textContent = LIVE.at ? `· ${new Date(LIVE.at).toLocaleString()} 刷新` : '· 还没刷新过,先显示目录数据'
|
|
1349
|
+
ANGLE_ORDER = new Map()
|
|
1350
|
+
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
|
+
const ANG = { rec: '综合', use: '使用', rep: '口碑', stable: '稳定', rise: '增速' }
|
|
1354
|
+
const cell = (r, fn) => (r ? fn(r) : '—')
|
|
1355
|
+
const rows = [
|
|
1356
|
+
['下载'],
|
|
1357
|
+
['30 天每日下载', ({ r }, i) => cell(r, x => (x.daily ? sparkSvg(x.daily, colorOf(i)) : '<span style="color:var(--t3)">刷新后显示</span>'))],
|
|
1358
|
+
['周下载', ({ n, r }) => cell(r, x => (x.w != null ? `<b>${num(x.w)}</b>${changeOf(n, 'w', x.w)}` : '—'))],
|
|
1359
|
+
['上周(前 7 天)', ({ r }) => cell(r, x => {
|
|
1360
|
+
const v = (x.daily || []).filter(d => d != null)
|
|
1361
|
+
return v.length >= 14 ? num(v.slice(-14, -7).reduce((a, b) => a + b, 0)) : '—'
|
|
1362
|
+
})],
|
|
1363
|
+
['日常基线(去噪)', ({ n, r }) => cell(r, x => (x.deep ? `${num(x.deep.base)}/天${changeOf(n, 'base', x.deep.base)}` : '—'))],
|
|
1364
|
+
['近 7 日环比', ({ r }) => cell(r, x => (x.deep && x.deep.growth != null ? `<span class="${x.deep.growth >= 0 ? 'up' : 'down'}">${pct(x.deep.growth)}</span>` : '—'))],
|
|
1365
|
+
['月下载', ({ r }) => cell(r, x => (x.m != null ? num(x.m) : '—'))],
|
|
1366
|
+
['累计下载', ({ r }) => cell(r, x => (x.total != null ? num(x.total) : '—'))],
|
|
1367
|
+
['版本'],
|
|
1368
|
+
['当前版本', ({ r }) => cell(r, x => (x.v ? `v${esc(x.v)}` : '—'))],
|
|
1369
|
+
['最近发版', ({ r }) => cell(r, x => (x.deep && x.deep.lastRelease ? `${esc(x.deep.lastRelease)}<span class="ch flat">${ageText(x.deep.age)}</span>` : '—'))],
|
|
1370
|
+
['版本总数', ({ r }) => cell(r, x => (x.deep && x.deep.versions != null ? num(x.deep.versions) : '—'))],
|
|
1371
|
+
['发版节奏', ({ r }) => cell(r, x => (x.deep && x.deep.cadence != null ? `${x.deep.cadence} 天/版` : '—'))],
|
|
1372
|
+
['健康度', ({ r }) => cell(r, x => (x.deep && x.deep.s != null ? x.deep.s : '—'))],
|
|
1373
|
+
['GitHub'],
|
|
1374
|
+
['星标', ({ n, r }) => cell(r, x => (x.gh ? `${num(x.gh.s)}${changeOf(n, 's', x.gh.s, { asPct: false })}` : '—'))],
|
|
1375
|
+
['Fork', ({ r }) => cell(r, x => (x.gh && x.gh.f != null ? num(x.gh.f) : '—'))],
|
|
1376
|
+
['未关闭 issue / PR', ({ r }) => cell(r, x => (x.gh && x.gh.i != null ? num(x.gh.i) : '—'))],
|
|
1377
|
+
['最近提交', ({ r }) => cell(r, x => (x.gh && x.gh.p ? `${esc(x.gh.p)}${x.gh.a ? '<span class="ch down">已归档</span>' : ''}` : '—'))],
|
|
1378
|
+
['市场位置'],
|
|
1379
|
+
['npm 总榜', ({ n, r }) => cell(r, x => (x.rank ? `#${num(x.rank)}${changeOf(n, 'rank', x.rank, { lowerIsBetter: true, asPct: false })}` : '—'))],
|
|
1380
|
+
['分类排名', ({ r }) => cell(r, x => (x.crank ? `${esc(x.cat)} #${num(x.crank)}` : '—'))],
|
|
1381
|
+
['综合榜排名', ({ n, r }) => cell(r, () => {
|
|
1382
|
+
const parts = Object.entries(ANG).map(([a, label]) => [label, angleRank(n, a)]).filter(([, v]) => v)
|
|
1383
|
+
return parts.length ? parts.map(([l, v]) => `${l} #${v}`).join('<br>') : '<span style="color:var(--t3)">没进综合榜</span>'
|
|
1384
|
+
})],
|
|
1385
|
+
['综合推荐分', ({ n, r }) => cell(r, x => (x.sc != null ? `${x.sc}${changeOf(n, 'sc', x.sc, { asPct: false })}` : '—'))],
|
|
1386
|
+
['收录于', ({ r }) => cell(r, x => (x.src && x.src.length ? srcChips(x.src, { short: true }) : '—'))],
|
|
1387
|
+
]
|
|
1388
|
+
$('#wdBody').innerHTML = rows.map(([label, fn]) => (fn
|
|
1389
|
+
? `<tr><td>${label}</td>${recs.map((x, i) => `<td>${fn(x, i)}</td>`).join('')}</tr>`
|
|
1390
|
+
: `<tr class="grp"><td colspan="${recs.length + 1}">${label}</td></tr>`)).join('')
|
|
1391
|
+
// 窄屏版:同一份指标,按指标分块,每块一行一个插件
|
|
1392
|
+
const names = recs.map(({ n, r }, i) => `<span class="nm" title="${esc((r && r.label) || n)}"><i style="background:${colorOf(i)}"></i>${esc((r && r.label) || n)}</span>`)
|
|
1393
|
+
$('#wdStack').innerHTML = rows.map(([label, fn]) => (fn
|
|
1394
|
+
? `<div class="m"><div class="ml">${label}</div>${recs.map((x, i) => `<div class="r">${names[i]}<span class="v">${fn(x, i)}</span></div>`).join('')}</div>`
|
|
1395
|
+
: `<div class="grp">${label}</div>`)).join('')
|
|
1396
|
+
WD_COUNT = recs.length
|
|
1397
|
+
layoutWatchDetail()
|
|
1398
|
+
}
|
|
1399
|
+
|
|
1400
|
+
/**
|
|
1401
|
+
* 监控详情选版式:右侧栏放得下整张表(每个插件一列)就用表格,放不下就用按指标分块的竖排版
|
|
1402
|
+
* (手机那样只往下长,不用横着滚)。直接量表格的实际宽度:插件名长短、有没有「较上次」都会影响列宽,估不准。
|
|
1403
|
+
* 拖动侧栏宽度时跟着切换
|
|
1404
|
+
*/
|
|
1405
|
+
let WD_COUNT = 0
|
|
1406
|
+
function layoutWatchDetail() {
|
|
1407
|
+
const wrap = $('#wdTable')
|
|
1408
|
+
if (!$('#secWatchDetail').clientWidth || !WD_COUNT) return // 标签页没显示时量不出宽度,显示出来再量
|
|
1409
|
+
wrap.classList.remove('hidden')
|
|
1410
|
+
const fits = wrap.scrollWidth <= wrap.clientWidth + 1
|
|
1411
|
+
wrap.classList.toggle('hidden', !fits)
|
|
1412
|
+
$('#wdStack').classList.toggle('hidden', fits)
|
|
1413
|
+
}
|
|
1414
|
+
if (typeof ResizeObserver !== 'undefined') {
|
|
1415
|
+
let lastW = 0
|
|
1416
|
+
new ResizeObserver(entries => {
|
|
1417
|
+
const w = Math.round(entries[0].contentRect.width)
|
|
1418
|
+
if (w !== lastW) { lastW = w; layoutWatchDetail() }
|
|
1419
|
+
}).observe(document.getElementById('secWatchDetail'))
|
|
1420
|
+
}
|
|
1421
|
+
// 保险:有的环境(后台页、老内核)不触发 ResizeObserver,窗口大小变了也量一次;切到「我的监控」时也会量
|
|
1422
|
+
window.addEventListener('resize', () => layoutWatchDetail())
|
|
1423
|
+
|
|
1424
|
+
/**
|
|
1425
|
+
* 用户输入 → 监控名:目录里的包名直接用;GitHub 地址或 owner/repo:目录里有发到 npm 的就记包名,
|
|
1426
|
+
* 没有就记 gh:owner/repo;其余像 npm 包名的也收(目录外的插件,刷新时去 npm 查)。认不出返回 ''
|
|
1427
|
+
*/
|
|
1428
|
+
function watchKeyOf(text) {
|
|
1429
|
+
const t = text.trim().replace(/\/+$/, '').replace(/\.git$/, '')
|
|
1430
|
+
if (CAT.packages[t]) return t
|
|
1431
|
+
const lower = t.toLowerCase()
|
|
1432
|
+
if (CAT.packages[lower]) return lower
|
|
1433
|
+
const gh = /^(?:https?:\/\/)?(?:www\.)?github\.com\/([A-Za-z0-9_.-]+)\/([A-Za-z0-9_.-]+)/.exec(t) || (!t.startsWith('@') && /^([A-Za-z0-9_.-]+)\/([A-Za-z0-9_.-]+)$/.exec(t))
|
|
1434
|
+
if (gh) {
|
|
1435
|
+
const repo = `${gh[1]}/${gh[2]}`
|
|
1436
|
+
const hit = Object.values(CAT.packages).filter(r => r.gh && r.gh.repo.toLowerCase() === repo.toLowerCase()).sort((a, b) => (b.w || 0) - (a.w || 0))[0]
|
|
1437
|
+
return hit ? hit.n : 'gh:' + repo
|
|
1438
|
+
}
|
|
1439
|
+
const npm = /^(?:https?:\/\/)?(?:www\.)?npmjs\.com\/package\/(.+)$/.exec(t)
|
|
1440
|
+
const name = (npm ? decodeURIComponent(npm[1]) : t).toLowerCase()
|
|
1441
|
+
return /^(@[a-z0-9._-]+\/)?[a-z0-9._-]+$/.test(name) ? name : ''
|
|
1442
|
+
}
|
|
1443
|
+
|
|
1444
|
+
/** 「+ 添加」:加进监控,再只查这一个的实时数据(不动「较上次」用的快照) */
|
|
1445
|
+
function addToWatch(text) {
|
|
1446
|
+
const key = watchKeyOf(text)
|
|
1447
|
+
if (!key) { toast(`认不出「${text}」:输入 npm 包名,或 GitHub 仓库地址`); return false }
|
|
1448
|
+
if (watch().includes(key)) { toast(`已经在我的监控里了:${watchName(key)}`); return true }
|
|
1449
|
+
const before = watch().length
|
|
1450
|
+
toggleWatch(key)
|
|
1451
|
+
if (watch().length === before) return false // 满 30 个,toggleWatch 已提示
|
|
1452
|
+
fetchLiveOne(key)
|
|
1453
|
+
return true
|
|
1454
|
+
}
|
|
1455
|
+
async function fetchLiveOne(key) {
|
|
1456
|
+
try {
|
|
1457
|
+
const r = await fetch(`${P.live}?names=${encodeURIComponent(key)}`, { cache: 'no-store' })
|
|
1458
|
+
const j = await r.json()
|
|
1459
|
+
if (!r.ok) throw new Error(j.error || 'HTTP ' + r.status)
|
|
1460
|
+
const row = j.rows.find(x => x.name === key)
|
|
1461
|
+
if (!row) return
|
|
1462
|
+
LIVE = { ...LIVE, rows: { ...LIVE.rows, [key]: row } }
|
|
1463
|
+
try { localStorage.setItem(LIVE_KEY, JSON.stringify(LIVE)) } catch { /* 存不下就只这次有效 */ }
|
|
1464
|
+
if (!row.found) toast(`${watchName(key)}:${key.startsWith('gh:') ? 'GitHub 上查不到这个仓库' : 'npm 上查不到这个包'},检查一下名字(不要的话点 × 移除)`)
|
|
1465
|
+
renderWatch()
|
|
1466
|
+
} catch { /* 没网就先显示目录数据,点「刷新」再查 */ }
|
|
1467
|
+
}
|
|
1468
|
+
|
|
1067
1469
|
async function refreshWatch() {
|
|
1068
1470
|
const list = watch()
|
|
1069
1471
|
if (!list.length) return
|
|
@@ -1076,6 +1478,7 @@ async function refreshWatch() {
|
|
|
1076
1478
|
if (!r.ok) throw new Error(j.error || 'HTTP ' + r.status)
|
|
1077
1479
|
LIVE = { at: j.at, anchor: j.anchor, rows: Object.fromEntries(j.rows.map(x => [x.name, x])) }
|
|
1078
1480
|
try { localStorage.setItem(LIVE_KEY, JSON.stringify(LIVE)) } catch { /* 存不下就只这次有效 */ }
|
|
1481
|
+
saveSnapshots(j.at)
|
|
1079
1482
|
const miss = j.rows.filter(x => !x.found).map(x => x.name)
|
|
1080
1483
|
toast([
|
|
1081
1484
|
miss.length ? `已刷新;npm 上查不到:${miss.join('、')}` : `已刷新 ${j.rows.length} 个插件`,
|
|
@@ -1098,7 +1501,8 @@ function renderWatch() {
|
|
|
1098
1501
|
: `现在显示的是目录数据(截止 <b>${esc(CAT.anchor)}</b>)。`
|
|
1099
1502
|
const host = $('#watchList')
|
|
1100
1503
|
if (!list.length) {
|
|
1101
|
-
|
|
1504
|
+
$('#watchAdd').classList.remove('hidden') // 空的时候直接摆出输入框
|
|
1505
|
+
host.innerHTML = '<div class="empty">还没有监控的插件。点上面的「+ 添加」输入插件名,或在「选插件」、排行榜里点彩色的 +。</div>'
|
|
1102
1506
|
$('#watchChart').innerHTML = ''
|
|
1103
1507
|
return
|
|
1104
1508
|
}
|
|
@@ -1140,6 +1544,8 @@ function renderWatch() {
|
|
|
1140
1544
|
host.querySelectorAll('[data-rm]').forEach(b =>
|
|
1141
1545
|
b.addEventListener('click', () => saveWatch(watch().filter(x => x !== b.dataset.rm)) || renderWatch()))
|
|
1142
1546
|
|
|
1547
|
+
renderWatchDetail(list)
|
|
1548
|
+
|
|
1143
1549
|
// 对数刻度横条图
|
|
1144
1550
|
const rows = list.map(watchRec).filter(r => r && r.w != null)
|
|
1145
1551
|
const max = Math.max(...rows.map(r => r.w), 1)
|
|
@@ -1154,7 +1560,7 @@ function renderWatch() {
|
|
|
1154
1560
|
|
|
1155
1561
|
/* ---------------- 导出结论(网页版) ---------------- */
|
|
1156
1562
|
function exportHtml() {
|
|
1157
|
-
const rows = picked.map(
|
|
1563
|
+
const rows = picked.map(cmpRec).filter(Boolean)
|
|
1158
1564
|
if (!rows.length) return
|
|
1159
1565
|
const need = $('#need').value.trim()
|
|
1160
1566
|
const verdicts = $('#verdicts').innerHTML
|