-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
233 lines (215 loc) · 10.7 KB
/
index.html
File metadata and controls
233 lines (215 loc) · 10.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
<!doctype html>
<html lang="zh-CN">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>BongoCat 一键下载助手</title>
<meta name="description" content="自动识别系统与架构,获取 BongoCat 最新版本并提供正确的下载链接。" />
<style>
:root { color-scheme: light dark; }
body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif; margin: 0; padding: 24px; line-height: 1.6; }
.container { max-width: 780px; margin: 0 auto; }
h1 { margin: 0 0 8px; font-size: 28px; }
.sub { margin: 0 0 24px; color: #666; font-size: 14px; }
.card { border: 1px solid rgba(0,0,0,0.08); border-radius: 12px; padding: 20px; margin-bottom: 16px; backdrop-filter: blur(4px); }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.kv { display: inline-flex; align-items: center; gap: 6px; padding: 6px 10px; border-radius: 999px; background: rgba(0,0,0,0.06); font-size: 13px; }
a.button { display: inline-block; padding: 12px 18px; border-radius: 10px; background: #2d6cdf; color: #fff; text-decoration: none; font-weight: 600; }
a.button[disabled] { opacity: 0.6; pointer-events: none; }
.muted { color: #666; font-size: 13px; }
ul { margin: 8px 0 0 18px; }
code { padding: 2px 6px; border-radius: 6px; background: rgba(0,0,0,0.06); }
.links { display: flex; gap: 10px; flex-wrap: wrap; }
.assets a { display: inline-block; margin: 4px 8px 0 0; }
</style>
</head>
<body>
<div class="container">
<h1>BongoCat 一键下载助手</h1>
<p class="sub">自动识别您的系统与架构,获取最新版本安装包并提供直达下载。</p>
<div class="card">
<div class="row" id="env">
<div class="kv"><strong>系统</strong><span id="os">检测中…</span></div>
<div class="kv"><strong>架构</strong><span id="arch">检测中…</span>
<select id="archSelect" style="margin-left:6px; height:28px; border-radius:8px; border:1px solid rgba(0,0,0,0.15); background:transparent;">
<option value="auto">自动</option>
<option value="arm64">arm64</option>
<option value="x64">x64</option>
<option value="x86">x86</option>
</select>
</div>
<div class="kv"><strong>最新版本</strong><span id="version">查询中…</span></div>
</div>
<div style="margin-top:16px;" class="links">
<a id="downloadBtn" class="button" href="#" rel="noopener" target="_blank" disabled>准备下载…</a>
<a id="releasesBtn" class="button" style="background:#3c9d5e" href="https://github.com/ayangweb/BongoCat/releases/latest" target="_blank" rel="noopener">查看 Releases</a>
</div>
<p class="muted" id="filenameHint" style="margin-top:10px;">文件名示例:<code>BongoCat_0.8.1_x64-setup.exe</code>(实际以最新版本与平台为准)</p>
</div>
<div class="card">
<strong>备选下载资源(若自动匹配失败)</strong>
<div class="assets" id="altAssets"></div>
<p class="muted">如遇问题,请加入 QQ 群获取帮助:<a href="https://qm.qq.com/q/OE8G4OcpOY" target="_blank" rel="noopener">点此加入 QQ 群</a></p>
</div>
<p class="muted">项目来源:<a href="https://github.com/ayangweb/BongoCat/" target="_blank" rel="noopener">ayangweb/BongoCat</a></p>
</div>
<script>
(function () {
const $ = (id) => document.getElementById(id);
const state = { os: "Unknown", arch: "unknown", archWasDefaulted: false, version: "", assets: [] };
function detectOS() {
const ua = navigator.userAgent || "";
const p = navigator.platform || "";
// Prefer UA hints
if (/Windows/i.test(ua) || /Win/i.test(p)) return "Windows";
if (/Macintosh|Mac OS X|Mac OS/i.test(ua) || /Mac/i.test(p)) return "macOS";
if (/Linux/i.test(ua) || /Linux/i.test(p)) return "Linux";
return "Unknown";
}
function detectArch() {
const ua = navigator.userAgent || "";
// Try userAgentData if available
// @ts-ignore
const uaData = navigator.userAgentData;
if (uaData && Array.isArray(uaData.brands)) {
// Many Chromium UAData expose architecture via platform or UA fallback
}
if (/arm64|aarch64|Apple\s?Silicon/i.test(ua)) return "arm64";
if (/x86_64|x64|Win64|AMD64/i.test(ua)) return "x64";
if (/i[3-6]86|x86\b/i.test(ua)) return "x86";
return "unknown";
}
function matchAssetFor(os, arch, assets) {
const score = (name) => {
let s = 0;
const n = name.toLowerCase();
// OS weight
if (os === "Windows" && (n.endsWith(".exe") || n.endsWith(".msi") || n.includes("windows"))) s += 5;
if (os === "macOS" && (n.endsWith(".dmg") || n.endsWith(".pkg") || n.includes("macos") || n.includes("darwin"))) s += 5;
if (os === "Linux" && (n.endsWith(".appimage") || n.endsWith(".deb") || n.endsWith(".rpm") || n.includes("linux"))) s += 5;
// Arch weight
if (arch === "arm64" && (n.includes("arm64") || n.includes("aarch64"))) s += 3;
if (arch === "x64" && (n.includes("x64") || n.includes("x86_64") || n.includes("amd64"))) s += 3;
if (arch === "x86" && (n.includes("x86") && !n.includes("x86_64"))) s += 3;
// Deprioritize source zips
if (n.endsWith(".zip") || n.endsWith(".tar.gz")) s += 1; // might be portable
if (n.includes("setup")) s += 1; // Windows installer
return s;
};
let best = null, bestScore = -1;
for (const a of assets) {
const s = score(a.name || "");
if (s > bestScore) { best = a; bestScore = s; }
}
return best;
}
function updateFilenameHint(version, assetName) {
const hint = $("filenameHint");
if (!version) return;
const v = version.startsWith("v") ? version.slice(1) : version;
if (assetName) {
hint.innerHTML = `已匹配到文件:<code>${assetName}</code>`;
} else {
hint.innerHTML = `文件名示例:<code>BongoCat_${v}_x64-setup.exe</code>(以实际平台为准)`;
}
}
function applyArchFromSelect() {
const sel = $("archSelect");
const value = sel ? sel.value : "auto";
if (value === "auto") {
// keep current detected/defaulted arch
return state.arch;
}
state.archWasDefaulted = false;
state.arch = value;
return state.arch;
}
function recomputeBest() {
const archNow = applyArchFromSelect();
const best = matchAssetFor(state.os, archNow, state.assets);
const btn = $("downloadBtn");
if (best && best.browser_download_url) {
btn.href = best.browser_download_url;
btn.textContent = "立即下载(自动匹配)";
btn.removeAttribute("disabled");
updateFilenameHint(state.version, best.name);
} else {
btn.textContent = "未匹配到合适安装包,请查看 Releases";
btn.setAttribute("disabled", "true");
updateFilenameHint(state.version, null);
}
// 更新展示的架构标签
const suffix = state.archWasDefaulted ? "(默认)" : "";
$("arch").textContent = state.arch + (suffix ? " " + suffix : "");
}
async function main() {
const os = detectOS();
const rawArch = detectArch();
let arch = rawArch;
let archSuffix = "";
// 当无法获取架构信息时,按平台给出默认值
if (rawArch === "unknown") {
if (os === "macOS") { arch = "arm64"; archSuffix = "(默认)"; }
else if (os === "Windows") { arch = "x64"; archSuffix = "(默认)"; }
}
state.os = os; state.arch = arch; state.archWasDefaulted = !!archSuffix;
$("os").textContent = os;
$("arch").textContent = arch + (archSuffix ? " " + archSuffix : "");
// URL 参数覆盖 (?arch=arm64)
const params = new URLSearchParams(location.search);
const qArch = (params.get("arch") || "").toLowerCase();
if (qArch === "arm64" || qArch === "x64" || qArch === "x86") {
state.arch = qArch;
state.archWasDefaulted = false;
}
// 初始化下拉框
const sel = $("archSelect");
if (sel) {
sel.value = qArch ? qArch : "auto";
sel.addEventListener("change", () => {
recomputeBest();
});
}
try {
const resp = await fetch("https://api.github.com/repos/ayangweb/BongoCat/releases/latest", {
headers: { "Accept": "application/vnd.github+json" }
});
if (!resp.ok) throw new Error("GitHub API 请求失败:" + resp.status);
const data = await resp.json();
const version = data.tag_name || data.name || "unknown";
$("version").textContent = version;
state.version = version;
const assets = Array.isArray(data.assets) ? data.assets : [];
state.assets = assets;
recomputeBest();
// 备选资源列表
const alt = $("altAssets");
if (assets.length) {
const frag = document.createDocumentFragment();
assets.forEach(a => {
const link = document.createElement("a");
link.href = a.browser_download_url;
link.target = "_blank";
link.rel = "noopener";
link.textContent = a.name || "下载项";
link.className = "button";
link.style.background = "#555";
frag.appendChild(link);
});
alt.appendChild(frag);
} else {
alt.innerHTML = '<p class="muted">该版本暂无可用资源,请稍后重试或前往 Releases 页面查看。</p>';
}
} catch (err) {
console.error(err);
$("version").textContent = "获取失败";
const btn = $("downloadBtn");
btn.textContent = "GitHub API 访问失败,请稍后重试或查看 Releases";
btn.setAttribute("disabled", "true");
}
}
main();
})();
</script>
</body>
</html>