自动跳转itdog
不知道通用不通用

// ==UserScript==// @name         哪吒探针后台 IP Ping 按钮// @namespace    http://tampermonkey.net/// @version      5.3// @description  在哪吒探针后台页面的 IP 地址后方插入 Ping 按钮// @author       gpt// @match        *://*/*// @grant        none// ==/UserScript==(function () {  'use strict';  // 判断是否为哪吒探针页面  function isNezhaPage() {    const title = document.title.toLowerCase();    const body = document.body?.innerText?.toLowerCase() || "";    return title.includes("哪吒") || title.includes("nezha") ||           body.includes("哪吒探针") || body.includes("nezha");  }  if (!isNezhaPage()) return;  // 样式  const style = document.createElement('style');  style.textContent = `    .nezha-ping-btn {      display:inline-flex; align-items:center; justify-content:center;      height:18px; line-height:18px; font-size:11px; padding:0 6px;      margin-left:6px; border-radius:6px; cursor:pointer; user-select:none;      border:1px solid var(--nz-ping-border,#ccc);      background:var(--nz-ping-bg,#f5f5f5); color:var(--nz-ping-fg,#000);      vertical-align:middle; text-decoration:none;    }    .nezha-ping-btn:hover { filter:brightness(0.95); }    html.dark .nezha-ping-btn {      --nz-ping-border:#555; --nz-ping-bg:#2f2f2f; --nz-ping-fg:#fff;    }    .nezha-ip-frag { white-space:pre-wrap; }  `;  document.head.appendChild(style);  // IPv4 正则  const ipv4 = /\b(?:(?:25[0-5]|2[0-4]\d|1?\d{1,2})\.){3}(?:25[0-5]|2[0-4]\d|1?\d{1,2})\b/;  // IPv6 正则(匹配完整连续 IPv6,包括 :: 压缩)  const ipv6 = /\b(?:[0-9A-Fa-f]{1,4}:){1,7}[0-9A-Fa-f]{0,4}\b|::/g;  // 判断 IP 类型  function isIPv4(ip) {    return ipv4.test(ip);  }  function getPingUrl(ip) {    return isIPv4(ip)      ? `https://www.itdog.cn/ping/${ip}`      : `https://www.itdog.cn/ping_ipv6/${ip}`;  }  // 获取 IP 列索引  function getIpColIndex() {    const ths = document.querySelectorAll('thead th');    for (let i = 0; i < ths.length; i++) {      const txt = ths[i].textContent.trim().toLowerCase();      if (txt === 'ip') return i;    }    return -1;  }  // 提取完整 IP(处理 IPv6 被换行截断的情况)  function extractIPs(text) {    // 移除换行空格,避免被拆    const normalized = text.replace(/\s+/g, '');    const results = [];    // 匹配 IPv4    const v4s = normalized.match(new RegExp(ipv4, 'g')) || [];    results.push(...v4s);    // 匹配 IPv6    const v6s = normalized.match(new RegExp(/([0-9A-Fa-f]{0,4}:){2,7}[0-9A-Fa-f]{0,4}|::/g, 'g')) || [];    results.push(...v6s);    return [...new Set(results)];  }  // 插入按钮  function injectPingAfterIP(container) {    if (container.dataset.nzPingProcessed === '1') return;    const text = container.textContent;    const ips = extractIPs(text);    if (ips.length === 0) return;    const frag = document.createDocumentFragment();    frag.appendChild(document.createTextNode(text));    ips.forEach(ip => {      const a = document.createElement('a');      a.className = 'nezha-ping-btn';      a.textContent = 'Ping';      a.href = getPingUrl(ip);      a.target = '_blank';      a.rel = 'noopener noreferrer';      frag.appendChild(a);    });    container.replaceChildren(frag);    container.classList.add('nezha-ip-frag');    container.dataset.nzPingProcessed = '1';  }  // 处理表格  function processTable() {    const ipCol = getIpColIndex();    const rows = document.querySelectorAll('tbody tr');    rows.forEach(tr => {      let targets = [];      if (ipCol >= 0 && tr.children[ipCol]) {        targets = [tr.children[ipCol]];      } else {        targets = Array.from(tr.querySelectorAll('td'));      }      targets.forEach(node => {        if (!node.textContent) return;        if (node.querySelector('.nezha-ping-btn')) return;        injectPingAfterIP(node);      });    });  }  // 初次运行  processTable();  // 监听 DOM 变化  let scheduled = false;  const observer = new MutationObserver(() => {    if (scheduled) return;    scheduled = true;    setTimeout(() => {      scheduled = false;      processTable();    }, 200);  });  observer.observe(document.body, { childList: true, subtree: true, characterData: true });  // 定时兜底  setInterval(processTable, 4000);})();