tp-wen / fail link show

// ==UserScript==
// @name         fail link show
// @namespace    tp-wen@tepeng.com
// @version      0.1
// @match        *://*.3d66.com/*
// @updateURL https://openuserjs.org/meta/tp-wen/fail_link_show.meta.js
// @downloadURL https://openuserjs.org/install/tp-wen/fail_link_show.user.js
// @grant        none
// @copyright 2026, tp-wen (https://openuserjs.org/users/tp-wen)
// @license MIT
// ==/UserScript==

(() => {
  "use strict";

  const STYLE_ID = "__query_only_mark_style__";
  const MARK_CLASS = "__query_only_mark";
  const BADGE_CLASS = "__query_only_badge";

  const ensureStyle = () => {
    if (document.getElementById(STYLE_ID)) return;
    const styleEl = document.createElement("style");
    styleEl.id = STYLE_ID;
    styleEl.textContent = `
      a.${MARK_CLASS}{
        outline:none !important;
      }
      a.${MARK_CLASS} .${BADGE_CLASS}{
        position:absolute !important;top:2px !important;right:2px !important;z-index:99999 !important;
        pointer-events:none !important;
        display:inline-flex !important;align-items:center !important;justify-content:center !important;
        width:12px !important;height:12px !important;
        font-size:10px !important;line-height:1 !important;border-radius:999px !important;
        color:rgba(229,57,53,.9) !important;
        background:rgba(229,57,53,.5) !important;
        border:1px solid rgba(229,57,53,.5) !important;
      }
    `;
    document.head.appendChild(styleEl);
  };

  const isQueryOnlyHref = (href) => {
    if (!href) return false;
    const trimmed = href.trim();
    return trimmed.startsWith("?");
  };

  const applyBadges = () => {
    ensureStyle();
    document.querySelectorAll("a[href]").forEach((a) => {
      const rawHref = a.getAttribute("href") || "";
      const isQueryOnly = isQueryOnlyHref(rawHref);
      const badge = a.querySelector(`.${BADGE_CLASS}`);
      if (!isQueryOnly) {
        a.classList.remove(MARK_CLASS);
        badge?.remove();
        return;
      }

      a.classList.add(MARK_CLASS);
      const computed = getComputedStyle(a);
      if (computed.position === "static") {
        a.style.position = "relative";
      }
      if (!badge) {
        const nextBadge = document.createElement("span");
        nextBadge.className = BADGE_CLASS;
        nextBadge.textContent = "✖";
        nextBadge.style.cssText =
          "position:absolute;top:2px;right:2px;z-index:99999;pointer-events:none;display:inline-flex;align-items:center;justify-content:center;width:12px;height:12px;font-size:10px;line-height:1;border-radius:999px;color:rgba(229,57,53,.55);background:rgba(229,57,53,.12);border:1px solid rgba(229,57,53,.35);box-shadow:0 0 0 1px rgba(0,0,0,.08);";
        a.appendChild(nextBadge);
      }
    });
  };

  let rafId = null;
  const scheduleApply = () => {
    if (rafId) return;
    rafId = requestAnimationFrame(() => {
      rafId = null;
      applyBadges();
    });
  };

  const observer = new MutationObserver(() => scheduleApply());
  observer.observe(document.documentElement, { subtree: true, childList: true, attributes: true });

  if (document.readyState === "loading") {
    document.addEventListener("DOMContentLoaded", () => applyBadges(), { once: true });
  } else {
    applyBadges();
  }
})();