// ==UserScript== // @name CDN & Server Info Displayer (Enhanced Recognition) // @name:en CDN & Server Info Displayer (Enhanced Recognition) // @namespace http://tampermonkey.net/ // @version 5.4.0 // @description [v5.4.0 规则增强] 新增对腾讯云 EdgeOne 的精确识别规则,修正了之前版本中可能将明确命中误判为疑似命中的问题。感谢用户反馈! // @description:en [v5.4.0 Rule Enhancement] Added specific recognition for Tencent Cloud EdgeOne, fixing an issue where a definite hit could be misidentified as inferred. Thanks to user feedback! // @author Gemini (AI Rule Enhancement) // @license MIT // @match *://*/* // @grant GM_addStyle // @run-at document-idle // @downloadURL none // ==/UserScript== (function() { 'use strict'; // --- Configuration (Unchanged) --- const config = { initialPosition: { bottom: '20px', right: '20px' }, minWindowSize: { width: 400, height: 300 }, initial_delay: 2500, retry_delay: 7000, max_retries: 4, excludePatterns: [ /* ... */ ] }; window.cdnScriptStatus = window.cdnScriptStatus || {}; // --- Core Info Parsing Functions --- function getCacheStatus(h) { // NEW: Add x-cache-lookup to the primary check list const headersToCheck = [ h.get('x-cache-lookup'), // <--- 新增 h.get('cache-status'), h.get('x-cache-status'), h.get('x-cache'), h.get('x-edge-cache-status'), h.get('x-sucuri-cache'), h.get('x-vercel-cache'), h.get('x-qc-cache'), h.get('cf-cache-status'), h.get('x-response-cache'), h.get('x-bdcdn-cache-status'), h.get('cdn-cache'), h.get('bunny-cache-state') ]; for (const value of headersToCheck) { if (!value) continue; const upperVal = value.toUpperCase(); if (upperVal.includes('HIT')) return 'HIT'; if (upperVal.includes('MISS')) return 'MISS'; if (upperVal.includes('BYPASS')) return 'BYPASS'; if (upperVal.includes('DYNAMIC')) return 'DYNAMIC'; if (upperVal.includes('UPDATING')) return 'UPDATING'; if (upperVal.includes('STALE')) return 'STALE'; if (upperVal.includes('EXPIRED')) return 'EXPIRED'; } if (parseInt(h.get('age'), 10) > 0) return 'HIT (inferred)'; return 'N/A'; } // --- NEW: Updated cdnProviders object --- const cdnProviders = { 'Tencent EdgeOne': { serverHeaders: ['edgeone-pages'], headers: ['x-nws-log-uuid'], priority: 10, getInfo: (h) => { let cache = 'N/A'; const lookup = h.get('x-cache-lookup'); // Prioritize this header if (lookup) { cache = lookup.replace('Cache ', '').toUpperCase(); } else { cache = getCacheStatus(h); } return { provider: 'Tencent EdgeOne', cache: cache, pop: 'N/A', extra: `Log-UUID: ${h.get('x-nws-log-uuid') || 'N/A'}` }; } }, 'Cloudflare':{headers:['cf-ray'],serverHeaders:['cloudflare'],priority:10,getInfo:(h)=>({provider:'Cloudflare',cache:h.get('cf-cache-status')?.toUpperCase()||'N/A',pop:h.get('cf-ray')?.slice(-3).toUpperCase()||'N/A',extra:`Ray ID: ${h.get('cf-ray')||'N/A'}`})}, 'AWS CloudFront':{headers:['x-amz-cf-pop','x-amz-cf-id'],priority:9,getInfo:(h)=>({provider:'AWS CloudFront',cache:getCacheStatus(h),pop:(h.get('x-amz-cf-pop')||'N/A').substring(0,3),extra:`CF ID: ${h.get('x-amz-cf-id')||'N/A'}`})}, 'Fastly':{headers:['x-fastly-request-id','x-served-by'],priority:9,getInfo:(h)=>({provider:'Fastly',cache:getCacheStatus(h),pop:h.get('x-served-by')?.split('-').pop()||'N/A',extra:`ReqID: ${h.get('x-fastly-request-id')||'N/A'}`})}, 'Vercel':{headers:['x-vercel-id'],priority:10,getInfo:(h)=>{let pop='N/A';const vercelId=h.get('x-vercel-id');if(vercelId){const regionPart=vercelId.split('::')[0];const match=regionPart.match(/^[a-zA-Z]+/);if(match)pop=match[0].toUpperCase();}return{provider:'Vercel',cache:getCacheStatus(h),pop:pop,extra:`ID: ${h.get('x-vercel-id')||'N/A'}`};}}, }; function parseInfo(h) { const lowerCaseHeaders=new Map();for(const[key,value]of h.entries()){lowerCaseHeaders.set(key.toLowerCase(),value);}let detectedProviders=[];for(const[_,cdn]of Object.entries(cdnProviders)){let isMatch=false;if(cdn.headers?.some(header=>lowerCaseHeaders.has(header.toLowerCase())))isMatch=true;if(!isMatch&&cdn.serverHeaders?.some(server=>(lowerCaseHeaders.get('server')||'').toLowerCase().includes(server.toLowerCase())))isMatch=true;if(isMatch)detectedProviders.push({...cdn.getInfo(lowerCaseHeaders),priority:cdn.priority||5});}if(detectedProviders.length>0){detectedProviders.sort((a,b)=>b.priority-a.priority);return detectedProviders[0];}const server=lowerCaseHeaders.get('server');if(server)return{provider:server,cache:getCacheStatus(lowerCaseHeaders),pop:'N/A',extra:'No CDN detected'};return{provider:'Unknown',cache:'N/A',pop:'N/A',extra:'No CDN or Server info'}; } // --- UI & Execution Functions (Unchanged) --- function getPanelCSS() { return ` :host { all: initial; position: fixed; z-index: 2147483647; bottom: ${config.initialPosition.bottom}; right: ${config.initialPosition.right}; } #cdn-info-panel-enhanced { position: relative; min-width: 270px; padding: 20px 24px; border-radius: 18px; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif; background: rgba(255, 255, 255, 0.65); backdrop-filter: blur(20px) saturate(110%); -webkit-backdrop-filter: blur(20px) saturate(110%); border: 1px solid rgba(0, 0, 0, 0.1); box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15); cursor: move; user-select: none; transition: transform 0.2s ease, box-shadow 0.2s ease; } #cdn-info-panel-enhanced:hover { transform: translateY(-4px); box-shadow: 0 15px 35px rgba(0, 0, 0, 0.18); } .close-btn { position: absolute; top: 8px; right: 8px; width: 22px; height: 22px; border-radius: 50%; background: rgba(0,0,0,0.05); color: rgba(0,0,0,0.5); border: none; cursor: pointer; font-size: 14px; display: flex; align-items: center; justify-content: center; transition: all 0.2s; line-height: 22px; z-index: 2;} .close-btn:hover { background: rgba(0,0,0,0.1); color: #000; } .panel-header { font-size: 13px; font-weight: 600; color: #555; text-align: center; margin-bottom: 16px; padding-bottom: 12px; border-bottom: 1px solid rgba(0, 0, 0, 0.1); } .info-line { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; font-size: 14px; } .info-line:last-child { margin-bottom: 0; } .info-label { font-weight: 400; color: #666; } .info-value { font-weight: 600; color: #222; } .cache-HIT { color: #059669 !important; } .cache-MISS { color: #be185d !important; } `; } function createDisplayPanel(info) { if (!info || document.getElementById('cdn-info-host-enhanced')) return; const host = document.createElement('div'); host.id = 'cdn-info-host-enhanced'; document.body.appendChild(host); const shadowRoot = host.attachShadow({ mode: 'open' }); const styleEl = document.createElement('style'); styleEl.textContent = getPanelCSS(); shadowRoot.appendChild(styleEl); const panel = document.createElement('div'); panel.id = 'cdn-info-panel-enhanced'; const cacheStatus = info.cache.toUpperCase(); const providerLabel = info.provider.includes('CDN') || info.provider.includes('Cloud') || info.provider.includes('EdgeOne') ? 'CDN Provider' : 'Server'; panel.innerHTML = `