UTags Ext - Replace Username

Replace username with UTags.

スクリプトをインストールするには、Tampermonkey, GreasemonkeyViolentmonkey のような拡張機能のインストールが必要です。

You will need to install an extension such as Tampermonkey to install this script.

スクリプトをインストールするには、TampermonkeyViolentmonkey のような拡張機能のインストールが必要です。

スクリプトをインストールするには、TampermonkeyUserscripts のような拡張機能のインストールが必要です。

このスクリプトをインストールするには、Tampermonkeyなどの拡張機能をインストールする必要があります。

このスクリプトをインストールするには、ユーザースクリプト管理ツールの拡張機能をインストールする必要があります。

(ユーザースクリプト管理ツールは設定済みなのでインストール!)

このスタイルをインストールするには、Stylusなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus などの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus tなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

(ユーザースタイル管理ツールは設定済みなのでインストール!)

作者のサイトでサポートを受ける。または、このスクリプトの質問や評価の投稿はこちら通報はこちらへお寄せください
// ==UserScript==
// @name                 UTags Ext - Replace Username
// @name:zh-CN           UTags 扩展 - 替换用户名
// @namespace            https://github.com/utags
// @homepageURL          https://github.com/utags/userscripts#readme
// @supportURL           https://github.com/utags/userscripts/issues
// @version              0.1.0
// @description          Replace username with UTags.
// @description:zh-CN    使用 UTags 标签替换用户名。
// @icon                 data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='%23ff6361' class='bi bi-tags-fill' viewBox='0 0 16 16'%3E %3Cpath d='M2 2a1 1 0 0 1 1-1h4.586a1 1 0 0 1 .707.293l7 7a1 1 0 0 1 0 1.414l-4.586 4.586a1 1 0 0 1-1.414 0l-7-7A1 1 0 0 1 2 6.586V2zm3.5 4a1.5 1.5 0 1 0 0-3 1.5 1.5 0 0 0 0 3z'/%3E %3Cpath d='M1.293 7.793A1 1 0 0 1 1 7.086V2a1 1 0 0 0-1 1v4.586a1 1 0 0 0 .293.707l7 7a1 1 0 0 0 1.414 0l.043-.043-7.457-7.457z'/%3E %3C/svg%3E
// @author               Pipecraft
// @license              MIT
// @match                https://github.com/*
// @noframes
// @run-at               document-idle
// ==/UserScript==
//
;(() => {
  'use strict'
  var style_default =
    'a[data-hovercard-url][data-utags-replaced]:before{content:attr(data-utags)}a[data-hovercard-url][data-utags-replaced] span{display:none}:not(#a):not(#b):not(#c) a[data-hovercard-url][data-utags-replaced]+ul .utags_text_tag:not(.utags_captain_tag2),:not(#a):not(#b):not(#c) a[data-hovercard-url][data-utags-replaced]:not(:hover)+ul:not(:hover){display:none!important}'
  var style = document.createElement('style')
  style.textContent = style_default
  document.head.append(style)
  function processElements() {
    var _a
    const elements = document.querySelectorAll(
      'a[data-hovercard-url]:not([data-utags-replaced="true"])'
    )
    for (const element of elements) {
      if (!(element instanceof HTMLElement)) continue
      const utags = element.dataset.utags
      if (!utags) continue
      element.dataset.utagsReplaced = 'true'
      const childNodes = Array.from(element.childNodes)
      for (const node of childNodes) {
        if (
          node.nodeType === Node.TEXT_NODE &&
          ((_a = node.textContent) == null ? void 0 : _a.trim())
        ) {
          const span = document.createElement('span')
          span.textContent = node.textContent
          node.replaceWith(span)
        }
      }
    }
  }
  var timer
  function scheduleProcess() {
    if (timer) return
    timer = requestAnimationFrame(() => {
      processElements()
      timer = void 0
    })
  }
  var observer = new MutationObserver((mutations) => {
    let shouldProcess = false
    for (const mutation of mutations) {
      if (mutation.type === 'childList' && mutation.addedNodes.length > 0) {
        shouldProcess = true
        break
      }
      if (
        mutation.type === 'attributes' &&
        mutation.attributeName === 'data-utags'
      ) {
        shouldProcess = true
        break
      }
    }
    if (shouldProcess) {
      scheduleProcess()
    }
  })
  scheduleProcess()
  observer.observe(document.body, {
    childList: true,
    subtree: true,
    attributes: true,
    attributeFilter: ['data-utags'],
  })
})()