Fix Chat Mentions

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

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

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

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

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

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

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.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

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