Jollytext

Jolly greentext

スクリプトをインストールするには、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         Jollytext
// @namespace    yuniDev
// @version      1.1
// @description  Jolly greentext
// @author       yuniDev
// @match        https://www.destiny.gg/embed/chat*
// @match        https://www.destiny.gg/chat*
// @match        https://www.destiny.gg/bigscreen*
// @grant        GM_addStyle
// @license      MIT
// ==/UserScript==

(function () {
  'use strict';

  function processTextNodes(container, wordIndex = { value: 0 }) {
    const children = Array.from(container.childNodes);

    for (const node of children) {
      if (node.nodeType === Node.TEXT_NODE) {
        const text = node.textContent;
        const parts = text.split(/(\s+)/);

        if (parts.length === 0) continue;

        const fragment = document.createDocumentFragment();

        for (const part of parts) {
          if (/^\s+$/.test(part)) {
            fragment.appendChild(document.createTextNode(part));
          } else {
            const shouldWrap = wordIndex.value % 2 !== 0;
            if (shouldWrap) {
              const span = document.createElement('span');
              span.style.color = '#f43a38';
              span.textContent = part;
              fragment.appendChild(span);
            } else {
              fragment.appendChild(document.createTextNode(part));
            }
            wordIndex.value++;
          }
        }

        node.parentNode.replaceChild(fragment, node);
      } else if (node.nodeType === Node.ELEMENT_NODE) {
        if (node.nodeName !== 'SPAN') {
          processTextNodes(node, wordIndex);
        }
      }
    }
  }

  function mutationCallback(mutationsList) {
    for (const mutation of mutationsList) {
      if (mutation.type === 'childList' && mutation.addedNodes.length > 0) {
        for (const addedNode of mutation.addedNodes) {
          const greentextSpan = addedNode.querySelector('.greentext');
          if (!greentextSpan) continue;

          const wordIndex = { value: 0 };
          processTextNodes(greentextSpan, wordIndex);
        }
      }
    }
  }

  const targetElement = document
    .getElementById('chat-win-main')
    ?.querySelector('.chat-lines');
  if (targetElement) {
    const observer = new MutationObserver(mutationCallback);
    observer.observe(targetElement, { childList: true });
  }
})();