跳到正文

个人记录

低调的黑客

liangbowen约 6 分钟
原文
文章信息与版本

文章信息

发布
2025年10月23日
收录
2025年12月12日
更新
2026年9月19日
篇幅
约 6 分钟

版本

  1. v2当前
  2. v1

AI 写的。

JavaScript
// ==UserScript==
// @name         洛谷低调的黑客识别工具
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  识别洛谷中低调的黑客
// @author       Copilot
// @match        *://*.luogu.com.cn/user/*
// @grant        none
// ==/UserScript==
(function () {
  const imgUrl = 'https://cdn.luogu.com.cn/upload/image_hosting/osxsoed9.png';
  const originalText = '该用户设置了完全隐私保护,无法查看练习记录';
  const newText = '该用户是低调的黑客,无法查看练习记录';
  const extraLine = '低调的黑客:我猜你在浏览我的个人主页';

  // 注入闪烁动画样式
  const injectStyle = () => {
    if (document.getElementById('copilot-blink-style')) return;
    const style = document.createElement('style');
    style.id = 'copilot-blink-style';
    style.textContent = `
      @keyframes blink {
        0%, 50%, 100% { opacity: 1; }
        25%, 75% { opacity: 0; }
      }
      .copilot-blink {
        animation: blink 3s infinite;
        color: red;
        margin-top: 0.5em;
      }
    `;
    document.head.appendChild(style);
  };

  const replaceSvg = () => {
    document.querySelectorAll('svg.fa-user-secret').forEach(svg => {
      if (svg.dataset.replaced) return;
      const s = getComputedStyle(svg);
      const w = parseFloat(s.width) * 1.5;
      const h = parseFloat(s.height) * 1.5;
      const img = new Image();
      img.src = imgUrl;
      img.alt = 'user-secret';
      img.style.width = w + 'px';
      img.style.height = h + 'px';
      svg.replaceWith(img);
      svg.dataset.replaced = 'true';
    });
  };

  const replaceText = () => {
    document.querySelectorAll('*').forEach(el => {
      if (el.childNodes.length === 1 && el.childNodes[0].nodeType === 3) {
        if (el.textContent.includes(originalText)) {
          el.textContent = '';
          const line1 = document.createElement('div');
          line1.textContent = newText;

          const line2 = document.createElement('div');
          line2.textContent = extraLine;
          line2.className = 'copilot-blink';

          el.appendChild(line1);
          el.appendChild(line2);
        }
      }
    });
  };

  const runPatch = () => {
    injectStyle();
    replaceSvg();
    replaceText();
  };

  const waitForButton = () => {
    const buttons = Array.from(document.querySelectorAll('span, a, button, div'));
    const target = buttons.find(el => el.textContent.trim() === '练习');
    if (target) {
      target.addEventListener('click', () => {
        setTimeout(runPatch, 500);
      });
    } else {
      setTimeout(waitForButton, 500);
    }
  };

  // 监听 URL 变化以支持 SPA 跳转
  let lastUrl = location.href;
  const observeUrlChange = () => {
    const observer = new MutationObserver(() => {
      if (location.href !== lastUrl) {
        lastUrl = location.href;
        if (/\/user\/[^/]+\/practice/.test(location.href)) {
          runPatch();
        }
      }
    });
    observer.observe(document.body, { childList: true, subtree: true });
  };

  // 初始加载判断是否为 practice 页面
  if (/\/user\/[^/]+\/practice/.test(location.href)) {
    runPatch();
  }

  // 启动监听
  observeUrlChange();
  waitForButton();
})();
原文
存档评论1 条抓取于