/* ===== Ping 延迟区域 ===== */ .exia-ping-container { width: 100%; padding: 6px 10px; background: rgba(0, 0, 0, 0.5); border-top: 1px solid rgba(128, 128, 128, 0.3); backdrop-filter: blur(8px); margin-top: auto; display: flex; justify-content: center; align-items: center; } .exia-ping-title { display: none; } .exia-ping-list { display: flex; flex-wrap: nowrap; gap: 6px; font-size: 10px; justify-content: center; align-items: center; } .exia-ping-item { padding: 4px 10px; border-radius: 5px; font-weight: 700; white-space: nowrap; border: 1px solid; backdrop-filter: blur(5px); flex-shrink: 0; transition: all 0.2s ease; } .exia-ping-item:hover { transform: translateY(-1px); box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2); } /* 延迟等级颜色 - 通用配色 */ .exia-ping-excellent { color: #10b981; border-color: rgba(16, 185, 129, 0.5); background: rgba(16, 185, 129, 0.1); } .exia-ping-good { color: #3b82f6; border-color: rgba(59, 130, 246, 0.5); background: rgba(59, 130, 246, 0.1); } .exia-ping-fair { color: #f59e0b; border-color: rgba(245, 158, 11, 0.5); background: rgba(245, 158, 11, 0.1); } .exia-ping-poor { color: #f97316; border-color: rgba(249, 115, 22, 0.5); background: rgba(249, 115, 22, 0.1); } .exia-ping-bad { color: #ef4444; border-color: rgba(239, 68, 68, 0.5); background: rgba(239, 68, 68, 0.1); } /* 让VPS卡片支持底部对齐 */ .purcarte-blur.theme-card-style:has(a[href*="/instance/"]) { display: flex !important; flex-direction: column !important; }
const EXIA_PING_CONFIG = { enabled: true, // 是否启用筛选 keywords: ['电信', '移动', '联通'], // 要显示的线路关键词 matchMode: 'include', // 匹配模式: 'include'(包含) 或 'exact'(精确) hours: 1, // 数据时间范围(小时) refreshInterval: 180000 // 刷新间隔(毫秒,默认3分钟) }; // ==================================== async function fetchKomariPingData(uuid) { try { const response = await fetch(`/api/records/ping?uuid=${uuid}&hours=${EXIA_PING_CONFIG.hours}`); if (!response.ok) return null; const result = await response.json(); if (result.status !== 'success' || !result.data.records.length) { return null; } const records = result.data.records; const tasks = result.data.tasks; const taskPings = {}; tasks.forEach(task => { // 应用筛选规则 if (EXIA_PING_CONFIG.enabled) { const shouldShow = EXIA_PING_CONFIG.keywords.some(keyword => { if (EXIA_PING_CONFIG.matchMode === 'exact') { return task.name === keyword; } else { return task.name.includes(keyword); } }); if (!shouldShow) return; } // 计算平均延迟 const taskRecords = records.filter(r => r.task_id === task.id && r.value > 0); if (taskRecords.length > 0) { const avgPing = taskRecords.reduce((sum, r) => sum + r.value, 0) / taskRecords.length; taskPings[task.name] = { ping: avgPing, loss: task.loss }; } }); return taskPings; } catch (error) { console.error(`❌ 获取 ${uuid} 延迟失败:`, error); return null; } } function getExiaPingClass(ping) { if (ping < 20) return 'exia-ping-excellent'; if (ping < 50) return 'exia-ping-good'; if (ping < 100) return 'exia-ping-fair'; if (ping < 200) return 'exia-ping-poor'; return 'exia-ping-bad'; } async function addExiaPingBadges() { const cards = document.querySelectorAll('.purcarte-blur.theme-card-style.text-card-foreground'); if (cards.length === 0) return false; for (const card of cards) { // 跳过离线服务器 const serverName = card.querySelector('h3.tracking-tight.text-base.font-bold'); if (!serverName) continue; // 检查是否离线(多种判断方式) if (serverName.classList.contains('offline') || serverName.classList.contains('exia-offline') || card.querySelector('.offline')) { continue; } // 提取UUID const link = card.querySelector('a[href*="/instance/"]'); if (!link) continue; const match = link.href.match(/\/instance\/([a-f0-9-]+)/); if (!match) continue; const uuid = match[1]; // 跳过已有Ping数据的卡片 if (card.querySelector('.exia-ping-container')) continue; // 获取Ping数据 const taskPings = await fetchKomariPingData(uuid); if (taskPings && Object.keys(taskPings).length > 0) { // 创建容器 const container = document.createElement('div'); container.className = 'exia-ping-container'; // 创建列表 const list = document.createElement('div'); list.className = 'exia-ping-list'; // 添加每个线路的延迟标签 Object.entries(taskPings).forEach(([taskName, data]) => { const item = document.createElement('div'); item.className = `exia-ping-item ${getExiaPingClass(data.ping)}`; // 简化显示名称(去掉常见前缀) const shortName = taskName .replace(/^(珠海|广东|上海|北京|深圳|香港|台湾)/, '') .trim(); item.innerHTML = `${shortName} ${data.ping.toFixed(1)}ms`; item.title = `${taskName}\n平均延迟: ${data.ping.toFixed(1)}ms\n丢包率: ${data.loss}%`; list.appendChild(item); }); container.appendChild(list); card.appendChild(container); console.log(`✅ ${serverName.textContent.trim()}: ${Object.keys(taskPings).length} 条线路`); } // 控制请求频率 await new Promise(resolve => setTimeout(resolve, 50)); } return true; } function waitForCards(maxAttempts = 10, interval = 500) { return new Promise((resolve) => { let attempts = 0; const check = () => { const cards = document.querySelectorAll('.purcarte-blur.theme-card-style.text-card-foreground'); if (cards.length > 0) { console.log(`✅ EXIA: 找到 ${cards.length} 个VPS卡片`); resolve(true); } else { attempts++; if (attempts >= maxAttempts) { console.warn('⚠️ EXIA: 未找到VPS卡片'); resolve(false); } else { setTimeout(check, interval); } } }; check(); }); } // 初始化EXIA Ping系统 setTimeout(async () => { console.log('🚀 GUNDAM EXIA - Ping延迟系统启动...'); console.log(`📊 EXIA配置: ${EXIA_PING_CONFIG.hours}小时数据 | 筛选: ${EXIA_PING_CONFIG.keywords.join(', ')}`); const cardsLoaded = await waitForCards(); if (cardsLoaded) { await addExiaPingBadges(); console.log('✅ EXIA: Ping数据加载完成!'); // 定时刷新 setInterval(async () => { console.log('🔄 EXIA: 刷新Ping数据...'); document.querySelectorAll('.exia-ping-container').forEach(c => c.remove()); await addExiaPingBadges(); }, EXIA_PING_CONFIG.refreshInterval); } }, 3000);