github-overview 0.1.2 → 0.2.0
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 +28 -10
- package/bin/cli.mjs +57 -24
- package/docs/screenshot-dark.png +0 -0
- package/docs/screenshot-light.png +0 -0
- package/package.json +1 -1
- package/public/index.html +1261 -120
- package/src/auth.mjs +279 -0
- package/src/config.mjs +37 -2
- package/src/github.mjs +122 -34
- package/src/loop.mjs +67 -0
- package/src/npm.mjs +14 -12
- package/src/server.mjs +988 -74
- package/src/store.mjs +74 -19
- package/src/summary.mjs +270 -20
package/public/index.html
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
<meta charset="utf-8">
|
|
5
5
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
6
6
|
<title>github-overview</title>
|
|
7
|
+
<link rel="icon" href="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Crect width='16' height='16' rx='3' fill='%230f1115'/%3E%3Cpath d='M4 11V6l4-2 4 2v5' fill='none' stroke='%234f8cff' stroke-width='1.6' stroke-linejoin='round'/%3E%3C/svg%3E">
|
|
7
8
|
<style>
|
|
8
9
|
:root[data-theme="dark"] {
|
|
9
10
|
--bg-base: #0f1115;
|
|
@@ -28,7 +29,7 @@
|
|
|
28
29
|
--label-primary: #12161d;
|
|
29
30
|
--label-secondary: #5c6472;
|
|
30
31
|
--brand: #2b62d9;
|
|
31
|
-
--machine: #
|
|
32
|
+
--machine: #5f6873;
|
|
32
33
|
--event: #a8761b;
|
|
33
34
|
--success: #1a7f37;
|
|
34
35
|
--shadow: 0 8px 28px rgba(16,24,40,.12);
|
|
@@ -62,15 +63,41 @@
|
|
|
62
63
|
.repo { font-size: 16px; font-weight: 600; white-space: nowrap; }
|
|
63
64
|
.repo span { color: var(--label-secondary); font-weight: 400; }
|
|
64
65
|
.caret { color: var(--label-secondary); font-weight: 400; }
|
|
66
|
+
.repo-wrap { position: relative; display: flex; align-items: center; gap: 4px; }
|
|
67
|
+
.repo-open { display: inline-flex; width: 20px; height: 20px; align-items: center; justify-content: center;
|
|
68
|
+
border-radius: 6px; color: var(--label-secondary); }
|
|
69
|
+
.repo-open:hover { background: var(--border-l1); color: var(--label-primary); }
|
|
70
|
+
.repo-open[hidden] { display: none; }
|
|
71
|
+
.repo-wrap > .repo { border: 0; background: none; padding: 0; font: inherit; font-weight: 600; color: var(--label-primary); cursor: pointer; }
|
|
72
|
+
.repo-wrap > .repo:hover { color: var(--label-secondary); }
|
|
73
|
+
.repo-menu { position: absolute; top: 26px; left: -8px; z-index: 20; min-width: 200px; max-height: 260px; overflow: auto;
|
|
74
|
+
padding: 6px; background: var(--bg-layer-2); border: 1px solid var(--border-l2); border-radius: 8px; }
|
|
75
|
+
.repo-menu button { display: flex; width: 100%; height: 30px; align-items: center; border: 0; border-radius: 8px; padding: 0 8px;
|
|
76
|
+
background: none; color: var(--label-primary); font-size: 12px; text-align: left; }
|
|
77
|
+
.repo-menu button:hover, .repo-menu button.on { background: var(--border-l1); }
|
|
65
78
|
.spacer { flex: 1; }
|
|
66
79
|
.seg { display: inline-flex; border: 1px solid var(--border-l2); border-radius: 8px; overflow: hidden; height: 28px; }
|
|
67
80
|
.seg button { border: 0; border-radius: 0; height: 26px; margin: 1px; padding: 0 10px; color: var(--label-secondary); }
|
|
68
|
-
.seg button.on { background: var(--bg-layer-2); color: var(--label-primary); }
|
|
81
|
+
.seg button.on { background: var(--bg-layer-2); color: var(--label-primary); font-weight: 600; }
|
|
82
|
+
[data-theme="light"] .seg button.on { box-shadow: inset 0 0 0 1px var(--border-l2); }
|
|
69
83
|
|
|
70
84
|
.kpis { display: grid; grid-template-columns: repeat(5, 1fr); gap: 4px 28px; padding: 18px 0 2px; }
|
|
71
85
|
.kpi-label { font-size: 12px; color: var(--label-secondary); }
|
|
72
86
|
.kpi-value { font-size: 24px; font-weight: 600; letter-spacing: -.02em; line-height: 1.35; }
|
|
73
87
|
.kpi-sub { font-size: 12px; color: var(--label-secondary); }
|
|
88
|
+
.head-note { font-size: 12px; font-weight: 400; color: var(--label-secondary); margin-left: 6px; }
|
|
89
|
+
#sec-top { margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--border-l1); }
|
|
90
|
+
#fork-stats { grid-template-columns: 1fr 1fr; }
|
|
91
|
+
#fork-list { margin-top: 10px; }
|
|
92
|
+
#fork-list td:first-child { font-size: 13px; font-weight: 400; }
|
|
93
|
+
.leaders { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px 28px; padding: 14px 0 4px; }
|
|
94
|
+
.lead { min-width: 0; }
|
|
95
|
+
.lead-label { font-size: 12px; color: var(--label-secondary); }
|
|
96
|
+
.lead-name { font-size: 12px; color: var(--label-primary); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
|
|
97
|
+
.lead-value { font-size: 24px; font-weight: 600; letter-spacing: -.02em; line-height: 1.35; font-variant-numeric: tabular-nums; }
|
|
98
|
+
.lead-sub { font-size: 12px; color: var(--label-secondary); }
|
|
99
|
+
.lead[data-key] { cursor: pointer; }
|
|
100
|
+
.lead[data-key]:hover .lead-name { color: var(--brand); }
|
|
74
101
|
.up { color: var(--success); }
|
|
75
102
|
|
|
76
103
|
.cols { display: grid; grid-template-columns: minmax(0, 1fr) 318px; min-width: 0; gap: 30px; margin-top: 20px; align-items: start; }
|
|
@@ -101,6 +128,7 @@
|
|
|
101
128
|
.donut-legend span { display: inline-flex; align-items: center; gap: 6px; color: var(--label-secondary); white-space: nowrap; }
|
|
102
129
|
.donut-legend i { width: 8px; height: 8px; border-radius: 2px; flex: none; }
|
|
103
130
|
.donut-legend b { font-weight: 500; }
|
|
131
|
+
.empty { font-size: 12px; color: var(--label-secondary); }
|
|
104
132
|
.ranks { display: grid; gap: 16px; }
|
|
105
133
|
.ranks h3 { margin: 0 0 8px; font-size: 12px; font-weight: 500; color: var(--label-secondary); }
|
|
106
134
|
.ranks ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 7px; }
|
|
@@ -109,10 +137,38 @@
|
|
|
109
137
|
.ranks .track { height: 6px; border-radius: 2px; background: var(--bg-layer-2); overflow: hidden; }
|
|
110
138
|
.ranks .track i { display: block; height: 100%; background: var(--brand); border-radius: 2px; }
|
|
111
139
|
.ranks .v { text-align: right; font-variant-numeric: tabular-nums; }
|
|
140
|
+
.stats em a { color: inherit; text-decoration: underline; text-underline-offset: 2px; }
|
|
141
|
+
.cmp ul { list-style: none; margin: 0; padding: 0 6px 0 0; display: grid; gap: 7px; }
|
|
142
|
+
.cmp li { display: grid; grid-template-columns: 172px 148px 1fr 60px; gap: 12px; align-items: baseline; font-size: 16px; cursor: pointer; }
|
|
143
|
+
.cmp li:hover .k { color: var(--label-primary); }
|
|
144
|
+
.cmp .k { color: var(--label-secondary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
145
|
+
.cmp .ver { font-size: 12px; color: var(--label-secondary); font-variant-numeric: tabular-nums; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
146
|
+
.cmp .v { text-align: right; font-variant-numeric: tabular-nums; }
|
|
147
|
+
.cmp .d { text-align: right; font-size: 12px; color: var(--label-secondary); font-variant-numeric: tabular-nums; }
|
|
148
|
+
.repo-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 28px; }
|
|
149
|
+
.repo-grid ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
|
|
150
|
+
.repo-grid li.muted { grid-template-columns: 1fr; font-size: 13px; }
|
|
151
|
+
.cmp li.muted { grid-template-columns: 1fr; font-size: 13px; }
|
|
152
|
+
@media (max-width: 560px) {
|
|
153
|
+
.cmp li { grid-template-columns: 1fr auto; gap: 2px 12px; font-size: 15px; padding: 6px 0; }
|
|
154
|
+
.cmp .k { grid-column: 1; grid-row: 1; }
|
|
155
|
+
.cmp .d { grid-column: 2; grid-row: 1; }
|
|
156
|
+
.cmp .ver { grid-column: 1; grid-row: 2; }
|
|
157
|
+
.cmp .v { grid-column: 2; grid-row: 2; }
|
|
158
|
+
}
|
|
159
|
+
.repo-grid li { display: grid; grid-template-columns: 168px 1fr 56px; align-items: center; gap: 10px; font-size: 16px; cursor: pointer; }
|
|
160
|
+
.repo-grid li:hover .k { color: var(--label-primary); }
|
|
161
|
+
.repo-grid .k { color: var(--label-secondary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
162
|
+
.repo-grid .track { height: 6px; border-radius: 2px; background: var(--bg-layer-2); overflow: hidden; }
|
|
163
|
+
.repo-grid .track i { display: block; height: 100%; background: var(--brand); border-radius: 2px; }
|
|
164
|
+
.repo-grid .v { text-align: right; font-variant-numeric: tabular-nums; }
|
|
165
|
+
@media (max-width: 900px) { .repo-grid { grid-template-columns: 1fr; } }
|
|
112
166
|
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 20px; margin-top: 12px; }
|
|
113
167
|
.stats div { display: flex; flex-direction: column; gap: 2px; }
|
|
114
168
|
.stats span { font-size: 12px; color: var(--label-secondary); }
|
|
115
169
|
.stats b { font-size: 24px; font-weight: 600; font-variant-numeric: tabular-nums; }
|
|
170
|
+
/* 对比区间两行放,一行会把中间日期折断 */
|
|
171
|
+
#impact-cover { font-size: 13px; white-space: pre-line; line-height: 1.6; }
|
|
116
172
|
.stats em { font-size: 12px; font-style: normal; color: var(--label-secondary); }
|
|
117
173
|
.note { margin: 12px 0 0; font-size: 12px; line-height: 1.65; color: var(--label-secondary); }
|
|
118
174
|
|
|
@@ -136,8 +192,34 @@
|
|
|
136
192
|
.cfg-row { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--label-secondary); margin-top: 8px; }
|
|
137
193
|
.cfg-row label { width: 56px; flex: none; }
|
|
138
194
|
.cfg { display: none; margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--border-l1); }
|
|
195
|
+
/* 绑定页:全屏盖住看板,只有一条主路径 */
|
|
196
|
+
.gate { position: fixed; inset: 0; z-index: 60; display: none; place-items: center; background: var(--bg-base); }
|
|
197
|
+
.gate.on { display: grid; }
|
|
198
|
+
body.gated { overflow: hidden; }
|
|
199
|
+
.gate-card { width: min(360px, calc(100vw - 40px)); text-align: left; }
|
|
200
|
+
.gate-card h1 { font-size: 15px; font-weight: 600; color: var(--label-primary); margin: 0 0 6px; }
|
|
201
|
+
.gate-card p { font-size: 12px; line-height: 1.6; color: var(--label-secondary); margin: 0 0 16px; }
|
|
202
|
+
.gate-card button.primary { width: 100%; height: 34px; border: 0; border-radius: 8px; background: var(--brand); color: #fff;
|
|
203
|
+
font-size: 13px; font-weight: 500; cursor: pointer; }
|
|
204
|
+
.gate-card button.primary:disabled { opacity: .55; cursor: default; }
|
|
205
|
+
.gate-alt { display: block; margin-top: 14px; }
|
|
206
|
+
/* 自己的分隔线,别借用页头那根 .sep(那是 1px 竖线,会把这里挤成一列字) */
|
|
207
|
+
.gate-alt.sep-top { padding-top: 14px; border-top: 1px solid var(--border-l1); }
|
|
208
|
+
.gate-alt input { width: 100%; height: 30px; background: var(--bg-layer-1); border: 1px solid var(--border-l1); border-radius: 8px;
|
|
209
|
+
color: var(--label-primary); font: inherit; font-size: 12px; padding: 0 10px; }
|
|
210
|
+
.gate-alt a { color: var(--brand); text-decoration: none; }
|
|
211
|
+
.gate-card a { color: var(--brand); text-decoration: none; }
|
|
212
|
+
.gate-card a:hover { text-decoration: underline; text-underline-offset: 2px; }
|
|
213
|
+
.gate-card p.gate-code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 15px; letter-spacing: .1em;
|
|
214
|
+
color: var(--label-primary); margin: 0 0 2px; }
|
|
215
|
+
.gate-out { font-size: 12px; color: var(--label-secondary); margin-top: 10px; min-height: 16px; }
|
|
216
|
+
.gate-code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 15px; letter-spacing: .1em; color: var(--label-primary); margin: 8px 0; }
|
|
139
217
|
.cfg.open { display: block; }
|
|
140
|
-
.
|
|
218
|
+
.ask-out { margin: 8px 0 0; font-size: 12px; line-height: 1.55; color: var(--label-secondary); }
|
|
219
|
+
.ask-out a { color: var(--brand); text-decoration: none; }
|
|
220
|
+
.ask-out a:hover { text-decoration: underline; }
|
|
221
|
+
.foot { display: flex; align-items: baseline; gap: 8px; font-size: 12px; color: var(--label-secondary); margin-top: 12px; }
|
|
222
|
+
#sum-src { margin-right: auto; }
|
|
141
223
|
.link { color: var(--label-secondary); border: 0; height: auto; padding: 0; background: none; text-decoration: underline; text-underline-offset: 2px; }
|
|
142
224
|
.link:hover { color: var(--label-primary); background: none; }
|
|
143
225
|
.rowline { display: flex; justify-content: space-between; align-items: center; font-size: 12px; color: var(--label-secondary); }
|
|
@@ -155,22 +237,29 @@
|
|
|
155
237
|
}
|
|
156
238
|
@media (max-width: 980px) {
|
|
157
239
|
.kpis { grid-template-columns: repeat(2, 1fr); row-gap: 14px; }
|
|
240
|
+
.leaders { grid-template-columns: repeat(2, 1fr); gap: 14px 20px; }
|
|
158
241
|
.kpi:nth-child(odd) { border-left: none; padding-left: 0; }
|
|
159
242
|
.kpi:nth-child(even) { border-left: 1px solid var(--border-l1); padding-left: 14px; }
|
|
160
243
|
}
|
|
161
244
|
@media (max-width: 620px) {
|
|
162
245
|
.wrap { padding: 14px 16px 28px; }
|
|
163
246
|
header { flex-wrap: wrap; row-gap: 8px; }
|
|
164
|
-
.repo {
|
|
247
|
+
.repo-wrap { min-width: 0; max-width: 100%; }
|
|
248
|
+
.repo-wrap > .repo { flex: 1 1 auto; min-width: 0; display: flex; align-items: center; gap: 4px; order: -1; }
|
|
249
|
+
.repo-wrap > .repo #repo-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
250
|
+
.repo-wrap > .repo-note { font-size: 12px; color: var(--label-secondary); white-space: nowrap; }
|
|
165
251
|
.spacer { display: none; }
|
|
166
252
|
.seg { margin-left: auto; }
|
|
167
253
|
.kpi-value { font-size: 24px; }
|
|
168
254
|
.kpi:last-child { grid-column: 1 / -1; border-left: none; padding-left: 0; }
|
|
169
255
|
.split { grid-template-columns: 1fr; gap: 20px; }
|
|
170
256
|
.donut { flex-direction: row; align-items: center; gap: 16px; }
|
|
171
|
-
.donut
|
|
172
|
-
.donut
|
|
173
|
-
.donut-legend
|
|
257
|
+
.donut { width: 100%; max-width: 100%; overflow: hidden; }
|
|
258
|
+
.donut svg { margin: 0; flex: none; width: 84px; height: 84px; }
|
|
259
|
+
.donut-legend { flex: 1; min-width: 0; overflow: hidden; }
|
|
260
|
+
.donut-legend div { min-width: 0; }
|
|
261
|
+
.donut-legend span { flex: 1 1 auto; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
|
|
262
|
+
.donut-legend b { flex: none; }
|
|
174
263
|
.stats { grid-template-columns: 1fr 1fr; gap: 14px; }
|
|
175
264
|
.stats b { font-size: 18px; }
|
|
176
265
|
thead th:nth-child(3), tbody td:nth-child(3) { display: none; }
|
|
@@ -183,9 +272,17 @@
|
|
|
183
272
|
<header>
|
|
184
273
|
<span class="brand">github-overview</span>
|
|
185
274
|
<span class="sep"></span>
|
|
186
|
-
<div class="repo
|
|
275
|
+
<div class="repo-wrap">
|
|
276
|
+
<button class="repo" id="repo-pick" aria-haspopup="true" aria-expanded="false"><span id="repo-owner"></span><span id="repo-name">全部仓库</span> <span class="caret">▾</span></button>
|
|
277
|
+
<a class="repo-open" id="repo-open" target="_blank" rel="noopener" aria-label="在 GitHub 打开" hidden>
|
|
278
|
+
<svg viewBox="0 0 16 16" width="12" height="12" aria-hidden="true"><path d="M6.5 3.5h6v6M12.5 3.5 5 11" fill="none" stroke="currentColor" stroke-width="1.4" stroke-linecap="round" stroke-linejoin="round"/></svg>
|
|
279
|
+
</a>
|
|
280
|
+
<div class="repo-menu" id="repo-menu" hidden></div>
|
|
281
|
+
<span class="repo-note" id="repo-note" hidden></span>
|
|
282
|
+
</div>
|
|
187
283
|
<div class="spacer"></div>
|
|
188
284
|
<div class="seg" id="seg">
|
|
285
|
+
<button data-r="1">1 天</button>
|
|
189
286
|
<button data-r="7" class="on">7 天</button>
|
|
190
287
|
<button data-r="30">30 天</button>
|
|
191
288
|
<button data-r="90">90 天</button>
|
|
@@ -201,38 +298,43 @@
|
|
|
201
298
|
|
|
202
299
|
<section class="kpis">
|
|
203
300
|
<div class="kpi">
|
|
204
|
-
<div class="kpi-label"
|
|
205
|
-
<div class="kpi-value" id="k-uniq"
|
|
206
|
-
<div class="kpi-sub" id="k-views-sub"
|
|
301
|
+
<div class="kpi-label">浏览</div>
|
|
302
|
+
<div class="kpi-value" id="k-uniq">—</div>
|
|
303
|
+
<div class="kpi-sub" id="k-views-sub"></div>
|
|
207
304
|
</div>
|
|
208
305
|
<div class="kpi">
|
|
209
306
|
<div class="kpi-label">外部贡献</div>
|
|
210
307
|
<div class="kpi-value" id="k-contrib">2</div>
|
|
211
|
-
<div class="kpi-sub" id="k-contrib-sub"
|
|
308
|
+
<div class="kpi-sub" id="k-contrib-sub">—</div>
|
|
212
309
|
</div>
|
|
213
310
|
<div class="kpi">
|
|
214
311
|
<div class="kpi-label">npm 下载</div>
|
|
215
|
-
<div class="kpi-value" id="k-npm"
|
|
216
|
-
<div class="kpi-sub"
|
|
312
|
+
<div class="kpi-value" id="k-npm">—</div>
|
|
313
|
+
<div class="kpi-sub" id="k-npm-sub">近 7 天</div>
|
|
217
314
|
</div>
|
|
218
315
|
<div class="kpi">
|
|
219
316
|
<div class="kpi-label">stars</div>
|
|
220
317
|
<div class="kpi-value" id="k-stars">9</div>
|
|
221
|
-
<div class="kpi-sub" id="k-forks"
|
|
318
|
+
<div class="kpi-sub" id="k-forks"></div>
|
|
222
319
|
</div>
|
|
223
320
|
<div class="kpi">
|
|
224
321
|
<div class="kpi-label">发版</div>
|
|
225
322
|
<div class="kpi-value" id="k-rel">4</div>
|
|
226
|
-
<div class="kpi-sub" id="k-rel-sub"
|
|
323
|
+
<div class="kpi-sub" id="k-rel-sub"></div>
|
|
227
324
|
</div>
|
|
228
325
|
</section>
|
|
229
326
|
|
|
327
|
+
<section class="sec" id="sec-top" hidden>
|
|
328
|
+
<div class="head"><h2>各仓之最<span class="head-note" id="top-note"></span></h2></div>
|
|
329
|
+
<div class="leaders" id="leaders"></div>
|
|
330
|
+
</section>
|
|
331
|
+
|
|
230
332
|
<div class="cols">
|
|
231
333
|
<main>
|
|
232
334
|
<section class="sec">
|
|
233
335
|
<div class="head">
|
|
234
336
|
<h2>流量</h2>
|
|
235
|
-
<span class="note" id="range-note"
|
|
337
|
+
<span class="note" id="range-note"></span>
|
|
236
338
|
<div class="spacer"></div>
|
|
237
339
|
<span class="key"><i style="background:var(--brand)"></i>浏览</span>
|
|
238
340
|
<span class="key"><i style="background:var(--machine)"></i>克隆</span>
|
|
@@ -246,25 +348,69 @@
|
|
|
246
348
|
<h2>下载</h2>
|
|
247
349
|
<div class="srcs">
|
|
248
350
|
<span class="src on">npm</span>
|
|
249
|
-
<span class="src off">PyPI</span>
|
|
250
|
-
<span class="src off">Docker</span>
|
|
251
|
-
<span class="src off">+ 添加</span>
|
|
252
351
|
</div>
|
|
253
352
|
</div>
|
|
254
353
|
<div class="chart" id="c-npm"></div>
|
|
255
354
|
</section>
|
|
256
355
|
|
|
257
356
|
<section class="sec">
|
|
258
|
-
<div class="head"><h2>贡献</h2></div>
|
|
357
|
+
<div class="head"><h2>贡献</h2><span class="src" id="contrib-range"></span><span class="head-note" id="contrib-fresh"></span></div>
|
|
259
358
|
<div class="stats">
|
|
260
|
-
<div><span>issue</span><b id="s-issues"
|
|
261
|
-
<div><span>PR</span><b id="s-prs"
|
|
262
|
-
<div><span
|
|
359
|
+
<div><span>issue</span><b id="s-issues">—</b><em id="s-issues-sub"></em></div>
|
|
360
|
+
<div><span>PR</span><b id="s-prs">—</b><em id="s-prs-sub"></em></div>
|
|
361
|
+
<div><span>安全告警 · 快照</span><b id="s-alerts">关闭</b><em id="s-alerts-sub">无数据</em></div>
|
|
362
|
+
</div>
|
|
363
|
+
</section>
|
|
364
|
+
|
|
365
|
+
<section class="sec" id="sec-forks" hidden>
|
|
366
|
+
<div class="head"><h2>Fork<span class="src" id="fork-range"></span><span class="head-note" id="fork-fresh"></span></div>
|
|
367
|
+
<div class="stats" id="fork-stats">
|
|
368
|
+
<div><span>新增</span><b id="f-new">—</b><em id="f-new-sub"></em></div>
|
|
369
|
+
<div><span>最近</span><b id="f-last">—</b><em id="f-last-sub"></em></div>
|
|
370
|
+
</div>
|
|
371
|
+
<div class="note" id="fork-note" hidden></div>
|
|
372
|
+
<div id="fork-list"></div>
|
|
373
|
+
</section>
|
|
374
|
+
|
|
375
|
+
<section class="sec" id="sec-impact" hidden>
|
|
376
|
+
<div class="head">
|
|
377
|
+
<h2>发版效果</h2>
|
|
378
|
+
<span class="src" id="impact-ver"></span>
|
|
379
|
+
</div>
|
|
380
|
+
<div class="stats">
|
|
381
|
+
<div><span>浏览日均</span><b id="impact-views">—</b><em id="impact-views-sub"></em></div>
|
|
382
|
+
<div><span>下载日均</span><b id="impact-npm">—</b><em id="impact-npm-sub"></em></div>
|
|
383
|
+
<div><span>对比区间</span><b id="impact-cover">—</b><em id="impact-cover-sub"></em></div>
|
|
384
|
+
</div>
|
|
385
|
+
</section>
|
|
386
|
+
|
|
387
|
+
<section class="sec" id="sec-cmp" hidden>
|
|
388
|
+
<div class="head"><h2>发版前后 · 浏览/天<span class="head-note" id="rel-note"></span></h2></div>
|
|
389
|
+
<div class="cmp"><ul id="cmp-list"></ul></div>
|
|
390
|
+
</section>
|
|
391
|
+
|
|
392
|
+
<section class="sec" id="sec-funnel" hidden>
|
|
393
|
+
<div class="head"><h2>漏斗</h2></div>
|
|
394
|
+
<div class="stats">
|
|
395
|
+
<div><span>浏览</span><b id="f-views">—</b><em id="f-views-sub"></em></div>
|
|
396
|
+
<div><span>仓库主页</span><b id="f-home">—</b><em id="f-home-sub"></em></div>
|
|
397
|
+
<div><span>npm 下载</span><b id="f-npm">—</b><em id="f-npm-sub"></em></div>
|
|
398
|
+
</div>
|
|
399
|
+
</section>
|
|
400
|
+
|
|
401
|
+
<section class="sec" id="sec-repos" hidden>
|
|
402
|
+
<div class="head">
|
|
403
|
+
<h2>项目<span class="head-note" id="proj-note"></span></h2>
|
|
404
|
+
<div class="srcs" id="ov-sort">
|
|
405
|
+
<span class="src on" data-sort="u">访客</span>
|
|
406
|
+
<span class="src off" data-sort="n">下载</span>
|
|
407
|
+
</div>
|
|
263
408
|
</div>
|
|
409
|
+
<div class="repo-grid" id="repo-list"></div>
|
|
264
410
|
</section>
|
|
265
411
|
|
|
266
412
|
<section class="sec">
|
|
267
|
-
<div class="head"><h2
|
|
413
|
+
<div class="head"><h2>构成<span class="head-note" id="comp-note">· 各仓最近一次快照</span></h2></div>
|
|
268
414
|
<div class="split">
|
|
269
415
|
<div class="donut" id="donut"></div>
|
|
270
416
|
<div class="ranks" id="ranks"></div>
|
|
@@ -275,20 +421,22 @@
|
|
|
275
421
|
|
|
276
422
|
<aside>
|
|
277
423
|
<div class="panel ai">
|
|
278
|
-
<h3>摘要<span id="sum-at"
|
|
279
|
-
<p id="sum-1"
|
|
280
|
-
<p id="sum-2"
|
|
281
|
-
<p id="sum-3"
|
|
424
|
+
<h3>摘要<span id="sum-at"></span></h3>
|
|
425
|
+
<p id="sum-1">摘要正在生成。</p>
|
|
426
|
+
<p id="sum-2" hidden></p>
|
|
427
|
+
<p id="sum-3" hidden></p>
|
|
282
428
|
|
|
283
429
|
<div class="ask">
|
|
284
|
-
<input placeholder="
|
|
430
|
+
<input id="ask-q" placeholder="问全部仓库">
|
|
285
431
|
<button class="mini">问</button>
|
|
286
432
|
</div>
|
|
287
|
-
<
|
|
433
|
+
<p class="ask-out" id="ask-out" hidden></p>
|
|
434
|
+
<div class="foot"><span id="ai-model">—</span><span id="sum-src"></span><button class="link" id="cfg-toggle">配置</button></div>
|
|
288
435
|
|
|
289
436
|
<div class="cfg" id="cfg">
|
|
290
|
-
<div class="cfg-row"><label>Base URL</label><input
|
|
291
|
-
<div class="cfg-row"><label>API Key</label><input type="password" placeholder="sk-…" spellcheck="false"></div>
|
|
437
|
+
<div class="cfg-row"><label>Base URL</label><input id="cfg-base" placeholder="https://…/v1" spellcheck="false"></div>
|
|
438
|
+
<div class="cfg-row"><label>API Key</label><input id="cfg-key" type="password" placeholder="sk-…" spellcheck="false"></div>
|
|
439
|
+
<div class="cfg-row"><label>模型</label><input id="cfg-model" placeholder="模型名" spellcheck="false"></div>
|
|
292
440
|
<div class="cfg-row" style="justify-content:flex-end;gap:6px">
|
|
293
441
|
<button class="mini ghost">取消</button>
|
|
294
442
|
<button class="mini" id="cfg-save">保存</button>
|
|
@@ -297,8 +445,9 @@
|
|
|
297
445
|
</div>
|
|
298
446
|
|
|
299
447
|
<div class="panel">
|
|
300
|
-
<h3>刷新<span
|
|
301
|
-
<div class="rowline"><span>上次</span><b id="r-last"
|
|
448
|
+
<h3>刷新<span id="r-interval">—</span></h3>
|
|
449
|
+
<div class="rowline"><span>上次</span><b id="r-last">—</b></div>
|
|
450
|
+
<div class="rowline" id="r-contrib-row" hidden><span>贡献</span><b id="r-contrib">—</b></div>
|
|
302
451
|
<div class="rowline"><span>已存</span><b id="r-days">8 天</b></div>
|
|
303
452
|
<div class="rowline" style="margin-top:10px"><span>数据源</span><b>GitHub · npm</b></div>
|
|
304
453
|
</div>
|
|
@@ -306,6 +455,19 @@
|
|
|
306
455
|
</div>
|
|
307
456
|
</div>
|
|
308
457
|
|
|
458
|
+
<div class="gate" id="gate">
|
|
459
|
+
<div class="gate-card">
|
|
460
|
+
<h1>把看板接到你的 GitHub</h1>
|
|
461
|
+
<p id="gate-lead">登录你自己的账号,数据只存在这台电脑上。</p>
|
|
462
|
+
<div id="gate-main"></div>
|
|
463
|
+
<div class="gate-alt">
|
|
464
|
+
<p id="gate-alt-lead" style="margin:0 0 8px">改用访问令牌</p>
|
|
465
|
+
<input id="gate-token" type="password" placeholder="ghp_… 或 github_pat_…" spellcheck="false" autocomplete="off">
|
|
466
|
+
<p style="margin:8px 0 0"><a id="gate-new" target="_blank" rel="noopener">在新标签页生成</a></p>
|
|
467
|
+
</div>
|
|
468
|
+
<div class="gate-out" id="gate-out"></div>
|
|
469
|
+
</div>
|
|
470
|
+
</div>
|
|
309
471
|
<script>
|
|
310
472
|
let DATA = [
|
|
311
473
|
{ d: "10-26", v: 1, u: 1, c: 81, cu: 34, n: 1240 },
|
|
@@ -318,7 +480,7 @@ let DATA = [
|
|
|
318
480
|
];
|
|
319
481
|
let RELEASE = { "10-29": 1, "10-30": 1, "10-31": 1, "11-01": 1 };
|
|
320
482
|
const NS = "http://www.w3.org/2000/svg";
|
|
321
|
-
const fmt = v =>
|
|
483
|
+
const fmt = v => (v > 0 && v < 10 ? Math.round(v * 10) / 10 : Math.round(v)).toLocaleString("en");
|
|
322
484
|
|
|
323
485
|
const theme = () => document.documentElement.dataset.theme;
|
|
324
486
|
function C() {
|
|
@@ -333,6 +495,19 @@ function el(tag, attrs, text) {
|
|
|
333
495
|
if (text != null) n.textContent = text;
|
|
334
496
|
return n;
|
|
335
497
|
}
|
|
498
|
+
// 窄屏放不下就少标几个日期,但末日一定标上,也别和前一个挤成一条
|
|
499
|
+
function axisIdx(n, iw) {
|
|
500
|
+
const fit = Math.max(3, Math.floor(iw / 64));
|
|
501
|
+
const step = Math.max(1, Math.ceil(n / fit));
|
|
502
|
+
const out = [];
|
|
503
|
+
for (let i = 0; i < n; i += step) out.push(i);
|
|
504
|
+
if (out[out.length - 1] !== n - 1) {
|
|
505
|
+
if (n - 1 - out[out.length - 1] < step / 2) out.pop();
|
|
506
|
+
out.push(n - 1);
|
|
507
|
+
}
|
|
508
|
+
return out;
|
|
509
|
+
}
|
|
510
|
+
|
|
336
511
|
function scale(max, ticks) {
|
|
337
512
|
const rough = max / ticks, p = Math.pow(10, Math.floor(Math.log10(rough))), m = rough / p;
|
|
338
513
|
const step = (m <= 1 ? 1 : m <= 2 ? 2 : m <= 2.5 ? 2.5 : m <= 5 ? 5 : 10) * p;
|
|
@@ -343,7 +518,9 @@ let LAST = dayIdx(DATA[DATA.length - 1].d);
|
|
|
343
518
|
|
|
344
519
|
function domain(days) {
|
|
345
520
|
const out = [];
|
|
346
|
-
|
|
521
|
+
// 只画有记录的那段,别把 14 天数据摊在 30 天轴上
|
|
522
|
+
const start = Math.max(LAST - days + 1, FIRST == null ? -Infinity : FIRST);
|
|
523
|
+
for (let i = LAST - start; i >= 0; i--) {
|
|
347
524
|
const dt = new Date((LAST - i) * 864e5);
|
|
348
525
|
const label = String(dt.getUTCMonth() + 1).padStart(2, "0") + "-" + String(dt.getUTCDate()).padStart(2, "0");
|
|
349
526
|
out.push({ label, rec: DATA.find(r => r.d === label) });
|
|
@@ -356,9 +533,10 @@ function flowChart(node, days) {
|
|
|
356
533
|
const dom = domain(days);
|
|
357
534
|
const W = Math.max(300, Math.round(node.clientWidth || 720)), H = 196, P = { l: 42, r: 42, t: 12, b: 22 };
|
|
358
535
|
const iw = W - P.l - P.r, ih = H - P.t - P.b, ticks = 4;
|
|
536
|
+
if (!DATA.some(r => (r.v || 0) > 0 || (r.c || 0) > 0)) return emptyInto(node, "还没有流量数据");
|
|
359
537
|
const L = scale(Math.max(...DATA.map(r => r.v)) * 1.06, ticks);
|
|
360
538
|
const R = scale(Math.max(...DATA.map(r => r.c)) * 1.06, ticks);
|
|
361
|
-
const x = i => P.l + (i * iw) / (dom.length - 1);
|
|
539
|
+
const x = i => (dom.length === 1 ? P.l + iw / 2 : P.l + (i * iw) / (dom.length - 1));
|
|
362
540
|
const yl = v => P.t + ih - (v / L.max) * ih;
|
|
363
541
|
const yr = v => P.t + ih - (v / R.max) * ih;
|
|
364
542
|
|
|
@@ -376,35 +554,60 @@ function flowChart(node, days) {
|
|
|
376
554
|
if (firstIdx > 0) {
|
|
377
555
|
svg.appendChild(el("rect", { x: P.l, y: P.t, width: x(firstIdx) - P.l, height: ih, fill: c.zero }));
|
|
378
556
|
svg.appendChild(el("line", { x1: x(firstIdx), x2: x(firstIdx), y1: P.t, y2: P.t + ih, stroke: c.grid, "stroke-dasharray": "3 4" }));
|
|
379
|
-
svg.appendChild(el("text", { x: x(firstIdx) + 7, y: P.t + 13, class: "tick-label" }, "
|
|
557
|
+
svg.appendChild(el("text", { x: x(firstIdx) + 7, y: P.t + 13, class: "tick-label" }, `${dom[firstIdx]?.label ?? ""} 起有数据`));
|
|
380
558
|
}
|
|
381
559
|
|
|
382
560
|
dom.forEach((d, i) => {
|
|
383
|
-
if (d.rec && RELEASE[d.label]) {
|
|
561
|
+
if (dom.length > 1 && d.rec && RELEASE[d.label]) {
|
|
384
562
|
svg.appendChild(el("line", { x1: x(i), x2: x(i), y1: P.t - 3, y2: P.t + ih, stroke: c.event, "stroke-width": 1, "stroke-dasharray": "2 4", opacity: .5 }));
|
|
385
563
|
}
|
|
386
564
|
});
|
|
387
565
|
|
|
388
|
-
const vp = dom.map((d, i) => d.rec ? `${x(i)},${yl(d.rec.v)}
|
|
389
|
-
|
|
566
|
+
const vp = dom.map((d, i) => (d.rec ? { i, pt: `${x(i)},${yl(d.rec.v)}`, v: d.rec.v } : null)).filter(Boolean);
|
|
567
|
+
// 末尾连续 0 = 当天还没采集到:实线停在最后有数的一天,后面用虚线
|
|
568
|
+
const recs = dom.filter((d) => d.rec);
|
|
569
|
+
const avgV = recs.length ? recs.reduce((a, d) => a + (d.rec.v || 0), 0) / recs.length : 0;
|
|
570
|
+
let cut = dom.length;
|
|
571
|
+
while (cut > 0 && dom[cut - 1].rec && (dom[cut - 1].rec.v || 0) === 0 && avgV >= 20) cut--;
|
|
572
|
+
const solidLen = Math.max(1, vp.filter((p) => p.i < cut).length);
|
|
573
|
+
const solid = vp.slice(0, solidLen), tail = vp.slice(solidLen);
|
|
574
|
+
|
|
575
|
+
if (dom.length === 1 && dom[0].rec) {
|
|
576
|
+
const bw2 = Math.min(26, iw * 0.16), cv = dom[0].rec.c || 0;
|
|
577
|
+
svg.appendChild(el("rect", { x: x(0) + Math.min(46, iw * 0.3) / 2 + 6, y: yr(cv), width: bw2, height: yr(0) - yr(cv), fill: c.machine, opacity: .3, rx: 3 }));
|
|
578
|
+
} else {
|
|
579
|
+
const cp = dom.slice(0, cut).map((d, i) => d.rec ? `${x(i)},${yr(d.rec.c)}` : null).filter(Boolean).join(" ");
|
|
580
|
+
svg.appendChild(el("polyline", { points: cp, fill: "none", stroke: c.machine, "stroke-width": 1.5, opacity: .9 }));
|
|
581
|
+
}
|
|
582
|
+
|
|
583
|
+
const lastSolid = solid[solid.length - 1], firstSolid = solid[0];
|
|
390
584
|
svg.appendChild(el("path", {
|
|
391
|
-
d: `M${
|
|
585
|
+
d: `M${firstSolid.pt} L` + solid.map((p) => p.pt).join(" L") + ` L${x(lastSolid.i)},${yl(0)} L${x(firstSolid.i)},${yl(0)} Z`,
|
|
392
586
|
fill: c.human, opacity: .14
|
|
393
587
|
}));
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
588
|
+
svg.appendChild(el("polyline", { points: solid.map((p) => p.pt).join(" "), fill: "none", stroke: c.human, "stroke-width": 2, "stroke-linejoin": "round" }));
|
|
589
|
+
// 单天没有折线可看,改成一个站直的柱子
|
|
590
|
+
if (dom.length === 1 && dom[0].rec) {
|
|
591
|
+
const bw = Math.min(46, iw * 0.3), v = dom[0].rec.v || 0;
|
|
592
|
+
svg.appendChild(el("rect", { x: x(0) - bw / 2, y: yl(v), width: bw, height: yl(0) - yl(v), fill: c.human, opacity: .18, rx: 3 }));
|
|
593
|
+
svg.appendChild(el("circle", { cx: x(0), cy: yl(v), r: 3.4, fill: c.human }));
|
|
594
|
+
}
|
|
595
|
+
if (tail.length) {
|
|
596
|
+
// 末尾没采集到的 0 不连成斜线,否则看起来像浏览真的掉到 0
|
|
597
|
+
const tpts = [lastSolid.pt, ...tail.map((p) => p.pt)];
|
|
598
|
+
if ((tail[tail.length - 1].v || 0) === 0) tpts.pop();
|
|
599
|
+
if (tpts.length > 1) svg.appendChild(el("polyline", { points: tpts.join(" "), fill: "none", stroke: c.human, "stroke-width": 1.5, "stroke-dasharray": "3 4", opacity: .55 }));
|
|
600
|
+
const cutLabel = dom[cut]?.label ?? "";
|
|
601
|
+
// 贴右轴会压住末端的刻度数字,改放在未采集灰区的左下
|
|
602
|
+
svg.appendChild(el("text", { x: x(cut) - 8, y: P.t + 12, "text-anchor": "end", class: "tick-label", fill: c.human, opacity: .75 }, cutLabel ? `${cutLabel} 未采集` : "未采集"));
|
|
603
|
+
}
|
|
399
604
|
|
|
400
605
|
const peak = DATA.reduce((a, b) => b.v > a.v ? b : a);
|
|
401
606
|
const pi = dom.findIndex(d => d.rec === peak);
|
|
402
607
|
svg.appendChild(el("text", { x: x(pi), y: yl(peak.v) - 8, "text-anchor": "middle", class: "val-label" }, fmt(peak.v)));
|
|
403
608
|
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
if (i % step && i !== dom.length - 1) return;
|
|
407
|
-
svg.appendChild(el("text", { x: x(i), y: H - 4, "text-anchor": "middle", class: "tick-label" }, d.label));
|
|
609
|
+
axisIdx(dom.length, iw).forEach((i) => {
|
|
610
|
+
svg.appendChild(el("text", { x: x(i), y: H - 4, "text-anchor": "middle", class: "tick-label" }, dom[i].label));
|
|
408
611
|
});
|
|
409
612
|
node.appendChild(svg);
|
|
410
613
|
}
|
|
@@ -414,7 +617,10 @@ function npmChart(node, days) {
|
|
|
414
617
|
const dom = domain(days);
|
|
415
618
|
const W = Math.max(300, Math.round(node.clientWidth || 720)), H = 122, P = { l: 44, r: 10, t: 14, b: 20 };
|
|
416
619
|
const iw = W - P.l - P.r, ih = H - P.t - P.b, ticks = 2;
|
|
417
|
-
const
|
|
620
|
+
const nvals = DATA.map(r => r.n).filter(v => typeof v === "number" && isFinite(v) && v > 0);
|
|
621
|
+
if (!nvals.length) return emptyInto(node, "还没有下载数据");
|
|
622
|
+
const NMAX = Math.max(...nvals);
|
|
623
|
+
const S = scale(NMAX * 1.02, ticks);
|
|
418
624
|
const bw = Math.max(4, Math.min(24, (iw / dom.length) * 0.5));
|
|
419
625
|
const cx = i => P.l + (i + .5) * (iw / dom.length);
|
|
420
626
|
const y = v => P.t + ih - (v / S.max) * ih;
|
|
@@ -426,21 +632,33 @@ function npmChart(node, days) {
|
|
|
426
632
|
svg.appendChild(el("line", { x1: P.l, x2: W - P.r, y1: yy, y2: yy, stroke: c.grid }));
|
|
427
633
|
svg.appendChild(el("text", { x: P.l - 8, y: yy + 4, "text-anchor": "end", class: "tick-label" }, fmt(S.step * t)));
|
|
428
634
|
}
|
|
635
|
+
// npm 下载比浏览晚几天才有数,开头空白要说明是哪天开始有数
|
|
636
|
+
const firstN = dom.findIndex((d) => d.rec && d.rec.n > 0);
|
|
637
|
+
if (firstN > 0) {
|
|
638
|
+
svg.appendChild(el("rect", { x: P.l, y: P.t, width: cx(firstN) - bw / 2 - P.l, height: ih, fill: c.zero }));
|
|
639
|
+
svg.appendChild(el("line", { x1: cx(firstN) - bw / 2, x2: cx(firstN) - bw / 2, y1: P.t, y2: P.t + ih, stroke: c.grid, "stroke-dasharray": "3 4" }));
|
|
640
|
+
svg.appendChild(el("text", { x: P.l + 6, y: P.t + 12, class: "tick-label" }, `${dom[firstN].label} 起有数据`));
|
|
641
|
+
}
|
|
429
642
|
dom.forEach((d, i) => {
|
|
430
643
|
if (!d.rec) return;
|
|
431
644
|
const v = d.rec.n;
|
|
432
645
|
const pending = i >= dom.length - 2;
|
|
433
646
|
if (v == null || (pending && v === 0)) {
|
|
647
|
+
if (!pending) return; // 早期缺失的数据不画桩,免得整排虚线像归零
|
|
434
648
|
svg.appendChild(el("rect", { x: cx(i) - bw / 2, y: P.t + ih - 7, width: bw, height: 7, rx: 2, fill: "none", stroke: c.machine, opacity: .55, "stroke-dasharray": "2 3" }));
|
|
435
649
|
return;
|
|
436
650
|
}
|
|
651
|
+
if (v === 0) return; // 0 下载不画成一条线
|
|
437
652
|
svg.appendChild(el("rect", { x: cx(i) - bw / 2, y: y(v), width: bw, height: Math.max(2, P.t + ih - y(v)), rx: 2, fill: c.human, opacity: .85 }));
|
|
438
|
-
if (v > 0 && bw > 12 && (iw / dom.length > 46 || v ===
|
|
653
|
+
if (v > 0 && bw > 12 && (iw / dom.length > 46 || v === NMAX)) svg.appendChild(el("text", { x: cx(i), y: y(v) - 6, "text-anchor": "middle", class: "val-label" }, fmt(v)));
|
|
439
654
|
});
|
|
440
|
-
|
|
441
|
-
dom.
|
|
442
|
-
|
|
443
|
-
svg.appendChild(el("text", { x:
|
|
655
|
+
// 末尾两根柱还没采到数,标出从哪天起是空的,别让人以为是零下载
|
|
656
|
+
const cutAt = dom.findIndex((d, i) => i >= dom.length - 2 && (!d.rec || d.rec.n == null || d.rec.n === 0));
|
|
657
|
+
if (cutAt >= 0 && dom[cutAt]?.label) {
|
|
658
|
+
svg.appendChild(el("text", { x: W - P.r - 6, y: P.t + 14, "text-anchor": "end", class: "tick-label", fill: c.machine, opacity: .75 }, `${dom[cutAt].label} 未采集`));
|
|
659
|
+
}
|
|
660
|
+
axisIdx(dom.length, iw).forEach((i) => {
|
|
661
|
+
svg.appendChild(el("text", { x: cx(i), y: H - 4, "text-anchor": "middle", class: "tick-label" }, dom[i].label));
|
|
444
662
|
});
|
|
445
663
|
node.appendChild(svg);
|
|
446
664
|
}
|
|
@@ -449,24 +667,43 @@ let RANKS = [
|
|
|
449
667
|
["看了哪些页面", [["仓库主页", 397], ["issues 列表", 15], ["README", 2], ["actions 页", 1]]]
|
|
450
668
|
];
|
|
451
669
|
let PATHS = null;
|
|
670
|
+
let FIRST = null;
|
|
671
|
+
let LIVE_SET = false;
|
|
672
|
+
// 实时数据:拿不到就继续用内置样例,页面始终能看
|
|
673
|
+
const LIVE = { totals: {}, range: { days: 7, storedDays: 0 }, repo: {}, contributions: { issues: [], pulls: [], open: null }, releases: [], paths: [], npmVersions: [], updatedAt: null };
|
|
674
|
+
|
|
675
|
+
const emptyInto = (node, text) => {
|
|
676
|
+
node.textContent = "";
|
|
677
|
+
const d = document.createElement("div");
|
|
678
|
+
d.className = "empty";
|
|
679
|
+
d.textContent = text;
|
|
680
|
+
node.appendChild(d);
|
|
681
|
+
};
|
|
452
682
|
let REFS = null;
|
|
453
683
|
|
|
454
|
-
const shortPath = p =>
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
684
|
+
const shortPath = p => {
|
|
685
|
+
const q = String(p).replace(/^\/+/, "");
|
|
686
|
+
return q === "仓库主页" ? "仓库主页"
|
|
687
|
+
: /^issues\/\d+$/.test(q) ? "issue 页"
|
|
688
|
+
: /^issues/.test(q) ? "issues 列表"
|
|
689
|
+
: /^readme/i.test(q) ? "README"
|
|
690
|
+
: /^actions/.test(q) ? "actions 页"
|
|
691
|
+
: /^blob\//.test(q) ? "文件页"
|
|
692
|
+
: p;
|
|
693
|
+
};
|
|
461
694
|
|
|
462
695
|
function donut(node) {
|
|
463
696
|
node.textContent = "";
|
|
464
697
|
const cs = getComputedStyle(document.documentElement);
|
|
465
698
|
let parts = PATHS ? PATHS : [];
|
|
466
|
-
if (!parts.length) parts = [["0.6.14", 320, "--brand"], ["旧版本", 1137, "--machine"]];
|
|
699
|
+
if (!parts.length && !LIVE_SET) parts = [["0.6.14", 320, "--brand"], ["旧版本", 1137, "--machine"]];
|
|
700
|
+
if (!parts.length) return emptyInto(node, "还没有页面数据");
|
|
701
|
+
// 占比只在这份热门榜内部算:页面榜是各仓最近一次同步拿到的前几个,
|
|
702
|
+
// 拿 14 天总浏览当分母会把两段时间混在一起,还会凭空补出一个「其他页面」
|
|
467
703
|
const total = parts.reduce((s, p) => s + p[1], 0);
|
|
704
|
+
if (!total) return emptyInto(node, "还没有页面数据");
|
|
468
705
|
const R = 40, ST = 13, CIRC = 2 * Math.PI * R;
|
|
469
|
-
const svg = el("svg", { viewBox: "0 0 104 104", role: "img", "aria-label": "
|
|
706
|
+
const svg = el("svg", { viewBox: "0 0 104 104", role: "img", "aria-label": "页面访问占比" });
|
|
470
707
|
svg.appendChild(el("circle", { cx: 52, cy: 52, r: R, fill: "none", stroke: cs.getPropertyValue("--border-l1").trim(), "stroke-width": ST }));
|
|
471
708
|
let off = 0;
|
|
472
709
|
parts.forEach(p => {
|
|
@@ -504,10 +741,15 @@ function donut(node) {
|
|
|
504
741
|
|
|
505
742
|
function ranks(node) {
|
|
506
743
|
node.textContent = "";
|
|
507
|
-
RANKS.
|
|
744
|
+
if (!RANKS.length) return;
|
|
745
|
+
// 只有一两个来源时别把数字推到半屏外
|
|
746
|
+
const thin = RANKS.length === 1 && RANKS[0][1].length <= 2;
|
|
747
|
+
node.style.maxWidth = thin ? "320px" : "";
|
|
748
|
+
RANKS.forEach(([group, rows, note]) => {
|
|
508
749
|
const box = document.createElement("div");
|
|
509
750
|
const h3 = document.createElement("h3");
|
|
510
|
-
h3.textContent = group;
|
|
751
|
+
h3.textContent = group + " · 最近一次快照";
|
|
752
|
+
if (note) { const sp = document.createElement("span"); sp.className = "head-note"; sp.textContent = "· " + note; h3.appendChild(sp); }
|
|
511
753
|
box.appendChild(h3);
|
|
512
754
|
const ul = document.createElement("ul");
|
|
513
755
|
const max = Math.max(...rows.map(r => r[1]), 1);
|
|
@@ -539,37 +781,63 @@ function ranks(node) {
|
|
|
539
781
|
});
|
|
540
782
|
}
|
|
541
783
|
|
|
784
|
+
// 有的 tag 写 v 有的不写,同一列里统一省掉前缀,版本号本身不变
|
|
785
|
+
const bareTag = (t) => String(t ?? "").trim().replace(/^[vV](?=\d)/, "");
|
|
786
|
+
|
|
542
787
|
const kUniq = document.getElementById("k-uniq");
|
|
543
788
|
const kViewsSub = document.getElementById("k-views-sub");
|
|
544
789
|
|
|
545
790
|
|
|
546
791
|
const rangeNote = document.getElementById("range-note");
|
|
547
|
-
let currentRange = 7;
|
|
792
|
+
let currentRange = [1, 7, 30, 90].includes(Number(new URLSearchParams(location.search).get("days"))) ? Number(new URLSearchParams(location.search).get("days")) : 7;
|
|
548
793
|
|
|
549
794
|
function render(days) {
|
|
550
795
|
currentRange = days;
|
|
796
|
+
const u = new URL(location.href);
|
|
797
|
+
if (days === 7) u.searchParams.delete("days"); else u.searchParams.set("days", String(days));
|
|
798
|
+
history.replaceState(null, "", u);
|
|
551
799
|
const dom = domain(days);
|
|
552
800
|
const recs = dom.filter(d => d.rec).map(d => d.rec);
|
|
553
801
|
const tv = recs.reduce((s, r) => s + r.v, 0);
|
|
554
802
|
const tu = recs.reduce((s, r) => s + r.u, 0);
|
|
555
803
|
// 访客只能用 API 窗口去重值;超过 14 天没有该值就退回日均
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
804
|
+
// 7 天取 API 去重值,更长范围按覆盖期逐日合计
|
|
805
|
+
let uniq = LIVE.totals.uniques != null ? LIVE.totals.uniques : null;
|
|
806
|
+
// 1 天时 totals.uniques 是 14 天窗口去重值,换成当天去重才不误导
|
|
807
|
+
if (days === 1 && recs.length) uniq = recs[recs.length - 1].u;
|
|
808
|
+
if (uniq == null) uniq = recs.length ? tu : null;
|
|
809
|
+
// 主数用窗口内浏览(逐日可加,跟着范围变);访客是 GitHub 的 14 天去重值,只能放副标说清口径
|
|
810
|
+
const covered = LIVE.range && LIVE.range.covered;
|
|
811
|
+
const covN = covered || recs.length;
|
|
812
|
+
kUniq.textContent = recs.length ? fmt(tv) : "—";
|
|
813
|
+
kViewsSub.textContent = uniq == null
|
|
814
|
+
? "访客 —"
|
|
815
|
+
: days === 1
|
|
816
|
+
? `访客 ${fmt(uniq)} · ${DATA[DATA.length - 1]?.d || ""}`
|
|
817
|
+
// 去重访客只有 GitHub 的 14 天窗口,比所选范围长时它会比上面的浏览还大;
|
|
818
|
+
// 窗口写在最前面,才不会被读成「这段里来了这么多人」
|
|
819
|
+
: Math.min(covN, 14) > days
|
|
820
|
+
? `近 ${Math.min(covN, 14)} 天去重访客 ${fmt(uniq)}`
|
|
821
|
+
: `访客 ${fmt(uniq)} · 近 ${Math.min(covN, 14)} 天去重`;
|
|
561
822
|
rangeNote.textContent = dom[0].label + " → " + dom[dom.length - 1].label;
|
|
823
|
+
// issue/PR 数跟着所选窗口走,标题要说清是哪段
|
|
824
|
+
const cSpan = LIVE.starGrowth?.span;
|
|
825
|
+
document.getElementById("contrib-range").textContent = days === 1 && LIVE.range?.to
|
|
826
|
+
? label(LIVE.range.to)
|
|
827
|
+
: cSpan ? `近 ${cSpan} 天` : `近 ${days} 天`;
|
|
562
828
|
flowChart(document.getElementById("c-flow"), days);
|
|
563
829
|
npmChart(document.getElementById("c-npm"), days);
|
|
564
830
|
donut(document.getElementById("donut"));
|
|
565
831
|
ranks(document.getElementById("ranks"));
|
|
832
|
+
// 切范围后 fork 的窗口标题也得跟着变,不能停在上一段
|
|
833
|
+
renderForks(LIVE, days);
|
|
566
834
|
}
|
|
567
835
|
|
|
568
836
|
document.getElementById("seg").addEventListener("click", e => {
|
|
569
837
|
const b = e.target.closest("button");
|
|
570
838
|
if (!b) return;
|
|
571
839
|
[...e.currentTarget.children].forEach(x => x.classList.toggle("on", x === b));
|
|
572
|
-
render
|
|
840
|
+
// 先 render 会拿上一段范围的数据去填新范围的标题,等这次请求回来再一起重画
|
|
573
841
|
pull(+b.dataset.r);
|
|
574
842
|
});
|
|
575
843
|
|
|
@@ -582,22 +850,67 @@ document.getElementById("theme").addEventListener("click", () => {
|
|
|
582
850
|
render(currentRange);
|
|
583
851
|
});
|
|
584
852
|
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
853
|
+
const postJson = (path, obj, opts = {}) =>
|
|
854
|
+
fetch(path, { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify(obj), ...opts });
|
|
855
|
+
const cfgPanel = document.getElementById("cfg");
|
|
856
|
+
async function loadCfg() {
|
|
857
|
+
try {
|
|
858
|
+
const r = await fetch("/api/config", { cache: "no-store" });
|
|
859
|
+
const c = await r.json();
|
|
860
|
+
document.getElementById("cfg-base").value = c.baseurl || "";
|
|
861
|
+
document.getElementById("cfg-model").value = c.model || "";
|
|
862
|
+
document.getElementById("ai-model").textContent = c.model || "deepseek-chat";
|
|
863
|
+
if (c.apikey) document.getElementById("cfg-key").placeholder = "已保存";
|
|
864
|
+
} catch {}
|
|
865
|
+
}
|
|
866
|
+
document.getElementById("cfg-toggle").addEventListener("click", () => {
|
|
867
|
+
const open = cfgPanel.classList.toggle("open");
|
|
868
|
+
if (open) loadCfg();
|
|
869
|
+
});
|
|
870
|
+
document.getElementById("cfg-save").addEventListener("click", async () => {
|
|
871
|
+
const base = document.getElementById("cfg-base").value.trim();
|
|
872
|
+
if (!base) { document.getElementById("cfg-base").focus(); return; }
|
|
873
|
+
const btn = document.getElementById("cfg-save");
|
|
874
|
+
btn.disabled = true;
|
|
875
|
+
try {
|
|
876
|
+
const r = await postJson("/api/config", { baseurl: base, apikey: document.getElementById("cfg-key").value.trim(), model: document.getElementById("cfg-model").value.trim() });
|
|
877
|
+
if (!r.ok) throw new Error("save");
|
|
878
|
+
const c = await r.json();
|
|
879
|
+
document.getElementById("ai-model").textContent = c.model || "deepseek-chat";
|
|
880
|
+
document.getElementById("cfg-key").value = "";
|
|
881
|
+
document.getElementById("cfg-toggle").textContent = "已保存";
|
|
882
|
+
document.getElementById("ask-out").hidden = true;
|
|
883
|
+
cfgPanel.classList.remove("open");
|
|
884
|
+
loadSummary(currentRange);
|
|
885
|
+
} catch {
|
|
886
|
+
document.getElementById("cfg-toggle").textContent = "保存失败";
|
|
887
|
+
}
|
|
888
|
+
btn.disabled = false;
|
|
589
889
|
});
|
|
590
890
|
|
|
591
891
|
const rb = document.getElementById("refresh");
|
|
592
892
|
rb.addEventListener("click", async () => {
|
|
593
893
|
const keep = rb.innerHTML;
|
|
594
|
-
rb.
|
|
894
|
+
rb.disabled = true;
|
|
895
|
+
rb.textContent = "同步中…";
|
|
896
|
+
// 31 个仓库要几十秒,显示到第几个,不然只能盯着一个不动的按钮
|
|
897
|
+
const tick = setInterval(async () => {
|
|
898
|
+
try {
|
|
899
|
+
const r = await fetch("/api/progress");
|
|
900
|
+
const st = await r.json();
|
|
901
|
+
if (st.total) rb.textContent = `同步 ${st.done}/${st.total}`;
|
|
902
|
+
} catch { /* 下一次还会再问 */ }
|
|
903
|
+
}, 700);
|
|
595
904
|
try {
|
|
596
|
-
await fetch("/api/sync", { method: "POST" });
|
|
905
|
+
const res = await fetch("/api/sync", { method: "POST" });
|
|
906
|
+
const j = await res.json().catch(() => ({}));
|
|
597
907
|
await pull(currentRange, true);
|
|
598
|
-
rb.textContent = "刚更新";
|
|
908
|
+
rb.textContent = j.cached ? "已是最新" : "刚更新";
|
|
599
909
|
} catch (e) {
|
|
600
910
|
rb.textContent = "刷新失败";
|
|
911
|
+
} finally {
|
|
912
|
+
clearInterval(tick);
|
|
913
|
+
rb.disabled = false;
|
|
601
914
|
}
|
|
602
915
|
setTimeout(() => { rb.innerHTML = keep; }, 1600);
|
|
603
916
|
});
|
|
@@ -608,15 +921,333 @@ try {
|
|
|
608
921
|
if (saved === "light") document.getElementById("theme").click();
|
|
609
922
|
} catch (e) {}
|
|
610
923
|
// 实时数据:拿不到就继续用内置样例,页面始终能看
|
|
611
|
-
const LIVE = { totals: {}, range: { days: 7, storedDays: 0 }, repo: {}, contributions: { issues: [], pulls: [] }, releases: [], paths: [], npmVersions: [], updatedAt: null };
|
|
612
924
|
const label = iso => String(iso).slice(5, 10);
|
|
613
925
|
const mmdd = iso => label(iso);
|
|
614
926
|
|
|
927
|
+
function renderImpact(it) {
|
|
928
|
+
const sec = document.getElementById("sec-impact");
|
|
929
|
+
if (!it) {
|
|
930
|
+
sec.hidden = true;
|
|
931
|
+
return;
|
|
932
|
+
}
|
|
933
|
+
sec.hidden = false;
|
|
934
|
+
const pct = (v) => pctText(v);
|
|
935
|
+
// 日均保留一位小数,四位数以上加千分位
|
|
936
|
+
const num = (v) => (v == null ? "—" : (Math.round(v * 10) / 10).toLocaleString("en"));
|
|
937
|
+
const show = (k, id, sub) => {
|
|
938
|
+
const b = it.before?.[k]?.avg;
|
|
939
|
+
const a = it.after?.[k]?.avg;
|
|
940
|
+
document.getElementById(id).textContent = b === null || b === undefined ? "—" : `${num(b)} → ${num(a)}`;
|
|
941
|
+
document.getElementById(sub).textContent = pct(it.delta?.[k]) || "";
|
|
942
|
+
};
|
|
943
|
+
// 全局视图主卡不止一个仓,版本号前面要带仓名,不然不知道说的是谁
|
|
944
|
+
document.getElementById("impact-ver").textContent = `${it.name ? it.name + " " : ""}${bareTag(it.version)} · ${String(it.at).slice(5)}${it.limited ? " · 数据不足" : ""}`;
|
|
945
|
+
show("views", "impact-views", "impact-views-sub");
|
|
946
|
+
// 这个仓没有 npm 包时整格不出现,别留一个「—」让人以为数据丢了
|
|
947
|
+
const npmCell = document.getElementById("impact-npm").parentElement;
|
|
948
|
+
const hasNpm = it.before?.npm?.avg != null || it.after?.npm?.avg != null;
|
|
949
|
+
// 用行内 display 而不是 hidden:.stats div 的 flex 会盖掉 [hidden]
|
|
950
|
+
if (npmCell) npmCell.style.display = hasNpm ? "" : "none";
|
|
951
|
+
if (hasNpm) show("npm", "impact-npm", "impact-npm-sub");
|
|
952
|
+
const spanTxt = (o) => (o?.from && o?.to ? `${String(o.from).slice(5)} – ${String(o.to).slice(5)}` : null);
|
|
953
|
+
const bSpan = spanTxt(it.before?.views), aSpan = spanTxt(it.after?.views);
|
|
954
|
+
document.getElementById("impact-cover").textContent = bSpan && aSpan
|
|
955
|
+
? `前 ${bSpan}\n后 ${aSpan}`
|
|
956
|
+
: `前 ${it.before?.views?.days ?? 0} 天\n后 ${it.after?.views?.days ?? 0} 天`;
|
|
957
|
+
document.getElementById("impact-cover-sub").textContent = `前 ${it.before?.views?.days ?? 0} 天 · 后 ${it.after?.views?.days ?? 0} 天`;
|
|
958
|
+
}
|
|
959
|
+
|
|
960
|
+
let OVERVIEW = [];
|
|
961
|
+
let OV_SORT = "u";
|
|
962
|
+
|
|
963
|
+
let TOP_SIG = "";
|
|
964
|
+
function renderTop() {
|
|
965
|
+
const sec = document.getElementById("sec-top");
|
|
966
|
+
if (!sec) return;
|
|
967
|
+
const rows = OVERVIEW.filter((r) => r && r.key);
|
|
968
|
+
sec.hidden = !rows.length;
|
|
969
|
+
if (!rows.length) return;
|
|
970
|
+
// 请求的范围超过已存天数时,标题按实际覆盖的天数说,别把 90 天写成 90 天
|
|
971
|
+
const covSpan = Math.min(currentRange, LIVE.range?.covered || currentRange);
|
|
972
|
+
const span = currentRange === 1 ? (DATA[DATA.length - 1]?.d || "") : `近 ${covSpan} 天`;
|
|
973
|
+
const sig = span + "|" + rows.map((r) => `${r.key}:${r.views}:${r.npm}:${r.npmWeek}:${r.uniques}:${r.starDelta}`).join(",");
|
|
974
|
+
if (sig === TOP_SIG) return;
|
|
975
|
+
TOP_SIG = sig;
|
|
976
|
+
document.getElementById("top-note").textContent = `· ${span}`;
|
|
977
|
+
const node = document.getElementById("leaders");
|
|
978
|
+
node.textContent = "";
|
|
979
|
+
const sum = (f) => rows.reduce((a, r) => a + (Number(f(r)) || 0), 0);
|
|
980
|
+
// npm 当天数据要晚一两天才到,窗口里全空时不能把「还没采集」写成 0
|
|
981
|
+
const hasNpm = DATA.some((r) => r.n != null);
|
|
982
|
+
const metrics = [
|
|
983
|
+
{ label: "浏览最多", k: "views", total: sum((r) => r.views), empty: "没有浏览" },
|
|
984
|
+
{ label: "访客最多", k: "uniques", total: sum((r) => r.uniques), empty: "没有访客", note: currentRange === 1 ? "当天访客" : "14 天去重" },
|
|
985
|
+
{ label: "涨星最多", k: "starDelta", total: sum((r) => r.starDelta), empty: "没有新增" },
|
|
986
|
+
{ label: "下载最多", k: "npm", total: sum((r) => r.npm), empty: hasNpm ? "没有下载" : "还没采集到", emptyVal: hasNpm ? "0" : "—" },
|
|
987
|
+
];
|
|
988
|
+
for (const m of metrics) {
|
|
989
|
+
const best = [...rows].sort((a, b) => (b[m.k] ?? -1) - (a[m.k] ?? -1))[0];
|
|
990
|
+
const val = best?.[m.k];
|
|
991
|
+
const tile = document.createElement("div");
|
|
992
|
+
tile.className = "lead";
|
|
993
|
+
const label = document.createElement("div");
|
|
994
|
+
label.className = "lead-label";
|
|
995
|
+
label.textContent = m.label;
|
|
996
|
+
const name = document.createElement("div");
|
|
997
|
+
name.className = "lead-name";
|
|
998
|
+
const value = document.createElement("div");
|
|
999
|
+
value.className = "lead-value";
|
|
1000
|
+
const sub = document.createElement("div");
|
|
1001
|
+
sub.className = "lead-sub";
|
|
1002
|
+
if (!best || !(val > 0)) {
|
|
1003
|
+
name.textContent = "—";
|
|
1004
|
+
value.textContent = m.emptyVal || "0";
|
|
1005
|
+
sub.textContent = m.empty;
|
|
1006
|
+
} else {
|
|
1007
|
+
name.textContent = best.name;
|
|
1008
|
+
name.title = best.key;
|
|
1009
|
+
value.textContent = (m.k === "starDelta" ? "+" : "") + fmt(val);
|
|
1010
|
+
const pct = m.total > 0 ? Math.round((val / m.total) * 100) : null;
|
|
1011
|
+
const bits = [];
|
|
1012
|
+
if (m.note) bits.push(m.note);
|
|
1013
|
+
if (pct != null) bits.push(`占全部仓库 ${pct}%`);
|
|
1014
|
+
sub.textContent = bits.join(" · ");
|
|
1015
|
+
tile.dataset.key = best.key;
|
|
1016
|
+
tile.title = `${best.key} · 点击查看`;
|
|
1017
|
+
tile.addEventListener("click", () => switchRepo(best.key));
|
|
1018
|
+
}
|
|
1019
|
+
tile.append(label, name, value, sub);
|
|
1020
|
+
node.appendChild(tile);
|
|
1021
|
+
}
|
|
1022
|
+
}
|
|
1023
|
+
|
|
1024
|
+
function drawOverview() {
|
|
1025
|
+
document.getElementById("sec-repos").hidden = !OVERVIEW.length;
|
|
1026
|
+
const node = document.getElementById("repo-list");
|
|
1027
|
+
node.textContent = "";
|
|
1028
|
+
if (!OVERVIEW.length) return;
|
|
1029
|
+
const k = OV_SORT === "u" ? "uniques" : "npm";
|
|
1030
|
+
const projNote = document.getElementById("proj-note");
|
|
1031
|
+
if (projNote) {
|
|
1032
|
+
// 访客只有 GitHub 的 14 天去重值,下载才是这段窗口的逐日合计:
|
|
1033
|
+
// 两个长度不同的数不能挂在一个「近 N 天」后面,各自把口径说全
|
|
1034
|
+
const day = DATA[DATA.length - 1]?.d || "";
|
|
1035
|
+
projNote.textContent = currentRange === 1
|
|
1036
|
+
? `· 访客和下载都取自 ${day} 当天`
|
|
1037
|
+
: `· 访客近 14 天去重 · 下载近 ${Math.min(currentRange, LIVE.range?.covered || currentRange)} 天`;
|
|
1038
|
+
}
|
|
1039
|
+
const emptyWord = OV_SORT === "u" ? "没有访客" : "没有下载";
|
|
1040
|
+
const all = [...OVERVIEW].sort((a, b) => (b[k] ?? 0) - (a[k] ?? 0));
|
|
1041
|
+
// 零访客的仓不占行,折成一句
|
|
1042
|
+
const used = all.filter((r) => (r[k] ?? 0) > 0);
|
|
1043
|
+
const rest = all.length - used.length;
|
|
1044
|
+
const rows = used.length ? used : all.slice(0, 6);
|
|
1045
|
+
const max = Math.max(...rows.map((r) => r[k] ?? 0), 1);
|
|
1046
|
+
const cols = 2;
|
|
1047
|
+
const per = Math.ceil(rows.length / cols);
|
|
1048
|
+
for (let c = 0; c < cols; c++) {
|
|
1049
|
+
const ul = document.createElement("ul");
|
|
1050
|
+
for (const r of rows.slice(c * per, (c + 1) * per)) {
|
|
1051
|
+
const li = document.createElement("li");
|
|
1052
|
+
const name = document.createElement("span");
|
|
1053
|
+
name.className = "k";
|
|
1054
|
+
name.textContent = r.name;
|
|
1055
|
+
const track = document.createElement("span");
|
|
1056
|
+
track.className = "track";
|
|
1057
|
+
const bar = document.createElement("i");
|
|
1058
|
+
bar.style.width = Math.max(2, ((r[k] ?? 0) / max) * 100) + "%";
|
|
1059
|
+
track.appendChild(bar);
|
|
1060
|
+
const v = document.createElement("span");
|
|
1061
|
+
v.className = "v";
|
|
1062
|
+
v.textContent = r[k] == null ? "—" : fmt(r[k]);
|
|
1063
|
+
li.title = r.key;
|
|
1064
|
+
li.append(name, track, v);
|
|
1065
|
+
li.addEventListener("click", () => switchRepo(r.key));
|
|
1066
|
+
ul.appendChild(li);
|
|
1067
|
+
}
|
|
1068
|
+
if (c === cols - 1 && rest) {
|
|
1069
|
+
const li = document.createElement("li");
|
|
1070
|
+
li.className = "muted";
|
|
1071
|
+
li.style.cursor = "default";
|
|
1072
|
+
const sp = document.createElement("span");
|
|
1073
|
+
sp.className = "k";
|
|
1074
|
+
sp.textContent = `另有 ${rest} 个${emptyWord}`;
|
|
1075
|
+
li.appendChild(sp);
|
|
1076
|
+
ul.appendChild(li);
|
|
1077
|
+
}
|
|
1078
|
+
node.appendChild(ul);
|
|
1079
|
+
}
|
|
1080
|
+
}
|
|
1081
|
+
|
|
1082
|
+
document.getElementById("ov-sort").addEventListener("click", (e) => {
|
|
1083
|
+
const b = e.target.closest("[data-sort]");
|
|
1084
|
+
if (!b) return;
|
|
1085
|
+
OV_SORT = b.dataset.sort;
|
|
1086
|
+
[...document.getElementById("ov-sort").children].forEach((x) => x.classList.toggle("on", x === b));
|
|
1087
|
+
drawOverview();
|
|
1088
|
+
});
|
|
1089
|
+
|
|
1090
|
+
// 统一成倍数:+795% 和 ×38 混排没法一眼比大小
|
|
1091
|
+
// 倍数带方向:单看 ×0.7 看不出是降了一半还是涨了
|
|
1092
|
+
function pctText(d) {
|
|
1093
|
+
if (d === null || d === undefined) return "";
|
|
1094
|
+
const r = 1 + d / 100;
|
|
1095
|
+
// 显示的倍数四舍五入到 ×1.0 时就是持平,别配上升箭头
|
|
1096
|
+
if (Number(r.toFixed(1)) === 1) return "持平";
|
|
1097
|
+
const arrow = r >= 1 ? "↑ " : "↓ ";
|
|
1098
|
+
if (r >= 10) return arrow + "×" + Math.round(r);
|
|
1099
|
+
if (r >= 0.1) return arrow + "×" + r.toFixed(1);
|
|
1100
|
+
return arrow + "×" + r.toFixed(2);
|
|
1101
|
+
}
|
|
1102
|
+
|
|
1103
|
+
function renderImpacts(list) {
|
|
1104
|
+
const all = (list || []).filter((i) => !i.limited && i.before?.views?.avg != null && i.after?.views?.avg != null);
|
|
1105
|
+
// 日均不到 5 次浏览的仓,倍数只是噪声(0.3 → 12 也是 ×39),排在最前面反而看不懂
|
|
1106
|
+
const solid = all.filter((i) => (i.before?.views?.avg ?? 0) >= 5);
|
|
1107
|
+
const rows = solid.length ? solid : all;
|
|
1108
|
+
document.getElementById("sec-cmp").hidden = !rows.length;
|
|
1109
|
+
const node = document.getElementById("cmp-list");
|
|
1110
|
+
node.textContent = "";
|
|
1111
|
+
// 上面那张主卡就是这个列表里最靠前的那条,列表里再出现一次只是重复
|
|
1112
|
+
const main = LIVE.impact;
|
|
1113
|
+
const sameAsMain = (r) => main && ((r.url && main.url && r.url === main.url) || (String(r.at) === String(main.at) && r.version === main.version));
|
|
1114
|
+
const rest = main ? rows.filter((r) => !sameAsMain(r)) : rows;
|
|
1115
|
+
const relNote = document.getElementById("rel-note");
|
|
1116
|
+
// 这行说的是能算出前后对比的仓,不是有发版的仓,别写成「有发版」
|
|
1117
|
+
// 这里数的是「最新一版落在所选范围里」的仓,前后对比各用自己那 90 天,窗口要说清
|
|
1118
|
+
if (relNote) relNote.textContent = rows.length ? ` · 范围内 ${rows.length} 个仓可对比` : "";
|
|
1119
|
+
const rank = [...rest].sort((a, b) => (b.delta?.views ?? -1e9) - (a.delta?.views ?? -1e9)).slice(0, 8);
|
|
1120
|
+
for (const r of rank) {
|
|
1121
|
+
const li = document.createElement("li");
|
|
1122
|
+
li.title = `${r.key} · 下载日均 ${r.before?.npm?.avg ?? "—"} → ${r.after?.npm?.avg ?? "—"}`;
|
|
1123
|
+
const k = document.createElement("span"); k.className = "k"; k.textContent = r.name;
|
|
1124
|
+
const ver = document.createElement("span"); ver.className = "ver"; ver.textContent = `${bareTag(r.version)} · ${String(r.at).slice(5)}`;
|
|
1125
|
+
const v = document.createElement("span"); v.className = "v"; v.textContent = `${fmt(r.before.views.avg)} → ${fmt(r.after.views.avg)}`;
|
|
1126
|
+
const d = document.createElement("span"); d.className = "d"; d.textContent = pctText(r.delta?.views);
|
|
1127
|
+
li.append(k, ver, v, d);
|
|
1128
|
+
li.addEventListener("click", () => switchRepo(r.key));
|
|
1129
|
+
node.appendChild(li);
|
|
1130
|
+
}
|
|
1131
|
+
if (rest.length > rank.length) {
|
|
1132
|
+
const li = document.createElement("li");
|
|
1133
|
+
li.className = "muted";
|
|
1134
|
+
li.style.cursor = "default";
|
|
1135
|
+
const sp = document.createElement("span"); sp.className = "k"; sp.textContent = `另有 ${rest.length - rank.length} 个仓未列出`;
|
|
1136
|
+
li.appendChild(sp);
|
|
1137
|
+
node.appendChild(li);
|
|
1138
|
+
}
|
|
1139
|
+
}
|
|
1140
|
+
|
|
1141
|
+
function renderForks(json, days) {
|
|
1142
|
+
const sec = document.getElementById("sec-forks");
|
|
1143
|
+
const f = json.forks;
|
|
1144
|
+
if (!f || f.total == null) { sec.hidden = true; return; }
|
|
1145
|
+
sec.hidden = false;
|
|
1146
|
+
const all = json.repo?.fullName === "全部仓库";
|
|
1147
|
+
const items = f.items || [];
|
|
1148
|
+
const note = document.getElementById("fork-note");
|
|
1149
|
+
note.hidden = true;
|
|
1150
|
+
note.textContent = "";
|
|
1151
|
+
// 标签必须写实际取到的窗口:1 天视图是最近一个完整日,90 天也可能只有 29 天数据
|
|
1152
|
+
const span = f.from && f.to ? Math.round((Date.parse(f.to) - Date.parse(f.from)) / 86400000) + 1 : days;
|
|
1153
|
+
document.getElementById("fork-range").textContent = span === 1 ? "今天" : `近 ${span} 天`;
|
|
1154
|
+
document.getElementById("fork-fresh").textContent = f.at ? `${label(f.at)} 更新` : "";
|
|
1155
|
+
// 卡片只报这一窗口里的 fork:总数是全生命周期的量,混在窗口卡片里会被读成窗口数
|
|
1156
|
+
const inWin = f.inWindow || 0;
|
|
1157
|
+
document.getElementById("f-new").textContent = inWin.toLocaleString("en");
|
|
1158
|
+
const reposWith = (json.repos || []).filter((r) => (r.newForks || 0) > 0).length;
|
|
1159
|
+
document.getElementById("f-new-sub").textContent = !items.length
|
|
1160
|
+
? "没有新 fork"
|
|
1161
|
+
: all
|
|
1162
|
+
? `${reposWith} 个仓库`
|
|
1163
|
+
: "";
|
|
1164
|
+
// 窗口里没有的时候,最近那个只当「上次」写进子标,别放在「最近」上被读成本窗口
|
|
1165
|
+
const inItem = items[0];
|
|
1166
|
+
const past = f.latest || items[0];
|
|
1167
|
+
document.getElementById("f-last").textContent = inItem ? inItem.login : "—";
|
|
1168
|
+
const short = (x) => (all && x.repo ? x.repo.split("/").slice(-1)[0] + " · " : "");
|
|
1169
|
+
document.getElementById("f-last-sub").textContent = inItem
|
|
1170
|
+
? short(inItem) + label(inItem.at)
|
|
1171
|
+
: past
|
|
1172
|
+
? "上次 " + label(past.at) + (all && past.repo ? " · " + past.repo.split("/").slice(-1)[0] : "")
|
|
1173
|
+
: "";
|
|
1174
|
+
const list = document.getElementById("fork-list");
|
|
1175
|
+
list.textContent = "";
|
|
1176
|
+
if (!items.length) return;
|
|
1177
|
+
if (all) {
|
|
1178
|
+
if (items.length >= 100) {
|
|
1179
|
+
note.hidden = false;
|
|
1180
|
+
note.textContent = "只统计最近 100 个 fork";
|
|
1181
|
+
}
|
|
1182
|
+
const rows = (json.repos || []).filter((r) => (r.newForks || 0) > 0)
|
|
1183
|
+
// 同分时按窗口里最近那个 fork 排:累计 fork 是全生命周期的量,不该决定这张表的顺序
|
|
1184
|
+
.sort((a, b) => (b.newForks || 0) - (a.newForks || 0)
|
|
1185
|
+
|| Date.parse(b.lastFork?.at || 0) - Date.parse(a.lastFork?.at || 0));
|
|
1186
|
+
if (!rows.length) return;
|
|
1187
|
+
const table = document.createElement("table");
|
|
1188
|
+
// 表里只放这一段窗口的量:累计 fork 是全生命周期的数,放进来会被当成窗口结果
|
|
1189
|
+
table.innerHTML = "<thead><tr><th>仓库</th><th>新增</th><th>最近</th></tr></thead>";
|
|
1190
|
+
const body = document.createElement("tbody");
|
|
1191
|
+
for (const r of rows) {
|
|
1192
|
+
const tr = document.createElement("tr");
|
|
1193
|
+
tr.innerHTML = `<td>${r.name}</td><td>${(r.newForks || 0).toLocaleString("en")}</td><td>${r.lastFork ? label(r.lastFork.at) : "—"}</td>`;
|
|
1194
|
+
body.appendChild(tr);
|
|
1195
|
+
}
|
|
1196
|
+
table.appendChild(body);
|
|
1197
|
+
list.appendChild(table);
|
|
1198
|
+
return;
|
|
1199
|
+
}
|
|
1200
|
+
if (items.length > 20) {
|
|
1201
|
+
note.hidden = false;
|
|
1202
|
+
note.textContent = `只列最近 20 个,另有 ${Math.max(items.length, inWin) - 20} 个`;
|
|
1203
|
+
}
|
|
1204
|
+
const table = document.createElement("table");
|
|
1205
|
+
table.innerHTML = "<thead><tr><th>谁</th><th>时间</th></tr></thead>";
|
|
1206
|
+
const body = document.createElement("tbody");
|
|
1207
|
+
for (const x of items.slice(0, 20)) {
|
|
1208
|
+
const tr = document.createElement("tr");
|
|
1209
|
+
const who = document.createElement("td");
|
|
1210
|
+
const a = document.createElement("a");
|
|
1211
|
+
a.href = x.url;
|
|
1212
|
+
a.target = "_blank";
|
|
1213
|
+
a.rel = "noreferrer";
|
|
1214
|
+
a.textContent = x.login;
|
|
1215
|
+
who.appendChild(a);
|
|
1216
|
+
const when = document.createElement("td");
|
|
1217
|
+
when.textContent = label(x.at);
|
|
1218
|
+
tr.append(who, when);
|
|
1219
|
+
body.appendChild(tr);
|
|
1220
|
+
}
|
|
1221
|
+
table.appendChild(body);
|
|
1222
|
+
list.appendChild(table);
|
|
1223
|
+
}
|
|
1224
|
+
|
|
1225
|
+
function renderFunnel(f) {
|
|
1226
|
+
const sec = document.getElementById("sec-funnel");
|
|
1227
|
+
if (!f || f.views == null) { sec.hidden = true; return; }
|
|
1228
|
+
sec.hidden = false;
|
|
1229
|
+
document.getElementById("f-views").textContent = fmt(f.views);
|
|
1230
|
+
// 漏斗固定取最近 14 个完整日,和上面选的范围无关,窗口写在数字下面而不是标题上
|
|
1231
|
+
document.getElementById("f-views-sub").textContent = `近 ${Math.min(LIVE.range?.covered || 14, 14)} 天`;
|
|
1232
|
+
document.getElementById("f-home").textContent = f.home == null ? "—" : fmt(f.home);
|
|
1233
|
+
document.getElementById("f-home-sub").textContent = f.home == null ? "" : Math.round((f.home / f.views) * 100) + "% 浏览";
|
|
1234
|
+
const fNoPkg = LIVE.repo && LIVE.repo.fullName !== "全部仓库" && !LIVE.repo.npmPkg;
|
|
1235
|
+
document.getElementById("f-npm").textContent = f.npm == null || fNoPkg ? "—" : fmt(f.npm);
|
|
1236
|
+
// 下载和浏览取同一段 14 天,只给日均,不跨窗口算倍数
|
|
1237
|
+
const fDays = Math.min(LIVE.range?.covered || 14, 14);
|
|
1238
|
+
document.getElementById("f-npm-sub").textContent = f.npm == null || fNoPkg ? "" : `日均 ${fmt(Math.round(f.npm / fDays))} 次`;
|
|
1239
|
+
}
|
|
1240
|
+
|
|
615
1241
|
function applyLive(json) {
|
|
616
1242
|
Object.assign(LIVE, json);
|
|
1243
|
+
LIVE_SET = true;
|
|
1244
|
+
PATHS = null;
|
|
1245
|
+
RANKS = [];
|
|
617
1246
|
if (Array.isArray(json.series) && json.series.length) {
|
|
618
1247
|
DATA = json.series.map(r => ({ d: label(r.d), v: r.v ?? 0, u: r.u ?? 0, c: r.c ?? 0, cu: r.cu ?? 0, n: r.n }));
|
|
619
1248
|
LAST = dayIdx(json.series[json.series.length - 1].d);
|
|
1249
|
+
FIRST = json.range?.first ? dayIdx(json.range.first) : null;
|
|
1250
|
+
if (FIRST != null && FIRST < 0) FIRST = null;
|
|
620
1251
|
RELEASE = {};
|
|
621
1252
|
for (const rel of json.releases || []) {
|
|
622
1253
|
const k = label(rel.at);
|
|
@@ -624,46 +1255,182 @@ function applyLive(json) {
|
|
|
624
1255
|
}
|
|
625
1256
|
}
|
|
626
1257
|
if (Array.isArray(json.paths) && json.paths.length) {
|
|
627
|
-
const
|
|
628
|
-
const
|
|
629
|
-
|
|
630
|
-
|
|
1258
|
+
const merged = new Map();
|
|
1259
|
+
for (const p of json.paths) merged.set(shortPath(p.p), (merged.get(shortPath(p.p)) || 0) + p.n);
|
|
1260
|
+
const rows = [...merged.entries()].sort((a, b) => b[1] - a[1]).slice(0, 3);
|
|
1261
|
+
const rest = [...merged.values()].reduce((s, n) => s + n, 0) - rows.reduce((s, r) => s + r[1], 0);
|
|
1262
|
+
PATHS = rows.map(([k, n], i) => [k, n, i === 0 ? "--brand" : i === 1 ? "--machine" : "--event"]);
|
|
1263
|
+
if (rest > 0) PATHS.push(["其他页面", rest, "--label-secondary"]);
|
|
631
1264
|
}
|
|
632
1265
|
if (Array.isArray(json.referrers) && json.referrers.length) {
|
|
633
|
-
|
|
1266
|
+
const refTotal = json.referrers.reduce((a, r) => a + r.n, 0);
|
|
1267
|
+
const refTop = json.referrers.slice(0, 4);
|
|
1268
|
+
const refShown = refTop.reduce((a, r) => a + r.n, 0);
|
|
1269
|
+
const refRest = refTotal - refShown;
|
|
1270
|
+
// GitHub 只回前几个来源,写「有来源 N 次」会被读成全部推荐流量的总数
|
|
1271
|
+
const refNote = refTotal
|
|
1272
|
+
? `前 ${refTop.length} 个 ${refShown.toLocaleString("en-US")} 次${refRest > 0 ? ` · 另有 ${refRest.toLocaleString("en-US")} 次来自其他来源` : ""}`
|
|
1273
|
+
: "";
|
|
1274
|
+
RANKS = [["从哪来", refTop.map(r => [r.from.replace(/^www\./, ""), r.n]), refNote]];
|
|
634
1275
|
}
|
|
635
1276
|
const repo = json.repo || {};
|
|
636
|
-
|
|
637
|
-
|
|
1277
|
+
const ownerEl = document.getElementById("repo-owner");
|
|
1278
|
+
const nameEl = document.getElementById("repo-name");
|
|
1279
|
+
const askQ = document.getElementById("ask-q");
|
|
1280
|
+
if (askQ) askQ.placeholder = repo.fullName === "全部仓库" ? "问全部仓库" : "问这个仓库";
|
|
1281
|
+
if (repo.fullName === "全部仓库") {
|
|
1282
|
+
ownerEl.textContent = "";
|
|
1283
|
+
nameEl.textContent = "全部仓库";
|
|
1284
|
+
setRepoLink(null);
|
|
1285
|
+
} else {
|
|
1286
|
+
ownerEl.textContent = repo.owner ? repo.owner + " /" : "";
|
|
1287
|
+
nameEl.textContent = repo.name || "";
|
|
1288
|
+
setRepoLink(repo.fullName);
|
|
1289
|
+
}
|
|
638
1290
|
const c = json.contributions || { issues: [], pulls: [] };
|
|
639
1291
|
const ic = c.issues.length, pc = c.pulls.length;
|
|
640
1292
|
document.getElementById("k-contrib").textContent = ic + pc;
|
|
641
|
-
|
|
1293
|
+
// 1 天视图报的是最近一个完整日,不是今天
|
|
1294
|
+
const dayLbl = json.range && json.range.to ? label(json.range.to) : "今天";
|
|
1295
|
+
// 子标要说清是哪几类反馈,别只给一个合计
|
|
1296
|
+
// 多天窗口里数据不够长时,写实际有数据的天数:90 天的选择只有 19 天数据,不能当成 90 天
|
|
1297
|
+
// 口径和摘要一致:min(图上选的天数, 实际覆盖天数),today 没采集到不算一天
|
|
1298
|
+
const rg = json.range || {}, asked = rg.days;
|
|
1299
|
+
const spanDays = asked && rg.covered ? Math.min(asked, rg.covered) : null;
|
|
1300
|
+
const covLbl = spanDays && asked && spanDays < asked ? spanDays + " 天 · " : "";
|
|
1301
|
+
document.getElementById("k-contrib-sub").textContent = currentRange === 1
|
|
1302
|
+
? (ic + pc ? dayLbl + " 新开 " + ic + " issue、" + pc + " PR" : dayLbl + " 没有新开 issue 或 PR")
|
|
1303
|
+
: covLbl + ic + " issue、" + pc + " PR";
|
|
642
1304
|
document.getElementById("k-stars").textContent = repo.stars ?? "—";
|
|
643
|
-
|
|
1305
|
+
// 星标增长只报真实覆盖区间:1 天报当天,多天报有数据的跨度
|
|
1306
|
+
const sg = json.starGrowth;
|
|
1307
|
+
const gTxt = sg && Number.isFinite(sg.delta) && sg.span
|
|
1308
|
+
? (sg.span === 1 ? label(sg.to) : "近 " + sg.span + " 天") + " " + (sg.delta > 0 ? "+" + sg.delta : sg.delta === 0 ? "±0" : String(sg.delta))
|
|
1309
|
+
: "";
|
|
1310
|
+
// 星标卡下面报的 fork 也要是这一窗口的,跟左边的星标增量对齐
|
|
1311
|
+
const forkWin = json.forks ? json.forks.inWindow || 0 : 0;
|
|
1312
|
+
document.getElementById("k-forks").textContent = (gTxt ? gTxt + " · " : "")
|
|
1313
|
+
+ (forkWin ? "新增 " + forkWin + " 个 fork" : "没有新 fork")
|
|
1314
|
+
+ (repo.fullName === "全部仓库" && repo.count ? " · " + repo.count + " 个仓" : "");
|
|
644
1315
|
const rels = (json.releases || []).filter(r => DATA.some(x => x.d === label(r.at)));
|
|
645
|
-
|
|
1316
|
+
// 后端对发版列表有硬上限(全局 120、单仓 200):只有真的取满上限,数字才是下限
|
|
1317
|
+
const relCap = repo.fullName === "全部仓库" ? 120 : 200;
|
|
1318
|
+
const relCapped = rels.length >= relCap;
|
|
1319
|
+
document.getElementById("k-rel").textContent = relCapped ? rels.length + "+" : rels.length;
|
|
1320
|
+
const relSpan = repo.fullName === "全部仓库"
|
|
1321
|
+
? (() => { const first = label(rels[rels.length - 1].at), last = label(rels[0].at); return first === last ? last : first + " → " + last; })()
|
|
1322
|
+
: (() => { const first = bareTag(rels[rels.length - 1].tag), last = bareTag(rels[0].tag); return first === last ? last : first + " → " + last; })();
|
|
1323
|
+
// 截断时说清这个区间只是最近若干个,别让人把 11-07 当成窗口起点
|
|
646
1324
|
document.getElementById("k-rel-sub").textContent = rels.length
|
|
647
|
-
? rels
|
|
1325
|
+
? (relCapped ? "最近 " + rels.length + " 个 · " + relSpan : relSpan)
|
|
648
1326
|
: "本窗口无发版";
|
|
649
|
-
const
|
|
1327
|
+
const pending = c.open ? c.open.issues : c.issues.filter((x) => x.state === "open");
|
|
650
1328
|
document.getElementById("s-issues").textContent = ic + " 个";
|
|
651
|
-
document.getElementById("s-issues-sub")
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
const
|
|
1329
|
+
const issub = document.getElementById("s-issues-sub");
|
|
1330
|
+
issub.textContent = "";
|
|
1331
|
+
// 一个都别藏:没有 hover 的触屏上 tooltip 等于不存在,每条都做成链接
|
|
1332
|
+
const addLinks = (parent, rows) => {
|
|
1333
|
+
rows.forEach((x, i) => {
|
|
1334
|
+
if (i) parent.appendChild(document.createTextNode("、"));
|
|
1335
|
+
const a = document.createElement("a");
|
|
1336
|
+
a.href = x.url;
|
|
1337
|
+
a.target = "_blank";
|
|
1338
|
+
a.rel = "noreferrer";
|
|
1339
|
+
a.textContent = `${(x.repo || "").split("/")[1] || ""} #${x.number}`.trim();
|
|
1340
|
+
parent.appendChild(a);
|
|
1341
|
+
});
|
|
1342
|
+
};
|
|
1343
|
+
if (!pending.length) {
|
|
1344
|
+
// 没有还开着的,不等于「都回复过」:关掉的也可能是没人理的
|
|
1345
|
+
issub.textContent = ic ? `窗口内 ${ic} 个都已关闭` : "没有外部 issue";
|
|
1346
|
+
} else {
|
|
1347
|
+
const replied = pending.some((x) => (x.comments ?? 0) > 0);
|
|
1348
|
+
issub.textContent = (ic ? "" : "窗口内没有新的;") + (pending.length === 1 ? (replied ? "还开着:" : "没回:") : `${replied ? "还开着" : "没回"} ${pending.length} 个:`);
|
|
1349
|
+
addLinks(issub, pending);
|
|
1350
|
+
}
|
|
655
1351
|
document.getElementById("s-prs").textContent = pc + " 个";
|
|
656
|
-
document.getElementById("s-prs-sub")
|
|
657
|
-
|
|
658
|
-
|
|
1352
|
+
const prSub = document.getElementById("s-prs-sub");
|
|
1353
|
+
const prMerged = c.pulls.filter((x) => x.merged).length;
|
|
1354
|
+
const openPrs = c.open ? c.open.pulls : c.pulls.filter((x) => !x.merged);
|
|
1355
|
+
prSub.textContent = "";
|
|
1356
|
+
if (openPrs.length) {
|
|
1357
|
+
prSub.textContent = (prMerged ? `已合并 ${prMerged} 个 · ` : "") + (pc ? "" : "窗口内没有新的;")
|
|
1358
|
+
+ (openPrs.length === 1 ? "待合:" : `待合 ${openPrs.length} 个:`);
|
|
1359
|
+
addLinks(prSub, openPrs);
|
|
1360
|
+
} else if (!pc) {
|
|
1361
|
+
prSub.textContent = "没有外部 PR";
|
|
1362
|
+
} else {
|
|
1363
|
+
prSub.textContent = `窗口内 ${pc} 个都已处理`;
|
|
1364
|
+
}
|
|
1365
|
+
const fresh = document.getElementById("contrib-fresh");
|
|
1366
|
+
if (fresh) {
|
|
1367
|
+
const d = c.at ? new Date(c.at) : null;
|
|
1368
|
+
fresh.textContent = d && !Number.isNaN(d.getTime()) ? `· ${String(d.getHours()).padStart(2, "0")}:${String(d.getMinutes()).padStart(2, "0")} 更新` : "";
|
|
1369
|
+
}
|
|
659
1370
|
const al = c.alerts;
|
|
660
1371
|
const opened = al ? ["dependabot", "codeScanning", "secretScanning"].filter(k => al[k]?.available) : [];
|
|
661
1372
|
const total = al ? opened.reduce((s, k) => s + (al[k].open || 0), 0) : null;
|
|
662
|
-
|
|
663
|
-
|
|
1373
|
+
renderImpact(json.impact);
|
|
1374
|
+
renderImpacts(json.impacts);
|
|
1375
|
+
renderFunnel(json.funnel);
|
|
1376
|
+
// 这里还没拿到 render(days) 的参数:用当前窗口,切范围时 render 会再刷一次
|
|
1377
|
+
renderForks(json, json.range?.days || currentRange);
|
|
1378
|
+
OVERVIEW = json.repos || [];
|
|
1379
|
+
drawOverview();
|
|
1380
|
+
renderTop();
|
|
1381
|
+
const atype = { dependabot: "依赖漏洞", codeScanning: "代码扫描", secretScanning: "密钥泄漏" };
|
|
1382
|
+
const asub = document.getElementById("s-alerts-sub");
|
|
1383
|
+
const aval = document.getElementById("s-alerts");
|
|
1384
|
+
const blocked = !!al && ["dependabot", "codeScanning", "secretScanning"].every((k) => al[k] && !al[k].available && al[k].blocked);
|
|
1385
|
+
aval.textContent = blocked ? "缺权限" : !al || !opened.length ? "关闭" : (total || 0) + " 条";
|
|
1386
|
+
asub.textContent = "";
|
|
1387
|
+
asub.removeAttribute("title");
|
|
1388
|
+
if (blocked) {
|
|
1389
|
+
asub.textContent = "重新授权 GitHub";
|
|
1390
|
+
} else if (!al || !opened.length) {
|
|
1391
|
+
asub.textContent = "无数据";
|
|
1392
|
+
} else if (!total) {
|
|
1393
|
+
// 0 条要说清零的含义,不能拿「功能已开启」当解释
|
|
1394
|
+
asub.textContent = json.repo && json.repo.fullName === "全部仓库" ? "全部仓库都没有待处理" : "没有待处理";
|
|
1395
|
+
} else if (Array.isArray(json.repos)) {
|
|
1396
|
+
const flat = opened.flatMap((k) => (al[k].repos || []).filter((r) => r.open > 0).map((r) => ({ type: k, ...r })));
|
|
1397
|
+
flat.sort((x, y) => y.open - x.open);
|
|
1398
|
+
const top = flat[0];
|
|
1399
|
+
if (top) {
|
|
1400
|
+
const a = document.createElement("a");
|
|
1401
|
+
a.href = `https://github.com/${top.key}/security/${top.type === "dependabot" ? "dependabot" : top.type === "codeScanning" ? "code-scanning" : "secret-scanning"}`;
|
|
1402
|
+
a.target = "_blank";
|
|
1403
|
+
a.rel = "noreferrer";
|
|
1404
|
+
a.textContent = `${top.key.split("/")[1]} ${top.open} 条`;
|
|
1405
|
+
// 主数是全部仓库合计,子标只点了最大的一仓,得说清这两件事
|
|
1406
|
+
asub.textContent = json.repo && json.repo.fullName === "全部仓库" ? "全部仓库合计 · 最多 " : "最多 ";
|
|
1407
|
+
asub.appendChild(a);
|
|
1408
|
+
asub.append(` · ${atype[top.type]}`);
|
|
1409
|
+
asub.title = flat.map((r) => `${r.key.split("/")[1]} ${atype[r.type]} ${r.open}`).join("\n");
|
|
1410
|
+
} else {
|
|
1411
|
+
asub.textContent = "待处理";
|
|
1412
|
+
}
|
|
1413
|
+
} else {
|
|
1414
|
+
const parts = opened.filter((k) => al[k].open > 0).map((k) => `${atype[k]} ${al[k].open}`);
|
|
1415
|
+
const a = document.createElement("a");
|
|
1416
|
+
a.href = `https://github.com/${json.repo.fullName}/security`;
|
|
1417
|
+
a.target = "_blank";
|
|
1418
|
+
a.rel = "noreferrer";
|
|
1419
|
+
asub.append(a);
|
|
1420
|
+
const txt = parts.length ? parts.join("、") : "待处理";
|
|
1421
|
+
a.textContent = txt;
|
|
1422
|
+
asub.title = "依赖漏洞 / 代码扫描 / 密钥泄漏";
|
|
1423
|
+
}
|
|
664
1424
|
const t = json.totals || {};
|
|
665
|
-
|
|
666
|
-
|
|
1425
|
+
// 逐日下载是按窗口存的,跟 npmWeek 那个固定 7 天滚动值不是一回事:这里只报窗口合计
|
|
1426
|
+
const npmWin = t.npm;
|
|
1427
|
+
document.getElementById("k-npm").textContent = npmWin != null ? fmt(npmWin) : "—";
|
|
1428
|
+
const npmSub = document.getElementById("k-npm-sub");
|
|
1429
|
+
if (npmSub) {
|
|
1430
|
+
const span = currentRange === 1 ? "当天" : `近 ${Math.min(currentRange, LIVE.range?.covered || currentRange)} 天`;
|
|
1431
|
+
const noPkg = repo.fullName !== "全部仓库" && LIVE.repo && !LIVE.repo.npmPkg;
|
|
1432
|
+
npmSub.textContent = noPkg ? "没有关联 npm 包" : npmWin == null ? "还没采集到"
|
|
1433
|
+
: (repo.fullName === "全部仓库" && repo.count ? repo.count + " 个仓 · " : "") + span;
|
|
667
1434
|
}
|
|
668
1435
|
const days = json.range?.storedDays || 0;
|
|
669
1436
|
document.getElementById("r-days").textContent = days + " 天";
|
|
@@ -673,49 +1440,423 @@ function applyLive(json) {
|
|
|
673
1440
|
}
|
|
674
1441
|
}
|
|
675
1442
|
|
|
676
|
-
|
|
1443
|
+
let REPOS = [];
|
|
1444
|
+
let currentRepo = new URLSearchParams(location.search).get("repo") || "all";
|
|
1445
|
+
function setRepoLink(fullName) {
|
|
1446
|
+
const a = document.getElementById("repo-open");
|
|
1447
|
+
if (!a) return;
|
|
1448
|
+
const owner = REPOS[0] ? REPOS[0].key.split("/")[0] : "";
|
|
1449
|
+
const url = fullName ? "https://github.com/" + fullName : owner ? "https://github.com/" + owner : "";
|
|
1450
|
+
if (url) { a.href = url; a.hidden = false; } else a.hidden = true;
|
|
1451
|
+
}
|
|
1452
|
+
|
|
1453
|
+
const PICK = document.getElementById("repo-pick");
|
|
1454
|
+
const MENU = document.getElementById("repo-menu");
|
|
1455
|
+
|
|
1456
|
+
function closeMenu() {
|
|
1457
|
+
MENU.hidden = true;
|
|
1458
|
+
PICK.setAttribute("aria-expanded", "false");
|
|
1459
|
+
}
|
|
1460
|
+
|
|
1461
|
+
function paintRepos() {
|
|
1462
|
+
MENU.innerHTML = "";
|
|
1463
|
+
const add = (key, label) => {
|
|
1464
|
+
const b = document.createElement("button");
|
|
1465
|
+
b.type = "button";
|
|
1466
|
+
b.textContent = label;
|
|
1467
|
+
b.dataset.key = key;
|
|
1468
|
+
b.classList.toggle("on", key === currentRepo);
|
|
1469
|
+
MENU.appendChild(b);
|
|
1470
|
+
};
|
|
1471
|
+
add("all", "全部仓库");
|
|
1472
|
+
for (const r of REPOS) add(r.key, r.label.replace(/^[^/]+\//, ""));
|
|
1473
|
+
closeMenu();
|
|
1474
|
+
}
|
|
1475
|
+
|
|
1476
|
+
async function loadRepos() {
|
|
677
1477
|
try {
|
|
678
|
-
const res = await fetch("/api/
|
|
1478
|
+
const res = await fetch("/api/repos", { cache: "no-store" });
|
|
1479
|
+
if (!res.ok) return;
|
|
1480
|
+
const data = await res.json();
|
|
1481
|
+
REPOS = data.repos || [];
|
|
1482
|
+
if (currentRepo !== "all" && !REPOS.some((r) => r.key === currentRepo)) {
|
|
1483
|
+
// 解析口径跟后端 resolveKey 对齐:精确 → 忽略大小写 → 仓名唯一匹配
|
|
1484
|
+
// 这样?repo=Envoy 和大小写/owner 写错的整名链接都能落到同一个仓,不会误退回全部仓库
|
|
1485
|
+
const q = currentRepo.toLowerCase();
|
|
1486
|
+
const nameOf = (k) => k.split("/")[1]?.toLowerCase() || "";
|
|
1487
|
+
// 只传仓名的链接按仓名唯一匹配;带 owner 的链接必须整个 key 对上(忽略大小写)
|
|
1488
|
+
const byName = currentRepo.includes("/") ? [] : REPOS.filter((r) => nameOf(r.key) === q);
|
|
1489
|
+
const hit = REPOS.find((r) => r.key.toLowerCase() === q)
|
|
1490
|
+
|| (byName.length === 1 ? byName[0] : null);
|
|
1491
|
+
const asked = currentRepo;
|
|
1492
|
+
currentRepo = hit ? hit.key : "all";
|
|
1493
|
+
// 链接里的仓没绑定时把参数改掉:否则下次刷新又退回全部仓库,还看不出为什么
|
|
1494
|
+
const u = new URL(location.href);
|
|
1495
|
+
if (hit) u.searchParams.set("repo", hit.key);
|
|
1496
|
+
else { u.searchParams.delete("repo"); stickyNote = true; repoNote("没有绑定 " + asked + ",已切回全部仓库"); }
|
|
1497
|
+
history.replaceState(null, "", u);
|
|
1498
|
+
}
|
|
1499
|
+
paintRepos();
|
|
1500
|
+
const cur = REPOS.find((r) => r.key === currentRepo);
|
|
1501
|
+
document.getElementById("repo-name").textContent = cur ? cur.key.replace(/^[^/]+\//, "") : "全部仓库";
|
|
1502
|
+
document.getElementById("repo-owner").textContent = cur ? cur.key.split("/")[0] + " /" : "";
|
|
1503
|
+
setRepoLink(cur ? cur.key : null);
|
|
1504
|
+
} catch (e) {}
|
|
1505
|
+
}
|
|
1506
|
+
|
|
1507
|
+
PICK.addEventListener("click", (e) => {
|
|
1508
|
+
e.stopPropagation();
|
|
1509
|
+
const open = MENU.hidden;
|
|
1510
|
+
MENU.hidden = !open;
|
|
1511
|
+
PICK.setAttribute("aria-expanded", String(open));
|
|
1512
|
+
});
|
|
1513
|
+
|
|
1514
|
+
function switchRepo(key) {
|
|
1515
|
+
stickyNote = false;
|
|
1516
|
+
currentRepo = key;
|
|
1517
|
+
paintRepos();
|
|
1518
|
+
const cur = REPOS.find((r) => r.key === key);
|
|
1519
|
+
document.getElementById("repo-name").textContent = key === "all" ? "全部仓库" : key.replace(/^[^/]+\//, "");
|
|
1520
|
+
document.getElementById("repo-owner").textContent = key === "all" ? "" : key.split("/")[0] + " /";
|
|
1521
|
+
setRepoLink(key === "all" ? null : key);
|
|
1522
|
+
const u = new URL(location.href);
|
|
1523
|
+
if (key === "all") u.searchParams.delete("repo"); else u.searchParams.set("repo", key);
|
|
1524
|
+
history.replaceState(null, "", u);
|
|
1525
|
+
pull(currentRange, true);
|
|
1526
|
+
}
|
|
1527
|
+
|
|
1528
|
+
MENU.addEventListener("click", (e) => {
|
|
1529
|
+
const b = e.target.closest("button");
|
|
1530
|
+
if (!b) return;
|
|
1531
|
+
switchRepo(b.dataset.key);
|
|
1532
|
+
});
|
|
1533
|
+
|
|
1534
|
+
document.addEventListener("click", () => closeMenu());
|
|
1535
|
+
|
|
1536
|
+
let PULL_SEQ = 0;
|
|
1537
|
+
// 「这个仓没绑定」这类要一直留着,直到用户自己换仓;网络抖动的提示下次拉通就清
|
|
1538
|
+
let stickyNote = false;
|
|
1539
|
+
function repoNote(txt) {
|
|
1540
|
+
const el = document.getElementById("repo-note");
|
|
1541
|
+
if (!el) return;
|
|
1542
|
+
el.textContent = txt || "";
|
|
1543
|
+
el.hidden = !txt;
|
|
1544
|
+
}
|
|
1545
|
+
let FIRST_T = null;
|
|
1546
|
+
async function pull(days, force, quiet) {
|
|
1547
|
+
const seq = ++PULL_SEQ;
|
|
1548
|
+
const want = currentRepo;
|
|
1549
|
+
try {
|
|
1550
|
+
const res = await fetch("/api/data?days=" + days + "&repo=" + encodeURIComponent(want), { cache: "no-store" });
|
|
1551
|
+
if (res.status === 404) {
|
|
1552
|
+
// ?repo= 指向没绑定的仓:退回全部仓库重拉,别把上一个仓的数字留在屏上
|
|
1553
|
+
const info = await res.json().catch(() => ({}));
|
|
1554
|
+
if (seq !== PULL_SEQ) return null;
|
|
1555
|
+
currentRepo = "all";
|
|
1556
|
+
const u = new URL(location.href);
|
|
1557
|
+
u.searchParams.delete("repo");
|
|
1558
|
+
history.replaceState(null, "", u);
|
|
1559
|
+
document.getElementById("repo-name").textContent = "全部仓库";
|
|
1560
|
+
document.getElementById("repo-owner").textContent = "";
|
|
1561
|
+
setRepoLink(null);
|
|
1562
|
+
paintRepos();
|
|
1563
|
+
stickyNote = true;
|
|
1564
|
+
repoNote(info.error || "这个仓库不在监控列表,已切回全部仓库");
|
|
1565
|
+
return pull(days, true, quiet);
|
|
1566
|
+
}
|
|
679
1567
|
if (!res.ok) throw new Error(res.status);
|
|
680
1568
|
const json = await res.json();
|
|
681
|
-
|
|
1569
|
+
// 连点切仓时慢的那次不许盖掉新仓:只认最后一次请求
|
|
1570
|
+
if (seq !== PULL_SEQ) return null;
|
|
1571
|
+
// 还没绑定:整屏交给绑定页,别让空 KPI 在底下闪
|
|
1572
|
+
if (json.needsBinding) {
|
|
1573
|
+
// 服务端知道这台机器上有哪几条登录路可走,先问到再开绑定页
|
|
1574
|
+
if (!GATE.state) await gateBoot();
|
|
1575
|
+
if (!GATE.state) gateOpen({ bound: false, repos: 0 });
|
|
1576
|
+
return null;
|
|
1577
|
+
}
|
|
1578
|
+
// 冷启动时第一次同步还没落盘:显示进度并自己重试,别把空快照画成「没有流量」
|
|
1579
|
+
if (json.empty) {
|
|
1580
|
+
const st = await fetch("/api/progress", { cache: "no-store" }).then((r) => r.json()).catch(() => null);
|
|
1581
|
+
if (seq === PULL_SEQ && st && st.running) {
|
|
1582
|
+
repoNote("正在同步 " + st.done + "/" + st.total + " 个仓库,第一次要一会儿");
|
|
1583
|
+
clearTimeout(FIRST_T);
|
|
1584
|
+
FIRST_T = setTimeout(() => { if (seq === PULL_SEQ) pull(days, true, quiet); }, 2500);
|
|
1585
|
+
return null;
|
|
1586
|
+
}
|
|
1587
|
+
}
|
|
1588
|
+
if (!stickyNote) repoNote("");
|
|
682
1589
|
applyLive(json);
|
|
683
1590
|
if (!(days === LIVE.range.days)) LIVE.range.days = days;
|
|
684
1591
|
render(days);
|
|
685
|
-
loadSummary(days);
|
|
1592
|
+
if (!quiet) loadSummary(days);
|
|
686
1593
|
return json;
|
|
687
1594
|
} catch (e) {
|
|
688
|
-
|
|
1595
|
+
if (seq !== PULL_SEQ) return null;
|
|
1596
|
+
// 拉不到就明说屏上是旧数据,别让旧仓数字看起来像新仓的
|
|
1597
|
+
repoNote("没连上服务,屏上还是上一次的数据");
|
|
1598
|
+
// 旧数据就按旧范围重画,别挂上新范围的名字
|
|
1599
|
+
render(LIVE.range?.days || days);
|
|
689
1600
|
return null;
|
|
690
1601
|
}
|
|
691
1602
|
}
|
|
692
1603
|
|
|
693
|
-
|
|
1604
|
+
// 概览别停在旧状态:切回页面立刻拉一次,1 天窗口 60 秒,其它 5 分钟
|
|
1605
|
+
let SOFT_T = null;
|
|
1606
|
+
async function softRefresh() {
|
|
1607
|
+
clearTimeout(SOFT_T);
|
|
1608
|
+
if (!document.hidden) await pull(currentRange, true, true);
|
|
1609
|
+
SOFT_T = setTimeout(softRefresh, currentRange === 1 ? 60000 : 300000);
|
|
1610
|
+
}
|
|
1611
|
+
addEventListener("visibilitychange", () => { if (!document.hidden) softRefresh(); });
|
|
1612
|
+
|
|
1613
|
+
let SUM_SEQ = 0;
|
|
1614
|
+
async function loadSummary(days, tries = 0) {
|
|
1615
|
+
const seq = ++SUM_SEQ;
|
|
694
1616
|
try {
|
|
695
|
-
const res = await fetch("/api/summary?days=" + days, { cache: "no-store" });
|
|
696
|
-
if (!res.ok) return;
|
|
1617
|
+
const res = await fetch("/api/summary?days=" + days + "&repo=" + encodeURIComponent(currentRepo), { cache: "no-store" });
|
|
1618
|
+
if (!res.ok || seq !== SUM_SEQ) return;
|
|
697
1619
|
const data = await res.json();
|
|
1620
|
+
if (seq !== SUM_SEQ) return;
|
|
698
1621
|
const lines = data.lines || [];
|
|
699
1622
|
["sum-1", "sum-2", "sum-3"].forEach((id, i) => {
|
|
700
1623
|
const node = document.getElementById(id);
|
|
701
1624
|
if (!node) return;
|
|
702
1625
|
node.textContent = lines[i] || "";
|
|
1626
|
+
node.hidden = !lines[i];
|
|
703
1627
|
});
|
|
704
1628
|
const at = document.getElementById("sum-at");
|
|
705
1629
|
if (at) at.textContent = new Date().toLocaleString("zh-CN", { month: "2-digit", day: "2-digit", hour: "2-digit", minute: "2-digit" }).replace("/", "-");
|
|
706
|
-
|
|
1630
|
+
// 来源和回退原因都写出来,别让人以为这就是模型写的
|
|
1631
|
+
const why = { checked: "数字没对上", empty: "模型没返回内容" }[data.error] || (data.error ? "请求失败" : "");
|
|
1632
|
+
const srcEl = document.getElementById("sum-src");
|
|
1633
|
+
// 没有 error 的 template 是后台还在生成,不是失败,别写成「模板兜底」
|
|
1634
|
+
if (srcEl) srcEl.textContent = data.source === "ai" ? "" : data.source === "none" ? "未配置模型" : why ? "模板兜底 · " + why : "模型生成中…";
|
|
1635
|
+
const modelEl = document.getElementById("ai-model");
|
|
1636
|
+
if (modelEl) modelEl.textContent = data.source === "ai" ? (data.model || "") : "";
|
|
1637
|
+
// 摘要第一次生成要几十秒,先给模板,生成好了再换过来
|
|
1638
|
+
// 模型一次要几十秒、最坏两三分钟,间隔逐次拉长,最多等近三分钟
|
|
1639
|
+
if (data.source === "template" && tries < 9) setTimeout(() => loadSummary(days, tries + 1), Math.min(5000 * (tries + 1), 20000));
|
|
1640
|
+
} catch (e) {
|
|
1641
|
+
console.error("summary failed", e);
|
|
1642
|
+
}
|
|
707
1643
|
}
|
|
708
1644
|
|
|
709
1645
|
document.querySelector(".ask button").addEventListener("click", async () => {
|
|
710
1646
|
const input = document.querySelector(".ask input");
|
|
711
|
-
|
|
1647
|
+
const btn = document.querySelector(".ask button");
|
|
1648
|
+
const out = document.getElementById("ask-out");
|
|
1649
|
+
const q = input.value.trim();
|
|
1650
|
+
if (!q) return;
|
|
712
1651
|
input.disabled = true;
|
|
713
|
-
|
|
714
|
-
|
|
1652
|
+
btn.disabled = true;
|
|
1653
|
+
out.hidden = false;
|
|
1654
|
+
out.textContent = "在查…";
|
|
1655
|
+
const slow = setTimeout(() => { if (!out.hidden && /在查/.test(out.textContent)) out.textContent = "还在查…"; }, 8000);
|
|
1656
|
+
const ac = new AbortController();
|
|
1657
|
+
const to = setTimeout(() => ac.abort(), 32000);
|
|
1658
|
+
try {
|
|
1659
|
+
const r = await postJson("/api/ask", { question: q, repo: currentRepo, days: currentRange }, { signal: ac.signal });
|
|
1660
|
+
const d = await r.json();
|
|
1661
|
+
out.replaceChildren();
|
|
1662
|
+
out.appendChild(document.createTextNode(d.answer || "没答上来。"));
|
|
1663
|
+
for (const l of d.links || []) {
|
|
1664
|
+
out.appendChild(document.createElement("br"));
|
|
1665
|
+
const a = document.createElement("a");
|
|
1666
|
+
a.href = l.url;
|
|
1667
|
+
a.target = "_blank";
|
|
1668
|
+
a.rel = "noreferrer";
|
|
1669
|
+
a.textContent = l.label;
|
|
1670
|
+
out.appendChild(a);
|
|
1671
|
+
}
|
|
1672
|
+
if (d.source === "ai") input.value = "";
|
|
1673
|
+
} catch (e) {
|
|
1674
|
+
out.textContent = e && e.name === "AbortError" ? "等太久了,再问一次。" : "连不上本地服务。";
|
|
1675
|
+
} finally {
|
|
1676
|
+
clearTimeout(to);
|
|
1677
|
+
clearTimeout(slow);
|
|
1678
|
+
input.disabled = false;
|
|
1679
|
+
btn.disabled = false;
|
|
1680
|
+
}
|
|
715
1681
|
});
|
|
716
1682
|
|
|
717
1683
|
|
|
718
|
-
|
|
1684
|
+
const segInit = document.getElementById("seg");
|
|
1685
|
+
[...segInit.children].forEach((b) => b.classList.toggle("on", +b.dataset.r === currentRange));
|
|
1686
|
+
// 「刷新」周期跟着后端启动参数走,页面上不写死一个时间
|
|
1687
|
+
async function loadInterval() {
|
|
1688
|
+
try {
|
|
1689
|
+
const r = await fetch("/api/progress");
|
|
1690
|
+
const st = await r.json();
|
|
1691
|
+
const el = document.getElementById("r-interval");
|
|
1692
|
+
if (el && st.intervalHours) el.textContent = `每 ${st.intervalHours} 小时`;
|
|
1693
|
+
const row = document.getElementById("r-contrib-row");
|
|
1694
|
+
const cb = document.getElementById("r-contrib");
|
|
1695
|
+
if (row && cb && st.contribMinutes > 0) {
|
|
1696
|
+
cb.textContent = `每 ${st.contribMinutes} 分钟`;
|
|
1697
|
+
row.hidden = false;
|
|
1698
|
+
}
|
|
1699
|
+
} catch { /* 拿不到就留着占位 */ }
|
|
1700
|
+
}
|
|
1701
|
+
|
|
1702
|
+
// ---- 绑定账号 ----
|
|
1703
|
+
// 只有一条主路:在浏览器里登录 GitHub 确认一次,绑的就是点确认的那个人。
|
|
1704
|
+
// 不读这台机器已有的登录态,别人打开不会绑到当前电脑的账号上。
|
|
1705
|
+
// 没有 git 命令行时退回粘贴访问令牌。
|
|
1706
|
+
const GATE = { on: false, state: null, timer: null };
|
|
1707
|
+
function gateSay(txt) { const el = document.getElementById("gate-out"); if (el) el.textContent = txt || ""; }
|
|
1708
|
+
function gateOpen(state) {
|
|
1709
|
+
GATE.on = true;
|
|
1710
|
+
GATE.state = state;
|
|
1711
|
+
document.getElementById("gate").classList.add("on");
|
|
1712
|
+
document.body.classList.add("gated");
|
|
1713
|
+
const main = document.getElementById("gate-main");
|
|
1714
|
+
const lead = document.getElementById("gate-lead");
|
|
1715
|
+
main.textContent = "";
|
|
1716
|
+
const browser = state.loginMode === "device" || state.loginMode === "gh";
|
|
1717
|
+
if (browser) {
|
|
1718
|
+
lead.textContent = "登录你的账号,数据只存在这台电脑上。";
|
|
1719
|
+
} else {
|
|
1720
|
+
lead.textContent = "粘贴访问令牌就能绑上。";
|
|
1721
|
+
}
|
|
1722
|
+
// 令牌输入是兜底,不是可选项:浏览器这条路走不通时它就顶上来,别把它藏掉
|
|
1723
|
+
const alt = document.querySelector(".gate-alt");
|
|
1724
|
+
if (alt) alt.classList.toggle("sep-top", browser);
|
|
1725
|
+
const altLead = document.getElementById("gate-alt-lead");
|
|
1726
|
+
if (altLead) altLead.hidden = !browser;
|
|
1727
|
+
const btn = document.createElement("button");
|
|
1728
|
+
btn.className = "primary";
|
|
1729
|
+
btn.id = "gate-go";
|
|
1730
|
+
btn.textContent = browser ? "用 GitHub 登录" : "绑定访问令牌";
|
|
1731
|
+
btn.onclick = () => (browser ? gateLogin(btn) : gatePaste(btn));
|
|
1732
|
+
main.appendChild(btn);
|
|
1733
|
+
}
|
|
1734
|
+
function gateClose() {
|
|
1735
|
+
GATE.on = false;
|
|
1736
|
+
clearInterval(GATE.timer);
|
|
1737
|
+
document.getElementById("gate").classList.remove("on");
|
|
1738
|
+
document.body.classList.remove("gated");
|
|
1739
|
+
}
|
|
1740
|
+
// 刚绑上时快照还是空的,第一次同步要跑好几十秒;这段时间说清楚在等什么,
|
|
1741
|
+
// 别让「没连上服务」这种失败文案盖在一个其实正常的首次同步上
|
|
1742
|
+
async function gateWaitSync() {
|
|
1743
|
+
for (let i = 0; i < 90; i++) {
|
|
1744
|
+
const st = await fetch("/api/progress", { cache: "no-store" }).then((r) => r.json()).catch(() => null);
|
|
1745
|
+
if (!st || !st.running) return true;
|
|
1746
|
+
repoNote(`正在同步 ${st.done}/${st.total} 个仓库,第一次要一会儿`);
|
|
1747
|
+
await new Promise((r) => setTimeout(r, 2000));
|
|
1748
|
+
}
|
|
1749
|
+
return false;
|
|
1750
|
+
}
|
|
1751
|
+
async function gateDone(json) {
|
|
1752
|
+
gateClose();
|
|
1753
|
+
gateSay("");
|
|
1754
|
+
await loadRepos();
|
|
1755
|
+
repoNote("已绑定 " + (json.login || "") + "," + json.repos + " 个仓库,正在同步");
|
|
1756
|
+
await gateWaitSync();
|
|
1757
|
+
await pull(currentRange, true, true);
|
|
1758
|
+
}
|
|
1759
|
+
async function gatePost(url, body) {
|
|
1760
|
+
const res = await fetch(url, { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify(body || {}) });
|
|
1761
|
+
const json = await res.json().catch(() => ({}));
|
|
1762
|
+
if (!res.ok) throw new Error(json.error || "没成功(" + res.status + ")");
|
|
1763
|
+
return json;
|
|
1764
|
+
}
|
|
1765
|
+
async function gateLogin(btn) {
|
|
1766
|
+
btn.disabled = true;
|
|
1767
|
+
gateSay("正在打开 GitHub…");
|
|
1768
|
+
let d;
|
|
1769
|
+
try {
|
|
1770
|
+
d = await gatePost("/api/auth/login");
|
|
1771
|
+
} catch (e) {
|
|
1772
|
+
gateSay(e.message);
|
|
1773
|
+
btn.disabled = false;
|
|
1774
|
+
return;
|
|
1775
|
+
}
|
|
1776
|
+
gateSay("");
|
|
1777
|
+
// 码、确认入口、进度都放在按钮下面,和这一步贴着,不要挂到卡片底部
|
|
1778
|
+
const box = document.createElement("div");
|
|
1779
|
+
box.style.cssText = "margin-top:10px;line-height:1.7";
|
|
1780
|
+
if (d.userCode) {
|
|
1781
|
+
const code = document.createElement("p");
|
|
1782
|
+
code.className = "gate-code";
|
|
1783
|
+
code.id = "gate-veri";
|
|
1784
|
+
code.style.margin = "0";
|
|
1785
|
+
code.textContent = d.userCode;
|
|
1786
|
+
box.appendChild(code);
|
|
1787
|
+
}
|
|
1788
|
+
if (d.verifyUrl) {
|
|
1789
|
+
const p = document.createElement("p");
|
|
1790
|
+
p.style.margin = "0";
|
|
1791
|
+
const a = document.createElement("a");
|
|
1792
|
+
a.href = d.verifyUrl;
|
|
1793
|
+
a.target = "_blank";
|
|
1794
|
+
a.rel = "noopener";
|
|
1795
|
+
a.textContent = "在 GitHub 里确认";
|
|
1796
|
+
p.appendChild(a);
|
|
1797
|
+
box.appendChild(p);
|
|
1798
|
+
// 能在点击里直接开更好;被拦了还有上面那个链接
|
|
1799
|
+
window.open(d.verifyUrl, "_blank", "noopener");
|
|
1800
|
+
}
|
|
1801
|
+
const wait = document.createElement("p");
|
|
1802
|
+
wait.style.cssText = "margin:0;font-size:12px;color:var(--label-secondary)";
|
|
1803
|
+
wait.textContent = d.userCode ? "输入这个码后确认,会自动绑上" : "确认后会自动绑上";
|
|
1804
|
+
box.appendChild(wait);
|
|
1805
|
+
document.getElementById("gate-main").appendChild(box);
|
|
1806
|
+
clearInterval(GATE.timer);
|
|
1807
|
+
GATE.timer = setInterval(async () => {
|
|
1808
|
+
try {
|
|
1809
|
+
const out = await gatePost("/api/auth/login/poll", { mode: d.mode, id: d.id, deviceCode: d.deviceCode });
|
|
1810
|
+
if (out.status === "ok") {
|
|
1811
|
+
clearInterval(GATE.timer);
|
|
1812
|
+
gateSay("已绑定 " + out.login + "," + out.repos + " 个仓库");
|
|
1813
|
+
await gateDone(out);
|
|
1814
|
+
} else if (out.status !== "pending") {
|
|
1815
|
+
clearInterval(GATE.timer);
|
|
1816
|
+
gateSay(out.message || "没绑上,再点一次");
|
|
1817
|
+
btn.disabled = false;
|
|
1818
|
+
}
|
|
1819
|
+
} catch (e) {
|
|
1820
|
+
clearInterval(GATE.timer);
|
|
1821
|
+
gateSay(e.message);
|
|
1822
|
+
btn.disabled = false;
|
|
1823
|
+
}
|
|
1824
|
+
}, Math.max(2, d.interval || 3) * 1000);
|
|
1825
|
+
}
|
|
1826
|
+
async function gatePaste(btn) {
|
|
1827
|
+
const token = document.getElementById("gate-token").value.trim();
|
|
1828
|
+
if (!token) {
|
|
1829
|
+
gateSay("先粘贴访问令牌");
|
|
1830
|
+
document.getElementById("gate-token").focus();
|
|
1831
|
+
return;
|
|
1832
|
+
}
|
|
1833
|
+
btn.disabled = true;
|
|
1834
|
+
gateSay("正在核对…");
|
|
1835
|
+
try {
|
|
1836
|
+
const out = await gatePost("/api/auth", { token });
|
|
1837
|
+
gateSay("已绑定 " + out.login + "," + out.repos + " 个仓库");
|
|
1838
|
+
await gateDone(out);
|
|
1839
|
+
} catch (e) {
|
|
1840
|
+
gateSay(e.message);
|
|
1841
|
+
btn.disabled = false;
|
|
1842
|
+
}
|
|
1843
|
+
}
|
|
1844
|
+
document.getElementById("gate-new").href =
|
|
1845
|
+
"https://github.com/settings/tokens/new?scopes=repo,read:user&description=github-overview";
|
|
1846
|
+
document.getElementById("gate-token").addEventListener("keydown", (e) => {
|
|
1847
|
+
if (e.key === "Enter") { const b = document.getElementById("gate-go"); if (b && !b.disabled) b.click(); }
|
|
1848
|
+
});
|
|
1849
|
+
async function gateBoot() {
|
|
1850
|
+
try {
|
|
1851
|
+
const st = await fetch("/api/auth", { cache: "no-store" }).then((r) => r.json());
|
|
1852
|
+
GATE.state = st;
|
|
1853
|
+
if (!st.bound || !st.repos) gateOpen(st);
|
|
1854
|
+
} catch { /* 服务没起来时别挡着页面的错误提示 */ }
|
|
1855
|
+
}
|
|
1856
|
+
|
|
1857
|
+
loadRepos().then(() => { pull(currentRange); loadInterval(); });
|
|
1858
|
+
gateBoot();
|
|
1859
|
+
softRefresh();
|
|
719
1860
|
let rzT;
|
|
720
1861
|
addEventListener("resize", () => { clearTimeout(rzT); rzT = setTimeout(() => render(currentRange), 160); });
|
|
721
1862
|
</script>
|