4chan umineko colored truths

enable umineko colored truths on 4chan

// ==UserScript==
// @name     4chan umineko colored truths
// @description enable umineko colored truths on 4chan
// @version  5
// @grant    none
// @include *//boards.4chan.org/*
// @include *//boards.4channel.org/*
// @namespace https://gf.qytechs.cn/users/141341
// ==/UserScript==
function process() {
  posts=document.getElementsByClassName('postMessage');
  for (var post of posts) {
    for (var i = 0; i < post.childNodes.length; ++i) {
      var node = post.childNodes[i];
      if (node.nodeName == '#text') {
        var a, b;
        a = node.textContent.indexOf('[red]');
        b = node.textContent.indexOf('[/red]', a);
        if (a != -1 && b != -1 && a < b) {
          var span = document.createElement("span");
          span.textContent = node.textContent.substring(a + 5, b);
          span.style='color:red;font-weight:bold';
          var prefix = document.createTextNode(node.textContent.substring(0, a));
          node.textContent = node.textContent.substring(b + 6);
          post.insertBefore(prefix, node);
          post.insertBefore(span, node);
          --i;
          continue;
        }
        a = node.textContent.indexOf('[blue]');
        b = node.textContent.indexOf('[/blue]', a);
        if (a != -1 && b != -1 && a < b) {
          var span = document.createElement("span");
          span.textContent = node.textContent.substring(a + 6, b);
          span.style='color:blue;font-weight:bold';
          var prefix = document.createTextNode(node.textContent.substring(0, a));
          node.textContent = node.textContent.substring(b + 7);
          post.insertBefore(prefix, node);
          post.insertBefore(span, node);
          --i;
          continue;
        }
        a = node.textContent.indexOf('[purple]');
        b = node.textContent.indexOf('[/purple]', a);
        if (a != -1 && b != -1 && a < b) {
          var span = document.createElement("span");
          span.textContent = node.textContent.substring(a + 8, b);
          span.style='color:purple;font-weight:bold';
          var prefix = document.createTextNode(node.textContent.substring(0, a));
          node.textContent = node.textContent.substring(b + 9);
          post.insertBefore(prefix, node);
          post.insertBefore(span, node);
          --i;
          continue;
        }
        a = node.textContent.indexOf('[gold]');
        b = node.textContent.indexOf('[/gold]', a);
        if (a != -1 && b != -1 && a < b) {
          var span = document.createElement("span");
          span.textContent = node.textContent.substring(a + 6, b);
          span.style='color:gold;font-weight:bold';
          var prefix = document.createTextNode(node.textContent.substring(0, a));
          node.textContent = node.textContent.substring(b + 7);
          post.insertBefore(prefix, node);
          post.insertBefore(span, node);
          --i;
          continue;
        }
      }
    }
  }
}
process();
document.addEventListener('4chanXInitFinished', function(e) {
  process();
});
document.addEventListener('ThreadUpdate', function(e) {
  process();
});

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址