mirror of
https://github.com/chenyme/grok2api.git
synced 2026-12-05 16:02:12 +00:00
43 lines
1.4 KiB
JavaScript
43 lines
1.4 KiB
JavaScript
async function loadFunctionHeader() {
|
|
const container = document.getElementById('app-header');
|
|
if (!container) return;
|
|
try {
|
|
const res = await fetch('/static/common/html/function-header.html?v=1.6.2');
|
|
if (!res.ok) return;
|
|
container.innerHTML = await res.text();
|
|
const logoutBtn = container.querySelector('#function-logout-btn');
|
|
if (logoutBtn) {
|
|
logoutBtn.classList.add('hidden');
|
|
try {
|
|
const verify = await fetch('/v1/function/verify', { method: 'GET' });
|
|
if (verify.status === 401) {
|
|
logoutBtn.classList.remove('hidden');
|
|
}
|
|
} catch (e) {
|
|
// Ignore verification errors and keep it hidden
|
|
}
|
|
}
|
|
if (window.I18n) {
|
|
I18n.applyToDOM(container);
|
|
var toggle = container.querySelector('#lang-toggle');
|
|
if (toggle) toggle.textContent = I18n.getLang() === 'zh' ? 'EN' : '中';
|
|
}
|
|
const path = window.location.pathname;
|
|
const links = container.querySelectorAll('a[data-nav]');
|
|
links.forEach((link) => {
|
|
const target = link.getAttribute('data-nav') || '';
|
|
if (target && path.startsWith(target)) {
|
|
link.classList.add('active');
|
|
}
|
|
});
|
|
} catch (e) {
|
|
// Fail silently to avoid breaking page load
|
|
}
|
|
}
|
|
|
|
if (document.readyState === 'loading') {
|
|
document.addEventListener('DOMContentLoaded', loadFunctionHeader);
|
|
} else {
|
|
loadFunctionHeader();
|
|
}
|