"侦探"标签摆在面前你没拿下,后悔莫及?不用等一万年!(娱乐版)
// ==UserScript==
// @name NodeSeek 侦探标签渲染器 (温和极速版)
// @namespace https://www.nodeseek.com/
// @version 0.5.0
// @description 脱离第三方元素依赖,原生温和挂载,无全量扫描,超低内存与 CPU 占用
// @match https://www.nodeseek.com/*
// @match https://www.deepflood.com/*
// @run-at document-idle
// @grant none
// @license MIT
// ==/UserScript==
(() => {
"use strict";
// 1. 目标 UID 配置
const DETECTIVE_UIDS = ["38057"];
const BADGE_CLASS = "nsk-detective-badge";
// 2. 注入轻量样式
function injectStyle() {
if (document.getElementById("nsk-detective-style")) return;
const style = document.createElement("style");
style.id = "nsk-detective-style";
style.textContent = `
.${BADGE_CLASS} {
display: inline-flex;
align-items: center;
justify-content: center;
padding: 1px 5px;
margin-left: 6px;
font-size: 11px;
line-height: 14px;
height: 18px;
color: #333333;
border: 1px solid rgba(0, 0, 0, 0.35);
border-radius: 4px;
background: linear-gradient(180deg, #ffffff 0%, #f3f3f3 100%);
box-shadow: 0 1px 2px rgba(0,0,0,0.06);
letter-spacing: 0.5px;
font-weight: 500;
vertical-align: middle;
user-select: none;
box-sizing: border-box;
}
@media (prefers-color-scheme: dark) {
.${BADGE_CLASS} {
color: #e0e0e0;
border-color: rgba(255, 255, 255, 0.3);
background: linear-gradient(180deg, rgba(255, 255, 255, 0.12) 0%, rgba(255, 255, 255, 0.04) 100%);
box-shadow: 0 1px 2px rgba(0,0,0,0.25);
}
}
`;
document.head.appendChild(style);
}
// 3. 核心挂载逻辑(直接基于原生 .author-info 容器)
function processAuthorInfo(container) {
if (!(container instanceof HTMLElement)) return;
if (container.querySelector(`.${BADGE_CLASS}`)) return;
// 锁定当前作者的原生主页链接(排除悬浮卡片等杂项)
const authorLink = container.querySelector("a[href^='/space/']:not(.nsx-user-info-display a)");
if (!authorLink) return;
const match = (authorLink.getAttribute("href") || "").match(/\/space\/(\d+)/);
if (!match) return;
const uid = match[1];
if (DETECTIVE_UIDS.length > 0 && !DETECTIVE_UIDS.includes(uid)) return;
// 创建标签
const badge = document.createElement("span");
badge.className = BADGE_CLASS;
badge.textContent = "侦探";
badge.title = `侦探认证 (UID: ${uid})`;
// 温和追加至作者信息行末尾(无论是否有管理记录或楼主标,均自动排在最后)
container.appendChild(badge);
}
// 4. 增量节点扫描
function scanNodes(root = document) {
if (!root || !root.querySelectorAll) return;
const targets = root.querySelectorAll(".author-info, .info-author");
for (let i = 0; i < targets.length; i++) {
processAuthorInfo(targets[i]);
}
}
// 5. 温和监听器(仅处理新增节点,拒绝全局扫描)
function init() {
injectStyle();
scanNodes(document);
const observer = new MutationObserver((mutations) => {
for (const m of mutations) {
for (const node of m.addedNodes) {
if (node.nodeType !== 1) continue; // 仅处理 ELEMENT_NODE
if (node.classList?.contains(BADGE_CLASS) || node.classList?.contains("layui-layer")) continue;
if (node.matches?.(".author-info, .info-author")) {
processAuthorInfo(node);
} else if (node.querySelectorAll) {
scanNodes(node);
}
}
}
});
// 仅监听主体内容区
const targetArea = document.querySelector(".nsk-container, #nsk-body, main") || document.body;
observer.observe(targetArea, { childList: true, subtree: true });
}
if (document.readyState === "loading") {
document.addEventListener("DOMContentLoaded", init, { once: true });
} else {
init();
}
})();