github-overview 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +63 -2
- package/bin/cli.mjs +89 -0
- package/docs/screenshot-dark.png +0 -0
- package/docs/screenshot-light.png +0 -0
- package/package.json +34 -4
- package/public/index.html +723 -0
- package/src/config.mjs +41 -0
- package/src/github.mjs +113 -0
- package/src/npm.mjs +67 -0
- package/src/server.mjs +158 -0
- package/src/store.mjs +71 -0
- package/src/summary.mjs +70 -0
|
@@ -0,0 +1,723 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="zh-CN" data-theme="dark">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8">
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
6
|
+
<title>github-overview</title>
|
|
7
|
+
<style>
|
|
8
|
+
:root[data-theme="dark"] {
|
|
9
|
+
--bg-base: #0f1115;
|
|
10
|
+
--bg-layer-1: #16191f;
|
|
11
|
+
--bg-layer-2: #1d2128;
|
|
12
|
+
--border-l1: #262b34;
|
|
13
|
+
--border-l2: #3a4250;
|
|
14
|
+
--label-primary: #e6e8ec;
|
|
15
|
+
--label-secondary: #98a1b0;
|
|
16
|
+
--brand: #4f8cff;
|
|
17
|
+
--machine: #7b8698;
|
|
18
|
+
--event: #d9a441;
|
|
19
|
+
--success: #3fb950;
|
|
20
|
+
--shadow: 0 8px 28px rgba(0,0,0,.45);
|
|
21
|
+
}
|
|
22
|
+
:root[data-theme="light"] {
|
|
23
|
+
--bg-base: #fbfbfc;
|
|
24
|
+
--bg-layer-1: #ffffff;
|
|
25
|
+
--bg-layer-2: #f0f2f6;
|
|
26
|
+
--border-l1: #e3e6ec;
|
|
27
|
+
--border-l2: #cdd2db;
|
|
28
|
+
--label-primary: #12161d;
|
|
29
|
+
--label-secondary: #5c6472;
|
|
30
|
+
--brand: #2b62d9;
|
|
31
|
+
--machine: #79838f;
|
|
32
|
+
--event: #a8761b;
|
|
33
|
+
--success: #1a7f37;
|
|
34
|
+
--shadow: 0 8px 28px rgba(16,24,40,.12);
|
|
35
|
+
}
|
|
36
|
+
* { box-sizing: border-box; }
|
|
37
|
+
html, body { margin: 0; background: var(--bg-base); }
|
|
38
|
+
body {
|
|
39
|
+
color: var(--label-primary);
|
|
40
|
+
font: 16px/1.65 -apple-system, "SF Pro Text", "PingFang SC", system-ui, sans-serif;
|
|
41
|
+
font-variant-numeric: tabular-nums;
|
|
42
|
+
-webkit-font-smoothing: antialiased;
|
|
43
|
+
transition: background .15s ease;
|
|
44
|
+
}
|
|
45
|
+
.wrap { max-width: 1150px; margin: 0 auto; padding: 22px 28px 36px; }
|
|
46
|
+
|
|
47
|
+
button { font: inherit; color: var(--label-primary); background: transparent; cursor: pointer; white-space: nowrap;
|
|
48
|
+
height: 28px; padding: 0 10px; border: 1px solid var(--border-l2); border-radius: 8px; }
|
|
49
|
+
button:hover { background: var(--bg-layer-2); }
|
|
50
|
+
button svg { display: block; }
|
|
51
|
+
.icon-btn { width: 28px; padding: 0; display: inline-flex; align-items: center; justify-content: center; border-color: transparent; color: var(--label-secondary); }
|
|
52
|
+
.icon-btn svg { width: 16px; height: 16px; }
|
|
53
|
+
.icon-btn:hover { color: var(--label-primary); border: 1px solid var(--border-l2); }
|
|
54
|
+
.ghost { border-color: transparent; color: var(--label-secondary); }
|
|
55
|
+
.pill { display: inline-flex; align-items: center; gap: 6px; height: 24px; padding: 0 9px; white-space: nowrap;
|
|
56
|
+
border: 1px solid var(--border-l1); border-radius: 999px; color: var(--label-secondary); font-size: 12px; }
|
|
57
|
+
.dot { width: 6px; height: 6px; border-radius: 50%; background: var(--success); }
|
|
58
|
+
|
|
59
|
+
header { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; row-gap: 10px; padding-bottom: 14px; border-bottom: 1px solid var(--border-l1); }
|
|
60
|
+
.brand { font-size: 12px; color: var(--label-secondary); letter-spacing: .01em; white-space: nowrap; }
|
|
61
|
+
.sep { width: 1px; height: 14px; background: var(--border-l1); }
|
|
62
|
+
.repo { font-size: 16px; font-weight: 600; white-space: nowrap; }
|
|
63
|
+
.repo span { color: var(--label-secondary); font-weight: 400; }
|
|
64
|
+
.caret { color: var(--label-secondary); font-weight: 400; }
|
|
65
|
+
.spacer { flex: 1; }
|
|
66
|
+
.seg { display: inline-flex; border: 1px solid var(--border-l2); border-radius: 8px; overflow: hidden; height: 28px; }
|
|
67
|
+
.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); }
|
|
69
|
+
|
|
70
|
+
.kpis { display: grid; grid-template-columns: repeat(5, 1fr); gap: 4px 28px; padding: 18px 0 2px; }
|
|
71
|
+
.kpi-label { font-size: 12px; color: var(--label-secondary); }
|
|
72
|
+
.kpi-value { font-size: 24px; font-weight: 600; letter-spacing: -.02em; line-height: 1.35; }
|
|
73
|
+
.kpi-sub { font-size: 12px; color: var(--label-secondary); }
|
|
74
|
+
.up { color: var(--success); }
|
|
75
|
+
|
|
76
|
+
.cols { display: grid; grid-template-columns: minmax(0, 1fr) 318px; min-width: 0; gap: 30px; margin-top: 20px; align-items: start; }
|
|
77
|
+
h2 { font-size: 16px; font-weight: 600; margin: 0; }
|
|
78
|
+
.sec + .sec { margin-top: 24px; padding-top: 18px; border-top: 1px solid var(--border-l1); }
|
|
79
|
+
.head { display: flex; align-items: center; gap: 10px; min-height: 24px; }
|
|
80
|
+
.note { font-size: 12px; color: var(--label-secondary); }
|
|
81
|
+
.key { font-size: 12px; color: var(--label-secondary); display: inline-flex; align-items: center; gap: 5px; }
|
|
82
|
+
.key i.dash { background: var(--event); width: 2px; height: 11px; opacity: .55; }
|
|
83
|
+
.key i { width: 8px; height: 8px; border-radius: 2px; }
|
|
84
|
+
|
|
85
|
+
.chart { margin-top: 4px; }
|
|
86
|
+
.chart svg { display: block; width: 100%; max-width: 100%; height: auto; overflow: visible; }
|
|
87
|
+
.tick-label { fill: var(--label-secondary); font-size: 12px; }
|
|
88
|
+
.val-label { fill: var(--label-primary); font-size: 12px; }
|
|
89
|
+
|
|
90
|
+
.srcs { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 6px; margin-left: auto; }
|
|
91
|
+
.src { display: inline-flex; align-items: center; gap: 6px; height: 22px; padding: 0 9px; font-size: 12px;
|
|
92
|
+
border: 1px solid var(--border-l1); border-radius: 999px; color: var(--label-secondary); }
|
|
93
|
+
.src.on { border: 1px solid var(--border-l2); background: var(--bg-layer-2); color: var(--label-primary); }
|
|
94
|
+
.src.off { border-style: dashed; color: var(--label-secondary); opacity: .65; }
|
|
95
|
+
|
|
96
|
+
.split { display: grid; grid-template-columns: 168px 1fr; gap: 32px; align-items: start; margin-top: 12px; }
|
|
97
|
+
.donut { display: flex; flex-direction: column; gap: 10px; }
|
|
98
|
+
.donut svg { width: 104px; height: 104px; margin: 0 auto; }
|
|
99
|
+
.donut-legend { display: flex; flex-direction: column; gap: 4px; font-size: 12px; }
|
|
100
|
+
.donut-legend div { display: flex; align-items: center; gap: 6px; justify-content: space-between; }
|
|
101
|
+
.donut-legend span { display: inline-flex; align-items: center; gap: 6px; color: var(--label-secondary); white-space: nowrap; }
|
|
102
|
+
.donut-legend i { width: 8px; height: 8px; border-radius: 2px; flex: none; }
|
|
103
|
+
.donut-legend b { font-weight: 500; }
|
|
104
|
+
.ranks { display: grid; gap: 16px; }
|
|
105
|
+
.ranks h3 { margin: 0 0 8px; font-size: 12px; font-weight: 500; color: var(--label-secondary); }
|
|
106
|
+
.ranks ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 7px; }
|
|
107
|
+
.ranks li { display: grid; grid-template-columns: 104px 1fr 48px; align-items: center; gap: 10px; font-size: 16px; }
|
|
108
|
+
.ranks .k { color: var(--label-secondary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
109
|
+
.ranks .track { height: 6px; border-radius: 2px; background: var(--bg-layer-2); overflow: hidden; }
|
|
110
|
+
.ranks .track i { display: block; height: 100%; background: var(--brand); border-radius: 2px; }
|
|
111
|
+
.ranks .v { text-align: right; font-variant-numeric: tabular-nums; }
|
|
112
|
+
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 20px; margin-top: 12px; }
|
|
113
|
+
.stats div { display: flex; flex-direction: column; gap: 2px; }
|
|
114
|
+
.stats span { font-size: 12px; color: var(--label-secondary); }
|
|
115
|
+
.stats b { font-size: 24px; font-weight: 600; font-variant-numeric: tabular-nums; }
|
|
116
|
+
.stats em { font-size: 12px; font-style: normal; color: var(--label-secondary); }
|
|
117
|
+
.note { margin: 12px 0 0; font-size: 12px; line-height: 1.65; color: var(--label-secondary); }
|
|
118
|
+
|
|
119
|
+
table { width: 100%; border-collapse: collapse; }
|
|
120
|
+
th { font-size: 12px; font-weight: 400; color: var(--label-secondary); text-align: right; padding: 2px 0 4px; }
|
|
121
|
+
th:first-child { text-align: left; }
|
|
122
|
+
td { padding: 6px 0; border-top: 1px solid var(--border-l1); text-align: right; color: var(--label-secondary); font-size: 12px; }
|
|
123
|
+
td:first-child { text-align: left; color: var(--label-primary); font-size: 16px; }
|
|
124
|
+
|
|
125
|
+
aside { position: sticky; top: 20px; display: flex; flex-direction: column; gap: 14px; }
|
|
126
|
+
.panel { background: var(--bg-layer-1); border: 1px solid var(--border-l1); border-radius: 12px; padding: 14px 15px; }
|
|
127
|
+
.panel h3 { margin: 0 0 8px; font-size: 16px; font-weight: 600; display: flex; justify-content: space-between; align-items: baseline; }
|
|
128
|
+
.panel h3 span { font-size: 12px; font-weight: 400; color: var(--label-secondary); }
|
|
129
|
+
.ai p { margin: 0 0 7px; font-size: 16px; line-height: 1.7; }
|
|
130
|
+
.ai p:last-of-type { margin-bottom: 10px; }
|
|
131
|
+
.ai b { font-weight: 500; }
|
|
132
|
+
.ask { display: flex; gap: 6px; }
|
|
133
|
+
.ask input, .cfg input { flex: 1; height: 28px; background: var(--bg-base); border: 1px solid var(--border-l1); border-radius: 8px;
|
|
134
|
+
color: var(--label-primary); font: inherit; padding: 0 9px; min-width: 0; }
|
|
135
|
+
.ask input::placeholder, .cfg input::placeholder { color: var(--label-secondary); }
|
|
136
|
+
.cfg-row { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--label-secondary); margin-top: 8px; }
|
|
137
|
+
.cfg-row label { width: 56px; flex: none; }
|
|
138
|
+
.cfg { display: none; margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--border-l1); }
|
|
139
|
+
.cfg.open { display: block; }
|
|
140
|
+
.foot { display: flex; justify-content: space-between; font-size: 12px; color: var(--label-secondary); margin-top: 12px; }
|
|
141
|
+
.link { color: var(--label-secondary); border: 0; height: auto; padding: 0; background: none; text-decoration: underline; text-underline-offset: 2px; }
|
|
142
|
+
.link:hover { color: var(--label-primary); background: none; }
|
|
143
|
+
.rowline { display: flex; justify-content: space-between; align-items: center; font-size: 12px; color: var(--label-secondary); }
|
|
144
|
+
.rowline b { font-weight: 400; color: var(--label-primary); }
|
|
145
|
+
.rowline + .rowline { margin-top: 6px; }
|
|
146
|
+
.mini { height: 26px; padding: 0 9px; font-size: 12px; }
|
|
147
|
+
|
|
148
|
+
@media (max-width: 1020px) {
|
|
149
|
+
.cols { grid-template-columns: minmax(0, 1fr); gap: 22px; }
|
|
150
|
+
main { min-width: 0; }
|
|
151
|
+
.seg { flex: 1 1 100%; }
|
|
152
|
+
.seg button { flex: 1; padding: 0 6px; }
|
|
153
|
+
aside { position: static; }
|
|
154
|
+
.brand, .sep { display: none; }
|
|
155
|
+
}
|
|
156
|
+
@media (max-width: 980px) {
|
|
157
|
+
.kpis { grid-template-columns: repeat(2, 1fr); row-gap: 14px; }
|
|
158
|
+
.kpi:nth-child(odd) { border-left: none; padding-left: 0; }
|
|
159
|
+
.kpi:nth-child(even) { border-left: 1px solid var(--border-l1); padding-left: 14px; }
|
|
160
|
+
}
|
|
161
|
+
@media (max-width: 620px) {
|
|
162
|
+
.wrap { padding: 14px 16px 28px; }
|
|
163
|
+
header { flex-wrap: wrap; row-gap: 8px; }
|
|
164
|
+
.repo { flex: 1 0 100%; order: -1; }
|
|
165
|
+
.spacer { display: none; }
|
|
166
|
+
.seg { margin-left: auto; }
|
|
167
|
+
.kpi-value { font-size: 24px; }
|
|
168
|
+
.kpi:last-child { grid-column: 1 / -1; border-left: none; padding-left: 0; }
|
|
169
|
+
.split { grid-template-columns: 1fr; gap: 20px; }
|
|
170
|
+
.donut { flex-direction: row; align-items: center; gap: 16px; }
|
|
171
|
+
.donut svg { margin: 0; flex: none; }
|
|
172
|
+
.donut-legend { flex: 1; min-width: 0; }
|
|
173
|
+
.donut-legend span { overflow: hidden; text-overflow: ellipsis; }
|
|
174
|
+
.stats { grid-template-columns: 1fr 1fr; gap: 14px; }
|
|
175
|
+
.stats b { font-size: 18px; }
|
|
176
|
+
thead th:nth-child(3), tbody td:nth-child(3) { display: none; }
|
|
177
|
+
}
|
|
178
|
+
</style>
|
|
179
|
+
</head>
|
|
180
|
+
<body>
|
|
181
|
+
<div class="wrap">
|
|
182
|
+
|
|
183
|
+
<header>
|
|
184
|
+
<span class="brand">github-overview</span>
|
|
185
|
+
<span class="sep"></span>
|
|
186
|
+
<div class="repo"><span id="repo-owner">owner /</span> <span id="repo-name">repo</span> <span class="caret">▾</span></div>
|
|
187
|
+
<div class="spacer"></div>
|
|
188
|
+
<div class="seg" id="seg">
|
|
189
|
+
<button data-r="7" class="on">7 天</button>
|
|
190
|
+
<button data-r="30">30 天</button>
|
|
191
|
+
<button data-r="90">90 天</button>
|
|
192
|
+
</div>
|
|
193
|
+
<button class="icon-btn" id="theme" title="切换主题">
|
|
194
|
+
<svg id="ico-sun" width="15" height="15" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.4" stroke-linecap="round"><circle cx="8" cy="8" r="3.1"/><path d="M8 1.2v1.6M8 13.2v1.6M1.2 8h1.6M13.2 8h1.6M3.2 3.2l1.1 1.1M11.7 11.7l1.1 1.1M12.8 3.2l-1.1 1.1M4.3 11.7l-1.1 1.1"/></svg>
|
|
195
|
+
<svg id="ico-moon" width="15" height="15" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.4" stroke-linejoin="round" style="display:none"><path d="M13.5 9.6A5.8 5.8 0 0 1 6.4 2.5a5.9 5.9 0 1 0 7.1 7.1Z"/></svg>
|
|
196
|
+
</button>
|
|
197
|
+
<button id="refresh">
|
|
198
|
+
<svg width="12" height="12" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.5" style="vertical-align:-2px;margin-right:4px;display:inline"><path d="M13.5 8a5.5 5.5 0 1 1-1.6-3.9"/><path d="M13.5 2.5V5H11"/></svg>刷新
|
|
199
|
+
</button>
|
|
200
|
+
</header>
|
|
201
|
+
|
|
202
|
+
<section class="kpis">
|
|
203
|
+
<div class="kpi">
|
|
204
|
+
<div class="kpi-label">访客</div>
|
|
205
|
+
<div class="kpi-value" id="k-uniq">341</div>
|
|
206
|
+
<div class="kpi-sub" id="k-views-sub">424 次浏览</div>
|
|
207
|
+
</div>
|
|
208
|
+
<div class="kpi">
|
|
209
|
+
<div class="kpi-label">外部贡献</div>
|
|
210
|
+
<div class="kpi-value" id="k-contrib">2</div>
|
|
211
|
+
<div class="kpi-sub" id="k-contrib-sub">1 issue、1 PR</div>
|
|
212
|
+
</div>
|
|
213
|
+
<div class="kpi">
|
|
214
|
+
<div class="kpi-label">npm 下载</div>
|
|
215
|
+
<div class="kpi-value" id="k-npm">10,527</div>
|
|
216
|
+
<div class="kpi-sub">周汇总</div>
|
|
217
|
+
</div>
|
|
218
|
+
<div class="kpi">
|
|
219
|
+
<div class="kpi-label">stars</div>
|
|
220
|
+
<div class="kpi-value" id="k-stars">9</div>
|
|
221
|
+
<div class="kpi-sub" id="k-forks">2 forks</div>
|
|
222
|
+
</div>
|
|
223
|
+
<div class="kpi">
|
|
224
|
+
<div class="kpi-label">发版</div>
|
|
225
|
+
<div class="kpi-value" id="k-rel">4</div>
|
|
226
|
+
<div class="kpi-sub" id="k-rel-sub">0.6.11 → 0.6.14</div>
|
|
227
|
+
</div>
|
|
228
|
+
</section>
|
|
229
|
+
|
|
230
|
+
<div class="cols">
|
|
231
|
+
<main>
|
|
232
|
+
<section class="sec">
|
|
233
|
+
<div class="head">
|
|
234
|
+
<h2>流量</h2>
|
|
235
|
+
<span class="note" id="range-note">10-26 → 11-01</span>
|
|
236
|
+
<div class="spacer"></div>
|
|
237
|
+
<span class="key"><i style="background:var(--brand)"></i>浏览</span>
|
|
238
|
+
<span class="key"><i style="background:var(--machine)"></i>克隆</span>
|
|
239
|
+
<span class="key"><i class="dash"></i>发版</span>
|
|
240
|
+
</div>
|
|
241
|
+
<div class="chart" id="c-flow"></div>
|
|
242
|
+
</section>
|
|
243
|
+
|
|
244
|
+
<section class="sec">
|
|
245
|
+
<div class="head">
|
|
246
|
+
<h2>下载</h2>
|
|
247
|
+
<div class="srcs">
|
|
248
|
+
<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
|
+
</div>
|
|
253
|
+
</div>
|
|
254
|
+
<div class="chart" id="c-npm"></div>
|
|
255
|
+
</section>
|
|
256
|
+
|
|
257
|
+
<section class="sec">
|
|
258
|
+
<div class="head"><h2>贡献</h2></div>
|
|
259
|
+
<div class="stats">
|
|
260
|
+
<div><span>issue</span><b id="s-issues">1 个</b><em id="s-issues-sub">已关闭</em></div>
|
|
261
|
+
<div><span>PR</span><b id="s-prs">1 个</b><em id="s-prs-sub">已合并,+118 −5</em></div>
|
|
262
|
+
<div><span>安全告警</span><b id="s-alerts">未开启</b><em id="s-alerts-sub">无数据</em></div>
|
|
263
|
+
</div>
|
|
264
|
+
</section>
|
|
265
|
+
|
|
266
|
+
<section class="sec">
|
|
267
|
+
<div class="head"><h2>构成</h2></div>
|
|
268
|
+
<div class="split">
|
|
269
|
+
<div class="donut" id="donut"></div>
|
|
270
|
+
<div class="ranks" id="ranks"></div>
|
|
271
|
+
</div>
|
|
272
|
+
</section>
|
|
273
|
+
|
|
274
|
+
</main>
|
|
275
|
+
|
|
276
|
+
<aside>
|
|
277
|
+
<div class="panel ai">
|
|
278
|
+
<h3>摘要<span id="sum-at">11-02 09:14</span></h3>
|
|
279
|
+
<p id="sum-1">近 7 天约 <b>341</b> 人来看过仓库。</p>
|
|
280
|
+
<p id="sum-2">外部提了 1 个 issue、1 个 PR。</p>
|
|
281
|
+
<p id="sum-3">Star 涨到 <b>9</b>,npm 周下载 1.05 万。</p>
|
|
282
|
+
|
|
283
|
+
<div class="ask">
|
|
284
|
+
<input placeholder="问这个仓库">
|
|
285
|
+
<button class="mini">问</button>
|
|
286
|
+
</div>
|
|
287
|
+
<div class="foot"><span>deepseek-v4</span><button class="link" id="cfg-toggle">配置</button></div>
|
|
288
|
+
|
|
289
|
+
<div class="cfg" id="cfg">
|
|
290
|
+
<div class="cfg-row"><label>Base URL</label><input value="https://api.deepseek.com/v1" spellcheck="false"></div>
|
|
291
|
+
<div class="cfg-row"><label>API Key</label><input type="password" placeholder="sk-…" spellcheck="false"></div>
|
|
292
|
+
<div class="cfg-row" style="justify-content:flex-end;gap:6px">
|
|
293
|
+
<button class="mini ghost">取消</button>
|
|
294
|
+
<button class="mini" id="cfg-save">保存</button>
|
|
295
|
+
</div>
|
|
296
|
+
</div>
|
|
297
|
+
</div>
|
|
298
|
+
|
|
299
|
+
<div class="panel">
|
|
300
|
+
<h3>刷新<span>每天 21:00</span></h3>
|
|
301
|
+
<div class="rowline"><span>上次</span><b id="r-last">3 分钟前</b></div>
|
|
302
|
+
<div class="rowline"><span>已存</span><b id="r-days">8 天</b></div>
|
|
303
|
+
<div class="rowline" style="margin-top:10px"><span>数据源</span><b>GitHub · npm</b></div>
|
|
304
|
+
</div>
|
|
305
|
+
</aside>
|
|
306
|
+
</div>
|
|
307
|
+
</div>
|
|
308
|
+
|
|
309
|
+
<script>
|
|
310
|
+
let DATA = [
|
|
311
|
+
{ d: "10-26", v: 1, u: 1, c: 81, cu: 34, n: 1240 },
|
|
312
|
+
{ d: "10-27", v: 3, u: 3, c: 381, cu: 135, n: 4348 },
|
|
313
|
+
{ d: "10-28", v: 0, u: 0, c: 232, cu: 78, n: 3742 },
|
|
314
|
+
{ d: "10-29", v: 41, u: 39, c: 137, cu: 49, n: 1197 },
|
|
315
|
+
{ d: "10-30", v: 101, u: 96, c: 72, cu: 28, n: null },
|
|
316
|
+
{ d: "10-31", v: 175, u: 127, c: 40, cu: 22, n: null },
|
|
317
|
+
{ d: "11-01", v: 103, u: 90, c: 39, cu: 21, n: null }
|
|
318
|
+
];
|
|
319
|
+
let RELEASE = { "10-29": 1, "10-30": 1, "10-31": 1, "11-01": 1 };
|
|
320
|
+
const NS = "http://www.w3.org/2000/svg";
|
|
321
|
+
const fmt = v => new Intl.NumberFormat("en").format(Math.round(v));
|
|
322
|
+
|
|
323
|
+
const theme = () => document.documentElement.dataset.theme;
|
|
324
|
+
function C() {
|
|
325
|
+
const cs = getComputedStyle(document.documentElement);
|
|
326
|
+
const g = n => cs.getPropertyValue(n).trim();
|
|
327
|
+
return { grid: theme() === "dark" ? "#22262e" : "#ebedf1", zero: theme() === "dark" ? "#191c22" : "#f4f5f8",
|
|
328
|
+
human: g("--brand"), machine: g("--machine"), event: g("--event") };
|
|
329
|
+
}
|
|
330
|
+
function el(tag, attrs, text) {
|
|
331
|
+
const n = document.createElementNS(NS, tag);
|
|
332
|
+
for (const k in attrs) n.setAttribute(k, attrs[k]);
|
|
333
|
+
if (text != null) n.textContent = text;
|
|
334
|
+
return n;
|
|
335
|
+
}
|
|
336
|
+
function scale(max, ticks) {
|
|
337
|
+
const rough = max / ticks, p = Math.pow(10, Math.floor(Math.log10(rough))), m = rough / p;
|
|
338
|
+
const step = (m <= 1 ? 1 : m <= 2 ? 2 : m <= 2.5 ? 2.5 : m <= 5 ? 5 : 10) * p;
|
|
339
|
+
return { step, max: step * ticks };
|
|
340
|
+
}
|
|
341
|
+
const dayIdx = s => Date.parse(/^\d{4}-/.test(s) ? s : "2026-" + s + "T00:00:00Z") / 864e5;
|
|
342
|
+
let LAST = dayIdx(DATA[DATA.length - 1].d);
|
|
343
|
+
|
|
344
|
+
function domain(days) {
|
|
345
|
+
const out = [];
|
|
346
|
+
for (let i = days - 1; i >= 0; i--) {
|
|
347
|
+
const dt = new Date((LAST - i) * 864e5);
|
|
348
|
+
const label = String(dt.getUTCMonth() + 1).padStart(2, "0") + "-" + String(dt.getUTCDate()).padStart(2, "0");
|
|
349
|
+
out.push({ label, rec: DATA.find(r => r.d === label) });
|
|
350
|
+
}
|
|
351
|
+
return out;
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
function flowChart(node, days) {
|
|
355
|
+
const c = C();
|
|
356
|
+
const dom = domain(days);
|
|
357
|
+
const W = Math.max(300, Math.round(node.clientWidth || 720)), H = 196, P = { l: 42, r: 42, t: 12, b: 22 };
|
|
358
|
+
const iw = W - P.l - P.r, ih = H - P.t - P.b, ticks = 4;
|
|
359
|
+
const L = scale(Math.max(...DATA.map(r => r.v)) * 1.06, ticks);
|
|
360
|
+
const R = scale(Math.max(...DATA.map(r => r.c)) * 1.06, ticks);
|
|
361
|
+
const x = i => P.l + (i * iw) / (dom.length - 1);
|
|
362
|
+
const yl = v => P.t + ih - (v / L.max) * ih;
|
|
363
|
+
const yr = v => P.t + ih - (v / R.max) * ih;
|
|
364
|
+
|
|
365
|
+
node.textContent = "";
|
|
366
|
+
const svg = el("svg", { viewBox: `0 0 ${W} ${H}`, role: "img" });
|
|
367
|
+
|
|
368
|
+
for (let t = 0; t <= ticks; t++) {
|
|
369
|
+
const yy = P.t + ih - (t / ticks) * ih;
|
|
370
|
+
svg.appendChild(el("line", { x1: P.l, x2: W - P.r, y1: yy, y2: yy, stroke: c.grid }));
|
|
371
|
+
svg.appendChild(el("text", { x: P.l - 8, y: yy + 4, "text-anchor": "end", class: "tick-label", fill: c.human, opacity: .85 }, fmt(L.step * t)));
|
|
372
|
+
svg.appendChild(el("text", { x: W - P.r + 8, y: yy + 4, class: "tick-label", fill: c.machine }, fmt(R.step * t)));
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
const firstIdx = dom.findIndex(d => d.rec);
|
|
376
|
+
if (firstIdx > 0) {
|
|
377
|
+
svg.appendChild(el("rect", { x: P.l, y: P.t, width: x(firstIdx) - P.l, height: ih, fill: c.zero }));
|
|
378
|
+
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" }, "10-26 起"));
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
dom.forEach((d, i) => {
|
|
383
|
+
if (d.rec && RELEASE[d.label]) {
|
|
384
|
+
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
|
+
}
|
|
386
|
+
});
|
|
387
|
+
|
|
388
|
+
const vp = dom.map((d, i) => d.rec ? `${x(i)},${yl(d.rec.v)}` : null);
|
|
389
|
+
const f = vp.findIndex(Boolean), l = vp.length - 1 - [...vp].reverse().findIndex(Boolean);
|
|
390
|
+
svg.appendChild(el("path", {
|
|
391
|
+
d: `M${x(f)},${yl(0)} L` + vp.filter(Boolean).join(" L") + ` L${x(l)},${yl(0)} Z`,
|
|
392
|
+
fill: c.human, opacity: .14
|
|
393
|
+
}));
|
|
394
|
+
|
|
395
|
+
const cp = dom.map((d, i) => d.rec ? `${x(i)},${yr(d.rec.c)}` : null).filter(Boolean).join(" ");
|
|
396
|
+
svg.appendChild(el("polyline", { points: cp, fill: "none", stroke: c.machine, "stroke-width": 1.5, opacity: .9 }));
|
|
397
|
+
|
|
398
|
+
svg.appendChild(el("polyline", { points: vp.filter(Boolean).join(" "), fill: "none", stroke: c.human, "stroke-width": 2, "stroke-linejoin": "round" }));
|
|
399
|
+
|
|
400
|
+
const peak = DATA.reduce((a, b) => b.v > a.v ? b : a);
|
|
401
|
+
const pi = dom.findIndex(d => d.rec === peak);
|
|
402
|
+
svg.appendChild(el("text", { x: x(pi), y: yl(peak.v) - 8, "text-anchor": "middle", class: "val-label" }, fmt(peak.v)));
|
|
403
|
+
|
|
404
|
+
const step = Math.max(1, Math.ceil(dom.length / 6));
|
|
405
|
+
dom.forEach((d, i) => {
|
|
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));
|
|
408
|
+
});
|
|
409
|
+
node.appendChild(svg);
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
function npmChart(node, days) {
|
|
413
|
+
const c = C();
|
|
414
|
+
const dom = domain(days);
|
|
415
|
+
const W = Math.max(300, Math.round(node.clientWidth || 720)), H = 122, P = { l: 44, r: 10, t: 14, b: 20 };
|
|
416
|
+
const iw = W - P.l - P.r, ih = H - P.t - P.b, ticks = 2;
|
|
417
|
+
const S = scale(Math.max(...DATA.filter(r => r.n).map(r => r.n)) * 1.02, ticks);
|
|
418
|
+
const bw = Math.max(4, Math.min(24, (iw / dom.length) * 0.5));
|
|
419
|
+
const cx = i => P.l + (i + .5) * (iw / dom.length);
|
|
420
|
+
const y = v => P.t + ih - (v / S.max) * ih;
|
|
421
|
+
|
|
422
|
+
node.textContent = "";
|
|
423
|
+
const svg = el("svg", { viewBox: `0 0 ${W} ${H}`, role: "img" });
|
|
424
|
+
for (let t = 0; t <= ticks; t++) {
|
|
425
|
+
const yy = y(S.step * t);
|
|
426
|
+
svg.appendChild(el("line", { x1: P.l, x2: W - P.r, y1: yy, y2: yy, stroke: c.grid }));
|
|
427
|
+
svg.appendChild(el("text", { x: P.l - 8, y: yy + 4, "text-anchor": "end", class: "tick-label" }, fmt(S.step * t)));
|
|
428
|
+
}
|
|
429
|
+
dom.forEach((d, i) => {
|
|
430
|
+
if (!d.rec) return;
|
|
431
|
+
const v = d.rec.n;
|
|
432
|
+
const pending = i >= dom.length - 2;
|
|
433
|
+
if (v == null || (pending && v === 0)) {
|
|
434
|
+
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
|
+
return;
|
|
436
|
+
}
|
|
437
|
+
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 === Math.max(...DATA.filter(r => r.n).map(r => r.n)))) svg.appendChild(el("text", { x: cx(i), y: y(v) - 6, "text-anchor": "middle", class: "val-label" }, fmt(v)));
|
|
439
|
+
});
|
|
440
|
+
const step = Math.max(1, Math.ceil(dom.length / 6));
|
|
441
|
+
dom.forEach((d, i) => {
|
|
442
|
+
if (i % step && i !== dom.length - 1) return;
|
|
443
|
+
svg.appendChild(el("text", { x: cx(i), y: H - 4, "text-anchor": "middle", class: "tick-label" }, d.label));
|
|
444
|
+
});
|
|
445
|
+
node.appendChild(svg);
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
let RANKS = [
|
|
449
|
+
["看了哪些页面", [["仓库主页", 397], ["issues 列表", 15], ["README", 2], ["actions 页", 1]]]
|
|
450
|
+
];
|
|
451
|
+
let PATHS = null;
|
|
452
|
+
let REFS = null;
|
|
453
|
+
|
|
454
|
+
const shortPath = p => p === "仓库主页" ? "仓库主页"
|
|
455
|
+
: /^issues\/\d+$/.test(p) ? "issue 页"
|
|
456
|
+
: /issues/.test(p) ? "issues 列表"
|
|
457
|
+
: /README/i.test(p) ? "README"
|
|
458
|
+
: /^actions/.test(p) ? "actions 页"
|
|
459
|
+
: /^blob\//.test(p) ? "文件页"
|
|
460
|
+
: p;
|
|
461
|
+
|
|
462
|
+
function donut(node) {
|
|
463
|
+
node.textContent = "";
|
|
464
|
+
const cs = getComputedStyle(document.documentElement);
|
|
465
|
+
let parts = PATHS ? PATHS : [];
|
|
466
|
+
if (!parts.length) parts = [["0.6.14", 320, "--brand"], ["旧版本", 1137, "--machine"]];
|
|
467
|
+
const total = parts.reduce((s, p) => s + p[1], 0);
|
|
468
|
+
const R = 40, ST = 13, CIRC = 2 * Math.PI * R;
|
|
469
|
+
const svg = el("svg", { viewBox: "0 0 104 104", role: "img", "aria-label": "npm 版本下载占比" });
|
|
470
|
+
svg.appendChild(el("circle", { cx: 52, cy: 52, r: R, fill: "none", stroke: cs.getPropertyValue("--border-l1").trim(), "stroke-width": ST }));
|
|
471
|
+
let off = 0;
|
|
472
|
+
parts.forEach(p => {
|
|
473
|
+
const len = (p[1] / total) * CIRC;
|
|
474
|
+
svg.appendChild(el("circle", {
|
|
475
|
+
cx: 52, cy: 52, r: R, fill: "none",
|
|
476
|
+
stroke: cs.getPropertyValue(p[2]).trim(),
|
|
477
|
+
"stroke-width": ST, "stroke-linecap": "butt",
|
|
478
|
+
"stroke-dasharray": `${Math.max(0, len - 3)} ${CIRC - Math.max(0, len - 3)}`,
|
|
479
|
+
"stroke-dashoffset": -off,
|
|
480
|
+
transform: "rotate(-90 52 52)"
|
|
481
|
+
}));
|
|
482
|
+
off += len;
|
|
483
|
+
});
|
|
484
|
+
svg.appendChild(el("text", { x: 52, y: 50, "text-anchor": "middle", class: "val-label", "font-size": 15, "font-weight": 600 }, Math.round((parts[0][1] / total) * 100) + "%"));
|
|
485
|
+
svg.appendChild(el("text", { x: 52, y: 64, "text-anchor": "middle", class: "tick-label", "font-size": 11 }, parts[0][0]));
|
|
486
|
+
node.appendChild(svg);
|
|
487
|
+
|
|
488
|
+
const lg = document.createElement("div");
|
|
489
|
+
lg.className = "donut-legend";
|
|
490
|
+
parts.forEach(p => {
|
|
491
|
+
const row = document.createElement("div");
|
|
492
|
+
const left = document.createElement("span");
|
|
493
|
+
const sw = document.createElement("i");
|
|
494
|
+
sw.style.background = `var(${p[2]})`;
|
|
495
|
+
left.appendChild(sw);
|
|
496
|
+
left.appendChild(document.createTextNode(p[0]));
|
|
497
|
+
const right = document.createElement("b");
|
|
498
|
+
right.textContent = Math.round((p[1] / total) * 100) + "%";
|
|
499
|
+
row.appendChild(left); row.appendChild(right);
|
|
500
|
+
lg.appendChild(row);
|
|
501
|
+
});
|
|
502
|
+
node.appendChild(lg);
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
function ranks(node) {
|
|
506
|
+
node.textContent = "";
|
|
507
|
+
RANKS.forEach(([group, rows]) => {
|
|
508
|
+
const box = document.createElement("div");
|
|
509
|
+
const h3 = document.createElement("h3");
|
|
510
|
+
h3.textContent = group;
|
|
511
|
+
box.appendChild(h3);
|
|
512
|
+
const ul = document.createElement("ul");
|
|
513
|
+
const max = Math.max(...rows.map(r => r[1]), 1);
|
|
514
|
+
const single = rows.length === 1;
|
|
515
|
+
rows.forEach(([name, value]) => {
|
|
516
|
+
const li = document.createElement("li");
|
|
517
|
+
const k = document.createElement("span");
|
|
518
|
+
k.className = "k";
|
|
519
|
+
k.textContent = name;
|
|
520
|
+
const v = document.createElement("span");
|
|
521
|
+
v.className = "v";
|
|
522
|
+
v.textContent = fmt(value);
|
|
523
|
+
li.appendChild(k);
|
|
524
|
+
if (single) {
|
|
525
|
+
li.style.gridTemplateColumns = "1fr auto";
|
|
526
|
+
} else {
|
|
527
|
+
const track = document.createElement("span");
|
|
528
|
+
track.className = "track";
|
|
529
|
+
const bar = document.createElement("i");
|
|
530
|
+
bar.style.width = Math.max(2, (value / max) * 100) + "%";
|
|
531
|
+
track.appendChild(bar);
|
|
532
|
+
li.appendChild(track);
|
|
533
|
+
}
|
|
534
|
+
li.appendChild(v);
|
|
535
|
+
ul.appendChild(li);
|
|
536
|
+
});
|
|
537
|
+
box.appendChild(ul);
|
|
538
|
+
node.appendChild(box);
|
|
539
|
+
});
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
const kUniq = document.getElementById("k-uniq");
|
|
543
|
+
const kViewsSub = document.getElementById("k-views-sub");
|
|
544
|
+
|
|
545
|
+
|
|
546
|
+
const rangeNote = document.getElementById("range-note");
|
|
547
|
+
let currentRange = 7;
|
|
548
|
+
|
|
549
|
+
function render(days) {
|
|
550
|
+
currentRange = days;
|
|
551
|
+
const dom = domain(days);
|
|
552
|
+
const recs = dom.filter(d => d.rec).map(d => d.rec);
|
|
553
|
+
const tv = recs.reduce((s, r) => s + r.v, 0);
|
|
554
|
+
const tu = recs.reduce((s, r) => s + r.u, 0);
|
|
555
|
+
// 访客只能用 API 窗口去重值;超过 14 天没有该值就退回日均
|
|
556
|
+
let uniq = days === 7 && LIVE.totals.uniques != null ? LIVE.totals.uniques : null;
|
|
557
|
+
if (uniq == null && days <= 14 && LIVE.totals.uniques != null && days === LIVE.range.days) uniq = LIVE.totals.uniques;
|
|
558
|
+
if (uniq == null) uniq = recs.length ? Math.round(tu / recs.length) : null;
|
|
559
|
+
kUniq.textContent = uniq == null ? "—" : fmt(uniq);
|
|
560
|
+
kViewsSub.textContent = days === 7 ? fmt(tv) + " 次浏览" : "日均 " + (recs.length ? fmt(tv / recs.length) : "—") + " 次浏览";
|
|
561
|
+
rangeNote.textContent = dom[0].label + " → " + dom[dom.length - 1].label;
|
|
562
|
+
flowChart(document.getElementById("c-flow"), days);
|
|
563
|
+
npmChart(document.getElementById("c-npm"), days);
|
|
564
|
+
donut(document.getElementById("donut"));
|
|
565
|
+
ranks(document.getElementById("ranks"));
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
document.getElementById("seg").addEventListener("click", e => {
|
|
569
|
+
const b = e.target.closest("button");
|
|
570
|
+
if (!b) return;
|
|
571
|
+
[...e.currentTarget.children].forEach(x => x.classList.toggle("on", x === b));
|
|
572
|
+
render(+b.dataset.r);
|
|
573
|
+
pull(+b.dataset.r);
|
|
574
|
+
});
|
|
575
|
+
|
|
576
|
+
document.getElementById("theme").addEventListener("click", () => {
|
|
577
|
+
const next = theme() === "dark" ? "light" : "dark";
|
|
578
|
+
document.documentElement.dataset.theme = next;
|
|
579
|
+
document.getElementById("ico-sun").style.display = next === "dark" ? "" : "none";
|
|
580
|
+
document.getElementById("ico-moon").style.display = next === "dark" ? "none" : "";
|
|
581
|
+
try { localStorage.setItem("go-theme", next); } catch (e) {}
|
|
582
|
+
render(currentRange);
|
|
583
|
+
});
|
|
584
|
+
|
|
585
|
+
document.getElementById("cfg-toggle").addEventListener("click", () => document.getElementById("cfg").classList.toggle("open"));
|
|
586
|
+
document.getElementById("cfg-save").addEventListener("click", () => {
|
|
587
|
+
document.getElementById("cfg").classList.remove("open");
|
|
588
|
+
document.getElementById("cfg-toggle").textContent = "已配置";
|
|
589
|
+
});
|
|
590
|
+
|
|
591
|
+
const rb = document.getElementById("refresh");
|
|
592
|
+
rb.addEventListener("click", async () => {
|
|
593
|
+
const keep = rb.innerHTML;
|
|
594
|
+
rb.textContent = "刷新中…";
|
|
595
|
+
try {
|
|
596
|
+
await fetch("/api/sync", { method: "POST" });
|
|
597
|
+
await pull(currentRange, true);
|
|
598
|
+
rb.textContent = "刚更新";
|
|
599
|
+
} catch (e) {
|
|
600
|
+
rb.textContent = "刷新失败";
|
|
601
|
+
}
|
|
602
|
+
setTimeout(() => { rb.innerHTML = keep; }, 1600);
|
|
603
|
+
});
|
|
604
|
+
|
|
605
|
+
try {
|
|
606
|
+
const q = new URLSearchParams(location.search).get("theme");
|
|
607
|
+
const saved = q || localStorage.getItem("go-theme");
|
|
608
|
+
if (saved === "light") document.getElementById("theme").click();
|
|
609
|
+
} catch (e) {}
|
|
610
|
+
// 实时数据:拿不到就继续用内置样例,页面始终能看
|
|
611
|
+
const LIVE = { totals: {}, range: { days: 7, storedDays: 0 }, repo: {}, contributions: { issues: [], pulls: [] }, releases: [], paths: [], npmVersions: [], updatedAt: null };
|
|
612
|
+
const label = iso => String(iso).slice(5, 10);
|
|
613
|
+
const mmdd = iso => label(iso);
|
|
614
|
+
|
|
615
|
+
function applyLive(json) {
|
|
616
|
+
Object.assign(LIVE, json);
|
|
617
|
+
if (Array.isArray(json.series) && json.series.length) {
|
|
618
|
+
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
|
+
LAST = dayIdx(json.series[json.series.length - 1].d);
|
|
620
|
+
RELEASE = {};
|
|
621
|
+
for (const rel of json.releases || []) {
|
|
622
|
+
const k = label(rel.at);
|
|
623
|
+
if (DATA.some(r => r.d === k)) RELEASE[k] = (RELEASE[k] || 0) + 1;
|
|
624
|
+
}
|
|
625
|
+
}
|
|
626
|
+
if (Array.isArray(json.paths) && json.paths.length) {
|
|
627
|
+
const rows = json.paths.slice(0, 3).map(p => [shortPath(p.p), p.n]);
|
|
628
|
+
const rest = json.paths.slice(3).reduce((s, p) => s + p.n, 0);
|
|
629
|
+
PATHS = [[...rows[0], "--brand"], ...rows.slice(1).map((r, i) => [...r, i ? "--event" : "--machine"])];
|
|
630
|
+
if (rest > 0) PATHS.push(["其他页面", rest, "--border-l2"]);
|
|
631
|
+
}
|
|
632
|
+
if (Array.isArray(json.referrers) && json.referrers.length) {
|
|
633
|
+
RANKS = [["从哪来", json.referrers.slice(0, 4).map(r => [r.from.replace(/^www\./, ""), r.n])]];
|
|
634
|
+
}
|
|
635
|
+
const repo = json.repo || {};
|
|
636
|
+
if (repo.owner) document.getElementById("repo-owner").textContent = repo.owner + " /";
|
|
637
|
+
if (repo.name) document.getElementById("repo-name").textContent = repo.name;
|
|
638
|
+
const c = json.contributions || { issues: [], pulls: [] };
|
|
639
|
+
const ic = c.issues.length, pc = c.pulls.length;
|
|
640
|
+
document.getElementById("k-contrib").textContent = ic + pc;
|
|
641
|
+
document.getElementById("k-contrib-sub").textContent = ic + " issue、" + pc + " PR";
|
|
642
|
+
document.getElementById("k-stars").textContent = repo.stars ?? "—";
|
|
643
|
+
document.getElementById("k-forks").textContent = (repo.forks ?? 0) + " forks";
|
|
644
|
+
const rels = (json.releases || []).filter(r => DATA.some(x => x.d === label(r.at)));
|
|
645
|
+
document.getElementById("k-rel").textContent = rels.length;
|
|
646
|
+
document.getElementById("k-rel-sub").textContent = rels.length
|
|
647
|
+
? rels[rels.length - 1].tag + " → " + rels[0].tag
|
|
648
|
+
: "本窗口无发版";
|
|
649
|
+
const iss = c.issues[0];
|
|
650
|
+
document.getElementById("s-issues").textContent = ic + " 个";
|
|
651
|
+
document.getElementById("s-issues-sub").textContent = iss
|
|
652
|
+
? (iss.state === "closed" ? "已关闭," : "开着,") + "来自 " + iss.author
|
|
653
|
+
: "没有外部 issue";
|
|
654
|
+
const pr = c.pulls[0];
|
|
655
|
+
document.getElementById("s-prs").textContent = pc + " 个";
|
|
656
|
+
document.getElementById("s-prs-sub").textContent = pr
|
|
657
|
+
? (pr.merged ? "已合并" : "没合并") + (pr.additions != null ? ",+" + pr.additions + " −" + pr.deletions : ",来自 " + pr.author)
|
|
658
|
+
: "没有外部 PR";
|
|
659
|
+
const al = c.alerts;
|
|
660
|
+
const opened = al ? ["dependabot", "codeScanning", "secretScanning"].filter(k => al[k]?.available) : [];
|
|
661
|
+
const total = al ? opened.reduce((s, k) => s + (al[k].open || 0), 0) : null;
|
|
662
|
+
document.getElementById("s-alerts").textContent = !al || !opened.length ? "未开启" : total ? total + " 条" : "无";
|
|
663
|
+
document.getElementById("s-alerts-sub").textContent = !al || !opened.length ? "无数据" : total ? "待处理" : "已开启";
|
|
664
|
+
const t = json.totals || {};
|
|
665
|
+
if (t.npmWeek != null) {
|
|
666
|
+
document.getElementById("k-npm").textContent = fmt(t.npmWeek);
|
|
667
|
+
}
|
|
668
|
+
const days = json.range?.storedDays || 0;
|
|
669
|
+
document.getElementById("r-days").textContent = days + " 天";
|
|
670
|
+
if (json.updatedAt) {
|
|
671
|
+
const mins = Math.max(0, Math.round((Date.now() - Date.parse(json.updatedAt)) / 60000));
|
|
672
|
+
document.getElementById("r-last").textContent = mins < 1 ? "刚刚" : mins < 60 ? mins + " 分钟前" : Math.round(mins / 60) + " 小时前";
|
|
673
|
+
}
|
|
674
|
+
}
|
|
675
|
+
|
|
676
|
+
async function pull(days, force) {
|
|
677
|
+
try {
|
|
678
|
+
const res = await fetch("/api/data?days=" + days, { cache: "no-store" });
|
|
679
|
+
if (!res.ok) throw new Error(res.status);
|
|
680
|
+
const json = await res.json();
|
|
681
|
+
if (json.repo && !json.repo.stars && !force) { /* 未同步过也照常渲染 */ }
|
|
682
|
+
applyLive(json);
|
|
683
|
+
if (!(days === LIVE.range.days)) LIVE.range.days = days;
|
|
684
|
+
render(days);
|
|
685
|
+
loadSummary(days);
|
|
686
|
+
return json;
|
|
687
|
+
} catch (e) {
|
|
688
|
+
render(days);
|
|
689
|
+
return null;
|
|
690
|
+
}
|
|
691
|
+
}
|
|
692
|
+
|
|
693
|
+
async function loadSummary(days) {
|
|
694
|
+
try {
|
|
695
|
+
const res = await fetch("/api/summary?days=" + days, { cache: "no-store" });
|
|
696
|
+
if (!res.ok) return;
|
|
697
|
+
const data = await res.json();
|
|
698
|
+
const lines = data.lines || [];
|
|
699
|
+
["sum-1", "sum-2", "sum-3"].forEach((id, i) => {
|
|
700
|
+
const node = document.getElementById(id);
|
|
701
|
+
if (!node) return;
|
|
702
|
+
node.textContent = lines[i] || "";
|
|
703
|
+
});
|
|
704
|
+
const at = document.getElementById("sum-at");
|
|
705
|
+
if (at) at.textContent = new Date().toLocaleString("zh-CN", { month: "2-digit", day: "2-digit", hour: "2-digit", minute: "2-digit" }).replace("/", "-");
|
|
706
|
+
} catch (e) {}
|
|
707
|
+
}
|
|
708
|
+
|
|
709
|
+
document.querySelector(".ask button").addEventListener("click", async () => {
|
|
710
|
+
const input = document.querySelector(".ask input");
|
|
711
|
+
if (!input.value.trim()) return;
|
|
712
|
+
input.disabled = true;
|
|
713
|
+
const res = await loadSummary(currentRange);
|
|
714
|
+
input.disabled = false;
|
|
715
|
+
});
|
|
716
|
+
|
|
717
|
+
|
|
718
|
+
pull(7);
|
|
719
|
+
let rzT;
|
|
720
|
+
addEventListener("resize", () => { clearTimeout(rzT); rzT = setTimeout(() => render(currentRange), 160); });
|
|
721
|
+
</script>
|
|
722
|
+
</body>
|
|
723
|
+
</html>
|