Fix Chat Mentions

Убирает @ из упоминаний, добавляет запятую, наследует цвет/градиент/жирность

スクリプトをインストールするには、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         Fix Chat Mentions
  // @namespace    http://tampermonkey.net/
  // @version      1.3
  // @description  Убирает @ из упоминаний, добавляет запятую, наследует цвет/градиент/жирность
  // @match        https://shikme.chat/*
  // @grant        none
  // @icon         https://shikme.chat/default_images/icon.png?v=1528136794
  // @run-at       document-idle
  // ==/UserScript==

  (function () {
      'use strict';

      function isGradientParent(el) {
          let parent = el.parentElement;
          while (parent) {
              const bg = parent.style.background || parent.style.backgroundImage || '';
              if (bg.includes('gradient')) return true;
              parent = parent.parentElement;
          }
          return false;
      }

      function fixMention(el) {
          if (el.dataset.fixed) return;
          el.dataset.fixed = '1';

          const text = el.textContent.replace(/^@/, '');

          const next = el.nextSibling;
          const hasTextAfter = next && next.textContent && next.textContent.trim().length > 0;

          if (hasTextAfter) {
              el.textContent = text + ',';
              if (next.nodeType === 3 && !next.textContent.startsWith(' ')) {
                  next.textContent = ' ' + next.textContent;
              }
          } else {
              el.textContent = text;
          }

          if (isGradientParent(el)) {
              el.style.cssText = `
                  background: none !important;
                  -webkit-background-clip: unset !important;
                  -webkit-text-fill-color: transparent !important;
                  color: inherit !important;
                  font-weight: inherit !important;
                  padding: 0 !important;
                  border-radius: 0 !important;
                  display: inline !important;
              `;
          } else {
              el.style.cssText = `
                  color: inherit !important;
                  -webkit-text-fill-color: inherit !important;
                  background: none !important;
                  font-weight: inherit !important;
                  padding: 0 !important;
                  border-radius: 0 !important;
              `;
          }
      }

      document.querySelectorAll('.mention').forEach(fixMention);

      const observer = new MutationObserver((mutations) => {
          for (const m of mutations) {
              for (const node of m.addedNodes) {
                  if (node.nodeType !== 1) continue;
                  if (node.classList?.contains('mention')) {
                      fixMention(node);
                  } else {
                      node.querySelectorAll?.('.mention').forEach(fixMention);
                  }
              }
          }
      });

      observer.observe(document.body, { childList: true, subtree: true });
  })();