Fix Chat Mentions

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

Voor het installeren van scripts heb je een extensie nodig, zoals Tampermonkey, Greasemonkey of Violentmonkey.

Voor het installeren van scripts heb je een extensie nodig, zoals {tampermonkey_link:Tampermonkey}.

Voor het installeren van scripts heb je een extensie nodig, zoals Tampermonkey of Violentmonkey.

Voor het installeren van scripts heb je een extensie nodig, zoals Tampermonkey of Userscripts.

Voor het installeren van scripts heb je een extensie nodig, zoals {tampermonkey_link:Tampermonkey}.

Voor het installeren van scripts heb je een gebruikersscriptbeheerder nodig.

(Ik heb al een user script manager, laat me het downloaden!)

Voor het installeren van gebruikersstijlen heb je een extensie nodig, zoals {stylus_link:Stylus}.

Voor het installeren van gebruikersstijlen heb je een extensie nodig, zoals {stylus_link:Stylus}.

Voor het installeren van gebruikersstijlen heb je een extensie nodig, zoals {stylus_link:Stylus}.

Voor het installeren van gebruikersstijlen heb je een gebruikersstijlbeheerder nodig.

Voor het installeren van gebruikersstijlen heb je een gebruikersstijlbeheerder nodig.

Voor het installeren van gebruikersstijlen heb je een gebruikersstijlbeheerder nodig.

(Ik heb al een beheerder - laat me doorgaan met de installatie!)

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