Fix Chat Mentions

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

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==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 });
  })();