添加路径

This commit is contained in:
CN-JS-HuiBai
2026-04-07 17:06:34 +08:00
parent 2c6a38c80d
commit cedfe004ed
5 changed files with 496 additions and 14 deletions

View File

@@ -1,4 +1,4 @@
<!doctype html>
<!doctype html>
<html lang="zh-CN">
<head>
@@ -124,6 +124,7 @@
async function loadSummary() {
if (STATE.loading || STATE.loaded) return;
const authorization = getAuthHeader();
if (!authorization) return;
@@ -160,8 +161,8 @@
}
function buildTriggerHtml() {
const count = STATE.data?.user?.online_count ?? 0;
return '<span>在线 IP</span><strong>' + count + '</strong>';
const count = STATE.data && STATE.data.user ? STATE.data.user.online_count : 0;
return '<span>Online IP</span><strong>' + count + '</strong>';
}
function buildMenuNode() {
@@ -169,16 +170,18 @@
wrapper.className = 'xboard-online-devices-menu';
wrapper.setAttribute('data-user-online-devices-menu', '1');
const devices = Array.isArray(STATE.data?.online_devices) ? STATE.data.online_devices : [];
const devices = STATE.data && Array.isArray(STATE.data.online_devices) ? STATE.data.online_devices : [];
const count = STATE.data && STATE.data.user ? STATE.data.user.online_count : 0;
const title = document.createElement('div');
title.className = 'xboard-online-devices-menu-title';
title.innerHTML = '<span>在线 IP / 设备</span><span>' + (STATE.data?.user?.online_count ?? 0) + '</span>';
title.innerHTML = '<span>Online IP / Devices</span><span>' + count + '</span>';
wrapper.appendChild(title);
if (!devices.length) {
const empty = document.createElement('div');
empty.className = 'xboard-online-devices-menu-empty';
empty.textContent = '当前没有检测到在线 IP。';
empty.textContent = 'No online IP detected.';
wrapper.appendChild(empty);
return wrapper;
}
@@ -199,16 +202,17 @@
function injectIntoAvatarArea() {
if (!STATE.enabled || !STATE.data) return;
if (document.querySelector('[data-user-online-devices-trigger="1"]')) {
const current = document.querySelector('[data-user-online-devices-trigger="1"]');
current.innerHTML = buildTriggerHtml();
const existing = document.querySelector('[data-user-online-devices-trigger="1"]');
if (existing) {
existing.innerHTML = buildTriggerHtml();
return;
}
const avatar = document.querySelector('.n-avatar');
if (!avatar) return;
const anchor = avatar.closest('button, .n-button, .n-space, .n-flex, div');
const anchor = avatar.closest('button, .n-button, .n-space, .n-flex, .n-popover-trigger, div');
if (!anchor || !anchor.parentElement) return;
const badge = document.createElement('span');
@@ -221,14 +225,13 @@
function injectIntoDropdowns() {
if (!STATE.enabled || !STATE.data) return;
const dropdowns = document.querySelectorAll('.n-dropdown-menu');
const dropdowns = document.querySelectorAll('.n-dropdown-menu, .n-popover-shared .n-base-menu, .n-popover-shared .n-dropdown-menu');
dropdowns.forEach(function (dropdown) {
if (dropdown.querySelector('[data-user-online-devices-menu="1"]')) return;
const menuNode = buildMenuNode();
const host = document.createElement('div');
host.className = 'n-dropdown-option';
host.appendChild(menuNode);
host.appendChild(buildMenuNode());
dropdown.appendChild(host);
});
}
@@ -248,7 +251,7 @@
window.setTimeout(function () {
injectIntoAvatarArea();
injectIntoDropdowns();
}, 120);
}, 200);
}, true);
window.setTimeout(loadSummary, 1200);
@@ -256,9 +259,18 @@
STATE.loaded = false;
loadSummary();
}, 30000);
window.__xboardUserOnlineDevicesDebug = {
reload: function () {
STATE.loaded = false;
return loadSummary();
},
state: STATE
};
})();
</script>
{!! $theme_config['custom_html'] !!}
</body>
</html>