// ==UserScript== // @name LLMs.txt Detector(排除 text/html & 空文件) // @namespace http://tampermonkey.net/ // @version 1.8 // @description 检测 llms.txt;空文件或 text/html 一律忽略,不显示、不提醒 // @author TinsFox // @match *://*/* // @license MIT // @grant GM_xmlhttpRequest // @downloadURL none // ==/UserScript== (() => { 'use strict'; const filesToCheck = [ 'llms.txt', 'llms-full.txt', 'LLMS.txt', 'LLMS-FULL.txt', '.well-known/llms.txt', '.well-known/llms-full.txt' ]; const base = location.origin.replace(/\/$/, ''); const toast = m => { const d = document.createElement('div'); d.textContent = m; d.style = `position:fixed;top:50%;left:50%;transform:translate(-50%,-50%);background:#111;color:#fff;padding:8px 14px;border-radius:6px;font-size:14px;z-index:99999;transition:.2s;opacity:0`; document.body.appendChild(d); requestAnimationFrame(() => d.style.opacity = 1); setTimeout(() => (d.style.opacity = 0, setTimeout(() => d.remove(), 200)), 1500); }; const panel = (() => { const p = document.createElement('div'); p.id = 'llms-panel-' + Math.random().toString(36).slice(2, 8); p.style = `position:fixed;top:20px;right:20px;width:360px;background:#fff;border:2px solid #007cba;border-radius:8px;padding:12px;box-shadow:0 4px 12px rgba(0,0,0,.15);font:14px/1.4 -apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,sans-serif;z-index:10000;display:none`; document.body.appendChild(p); return p; })(); const show = found => { panel.innerHTML = `
🔍 LLMs.txt 检测结果
✅ 找到 ${found.length} 个文件:
${found.map(r => `
📄 ${r.file}
状态 ${r.status} · 长度 ${r.len ?? '-'} · 类型 ${r.mime ?? '-'}
`).join('')}`; panel.style.display = 'block'; panel.querySelectorAll('.file-row').forEach(row => { const btn = row.querySelector('.copy-btn'); row.addEventListener('mouseenter', () => btn.style.display = 'inline-block'); row.addEventListener('mouseleave', () => btn.style.display = 'none'); btn.addEventListener('click', e => { e.preventDefault(); navigator.clipboard.writeText(btn.dataset.url).then(() => toast('已复制')); }); }); }; const check = f => new Promise(r => { const u = `${base}/${f.replace(/^\//, '')}`; const cb = (ok, st, len, mime) => { // 过滤:空文件 或 text/html 一律视为不存在 const reallyOk = ok && (len > 0) && !mime.includes('text/html'); r({file: f, url: u, found: reallyOk, status: st, len, mime}); }; if (typeof GM_xmlhttpRequest !== 'undefined') { GM_xmlhttpRequest({ method: 'HEAD', url: u, onload: x => cb(x.status >= 200 && x.status < 300, x.status, parseInt(x.responseHeaders.match(/content-length:\s*(\d+)/i)?.[1] || 0, 10), x.responseHeaders.match(/content-type:\s*([^;\r\n]+)/i)?.[1].trim() ?? ''), onerror: x => cb(false, x.status || 'error', 0, '') }); } else { fetch(u, {method: 'HEAD'}) .then(x => { const len = parseInt(x.headers.get('content-length') || 0, 10); const mime = x.headers.get('content-type')?.split(';')[0].trim() || ''; cb(x.ok, x.status, len, mime); }) .catch(() => cb(false, 'error', 0, '')); } }); const run = () => Promise.all(filesToCheck.map(check)).then(res => { const found = res.filter(r => r.found); if (found.length) { show(found); if (!document.getElementById(panel.id + '-btn')) { const b = document.createElement('div'); b.id = panel.id + '-btn'; b.textContent = '📄 LLMs.txt'; b.style = `position:fixed;bottom:20px;right:20px;background:#007cba;color:#fff;padding:8px 12px;border-radius:20px;font-size:12px;cursor:pointer;box-shadow:0 2px 8px rgba(0,0,123,.3);z-index:10000`; b.onclick = () => panel.style.display = panel.style.display === 'none' ? 'block' : 'none'; document.body.appendChild(b); } } }); document.addEventListener('keydown', e => { if (e.ctrlKey && e.shiftKey && e.key === 'L') { e.preventDefault(); run(); } }); if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', () => setTimeout(run, 1000)); else setTimeout(run, 1000); })();