Fix Chat Mentions

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

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

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

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

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