26 lines
681 B
JavaScript
26 lines
681 B
JavaScript
/**
|
||
* 版本号加载器
|
||
* 读取 /api/version 并将版本号填充到页面元素的 #version-text(或 .statusbar-version)
|
||
*/
|
||
(function () {
|
||
function fill(text) {
|
||
var el = document.getElementById("version-text");
|
||
if (!el) el = document.querySelector(".statusbar-version");
|
||
if (!el) return;
|
||
el.textContent = text;
|
||
}
|
||
|
||
try {
|
||
fetch("/api/version")
|
||
.then(function (r) {
|
||
if (!r.ok) throw new Error("bad status");
|
||
return r.json();
|
||
})
|
||
.then(function (data) {
|
||
if (data && data.success && data.data) {
|
||
fill(data.data.version || "");
|
||
}
|
||
})
|
||
.catch(function () {});
|
||
} catch (e) {}
|
||
})(); |