Greasy Fork

Greasy Fork is available in English.

LLMs.txt Detector(排除 text/html & 空文件)

检测 llms.txt;空文件或 text/html 一律忽略,不显示、不提醒

当前为 2025-11-04 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==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
// ==/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 = `
      <div style="margin-bottom:10px;font-weight:bold;color:#333">🔍 LLMs.txt 检测结果
        <button onclick="this.parentElement.parentElement.style.display='none'" style="float:right;background:#f0f0f0;border:none;border-radius:4px;padding:2px 6px;cursor:pointer;font-size:12px">×</button>
      </div>
      <div style="margin-bottom:8px">✅ 找到 ${found.length} 个文件:</div>
      ${found.map(r => `
        <div class="file-row" style="display:flex;align-items:center;margin:6px 0;padding:6px;background:#e8f5e8;border-radius:4px">
          <div style="flex:1">
            <a href="${r.url}" target="_blank" style="color:#2d7d2d;text-decoration:none">📄 ${r.file}</a>
            <div style="font-size:11px;color:#666;margin-top:2px">状态 ${r.status} · 长度 ${r.len ?? '-'} · 类型 ${r.mime ?? '-'}</div>
          </div>
          <button data-url="${r.url}" class="copy-btn" style="margin-left:6px;background:#007cba;color:#fff;border:none;padding:4px 8px;border-radius:4px;font-size:12px;cursor:pointer;display:none">复制</button>
        </div>`).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);
})();