服务器信息显示

流量监控


优化代码

复制代码到哪吒管理后台的系统设置>自定义代码(样式和脚本)中

<script>//哪吒自定义属性window.ShowNetTransfer=false;window.DisableAnimatedMan=true;window.ForceUseSvgFlag=true;const selectorButton = '#root > div > main > div.mx-auto.w-full.max-w-5xl.px-0.flex.flex-col.gap-4.server-info > section > div.flex.justify-center.w-full.max-w-\\[200px\\] > div > div > div.relative.cursor-pointer.rounded-3xl.px-2\\.5.py-\\[8px\\].text-\\[13px\\].font-\\[600\\].transition-all.duration-500.text-stone-400.dark\\:text-stone-500';const selectorSection = '#root > div > main > div.mx-auto.w-full.max-w-5xl.px-0.flex.flex-col.gap-4.server-info > section';const selector3 = '#root > div > main > div.mx-auto.w-full.max-w-5xl.px-0.flex.flex-col.gap-4.server-info > div:nth-child(3)';const selector4 = '#root > div > main > div.mx-auto.w-full.max-w-5xl.px-0.flex.flex-col.gap-4.server-info > div:nth-child(4)';let hasClicked = false;let divVisible = false;function forceBothVisible() {  const div3 = document.querySelector(selector3);  const div4 = document.querySelector(selector4);  if (div3 && div4) {    div3.style.display = 'block';    div4.style.display = 'block';  }}function hideSection() {  const section = document.querySelector(selectorSection);  if (section) {    section.style.display = 'none';  }}function tryClickButton() {  const btn = document.querySelector(selectorButton);  if (btn && !hasClicked) {    btn.click();    hasClicked = true;    setTimeout(forceBothVisible, 500);  }}const observer = new MutationObserver(() => {  const div3 = document.querySelector(selector3);  const div4 = document.querySelector(selector4);  const isDiv3Visible = div3 && getComputedStyle(div3).display !== 'none';  const isDiv4Visible = div4 && getComputedStyle(div4).display !== 'none';  const isAnyDivVisible = isDiv3Visible || isDiv4Visible;  if (isAnyDivVisible && !divVisible) {    hideSection();    tryClickButton();  } else if (!isAnyDivVisible && divVisible) {    hasClicked = false;  }  divVisible = isAnyDivVisible;  if (div3 && div4) {    if (!isDiv3Visible || !isDiv4Visible) {      forceBothVisible();    }  }  // 立即执行一次,防止初始没触发 observer  hideDynamicH3();    // 更新进度条颜色  updateTrafficProgressColors();});const root = document.querySelector('#root');if (root) {  observer.observe(root, {    childList: true,    attributes: true,    subtree: true,    attributeFilter: ['style', 'class']  });}const hideDynamicH3 = () => {  document.querySelectorAll('h3.font-semibold.tracking-tight').forEach(el => {    if (el.textContent.trim() !== '') {      el.style.display = 'none';    }  });};// ===== 新增:流量监控进度条颜色功能 =====/** * 更新流量监控版块进度条颜色 * 根据使用率自动设置:70%以下绿色,70%-90%黄色,90%-99%红色,100%灰色 */function updateTrafficProgressColors() {  // 查找所有绿色进度条  const allProgressBars = document.querySelectorAll('.bg-emerald-500');    allProgressBars.forEach((bar) => {    // 向上查找百分比信息    let percentage = 0;    let serverName = '未知';        // 查找父级卡片    let parent = bar;    for (let i = 0; i < 10; i++) {      if (parent.classList.contains('w-full')) {        break;      }      parent = parent.parentElement;      if (!parent) break;    }        if (parent) {      // 查找服务器名称      const nameEl = parent.querySelector('.text-sm.font-medium.text-neutral-800');      if (nameEl) {        serverName = nameEl.textContent.trim();      }            // 查找百分比      const percentEl = parent.querySelector('.text-xs.font-medium.text-neutral-600');      if (percentEl) {        const text = percentEl.textContent;        const match = text.match(/(\d+(?:\.\d+)?)%/);        if (match) {          percentage = parseFloat(match[1]);        }      }    }        // 根据百分比设置颜色    if (percentage >= 100) {      bar.style.background = 'linear-gradient(90deg, #6b7280 0%, #4b5563 100%)'; // 灰色    } else if (percentage >= 90) {      bar.style.background = 'linear-gradient(90deg, #ef4444 0%, #dc2626 100%)'; // 红色    } else if (percentage >= 70) {      bar.style.background = 'linear-gradient(90deg, #fbbf24 0%, #f59e0b 100%)'; // 黄色    } else {      bar.style.background = 'linear-gradient(90deg, #10b981 0%, #059669 100%)'; // 绿色    }  });}/** * 初始化流量监控进度条颜色功能 */function initTrafficProgressColors() {  // 创建样式  const style = document.createElement('style');  style.textContent = `    /* 流量监控进度条颜色样式 */    .traffic-progress-warning {      background: linear-gradient(90deg, #fbbf24 0%, #f59e0b 100%) !important;    }        .traffic-progress-danger {      background: linear-gradient(90deg, #ef4444 0%, #dc2626 100%) !important;    }        .traffic-progress-critical {      background: linear-gradient(90deg, #6b7280 0%, #4b5563 100%) !important;    }        .traffic-progress-normal {      background: linear-gradient(90deg, #10b981 0%, #059669 100%) !important;    }  `;  document.head.appendChild(style);    // 延迟执行,确保页面加载完成  setTimeout(updateTrafficProgressColors, 1000);  setTimeout(updateTrafficProgressColors, 3000);}// 在页面加载完成后初始化流量监控功能document.addEventListener('DOMContentLoaded', initTrafficProgressColors);// 如果页面已经加载,立即执行if (document.readyState === 'loading') {  document.addEventListener('DOMContentLoaded', initTrafficProgressColors);} else {  initTrafficProgressColors();}</script>