Northie / 新版河畔修改svg水印内容

// ==UserScript==
// @name         新版河畔修改svg水印内容
// @namespace    https://openuserjs.org/users/Northie
// @version      2026.02.04
// @description  新版河畔修改水印内容
// @author       Northie
// @copyright    2026, Northie (https://openuserjs.org/users/Northie)
// @license      GPL-3.0-or-later; https://www.gnu.org/licenses/gpl-3.0.txt
// @homepageURL  https://github.com/WhyPilotXia/Crack-SVG-watermark-for-bbs.uestc.edu.cn
// @supportURL   https://github.com/WhyPilotXia/Crack-SVG-watermark-for-bbs.uestc.edu.cn/issues
// @match        https://bbs.uestc.edu.cn/*
// @grant        none
// @run-at       document-start
// ==/UserScript==

// ==OpenUserJS==
// @author       Northie
// ==/OpenUserJS==

(function () {
  const OLD_TEXT = '9999'   // 改成你自己ID
  const NEW_TEXT = '114514'

  function rewriteBackgroundImage(style) {
    if (!style || !style.backgroundImage) return

    const bg = style.backgroundImage
    if (!bg.includes('data:image/svg+xml;base64,')) return

    const base64 = bg.match(/base64,([^")]+)/)?.[1]
    if (!base64) return

    try {
      const svg = decodeURIComponent(escape(atob(base64)))

      console.log(svg);

      if (!svg.includes(OLD_TEXT)) return

      const modifiedSvg = svg.replaceAll(OLD_TEXT, NEW_TEXT)

      const newBase64 = btoa(
        unescape(encodeURIComponent(modifiedSvg))
      )

      style.backgroundImage =
        `url("data:image/svg+xml;base64,${newBase64}")`

      console.log('[WM] watermark rewritten:', OLD_TEXT, '→', NEW_TEXT)
    } catch (e) {
      console.warn('[WM] rewrite failed', e)
    }
  }

  const rawAppend = Element.prototype.appendChild
  const rawInsert = Element.prototype.insertBefore

  function handleNode(node) {
    if (!(node instanceof HTMLElement)) return
    rewriteBackgroundImage(node.style)
  }

  Element.prototype.appendChild = function (node) {
    handleNode(node)
    return rawAppend.call(this, node)
  }

  Element.prototype.insertBefore = function (node, ref) {
    handleNode(node)
    return rawInsert.call(this, node, ref)
  }
})()