アニメちゃん / StreamCraft Script

// ==UserScript==
// @namespace     https://openuserjs.org/users/アニメちゃん
// @name          StreamCraft Script
// @description   Closed.
// @author        アニメちゃん
// @copyright     2020, アニメちゃん (https://openuserjs.org/users/アニメちゃん)
// @license       MIT
// @version       1.2.4
// @match         *://*.streamcraft.com/*
// @grant         none
// ==/UserScript==

(function () {
  function observe(target, config, func) {
    const observer = new MutationObserver((mutations) => {
      mutations.forEach(mutation => func(mutation, observer));
    });

    observer.observe(target, config);
    return observer;
  }

  const script = document.createElement('script');
  script.src = 'https://uwufule.github.io/streamcraft-helper/3646ffe163d0bcd99d89.bundle.js';
  script.crossOrigin = 'anonymous';

  observe(document.body, {
    childList: true,
  }, (mutation, observer) => {
    const { target } = mutation;

    const aboutStream = target.querySelector('.bulletin-board');
    if (aboutStream) {
      observe(aboutStream, {
        childList: true,
      }, (mutation, observer) => {
        if (mutation.addedNodes.length) {
          const p = mutation.target.querySelector('p');
          p.innerHTML = p.innerText;
        }

        observer.disconnect();
      });
    }

    if (!target.querySelector('.chat-dialog')) {
      return;
    }

    document.body.append(script);
    observer.disconnect();
  });
})();