ColorAskMona

AskMonaのレスに独自に色をつけます。

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

You will need to install a user script manager extension to install this script.

(У мене вже є менеджер скриптів, дайте мені встановити його!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name        ColorAskMona
// @namespace   sei0o.askmona.color
// @description AskMonaのレスに独自に色をつけます。
// @include     http://askmona.org/*
// @version     1.0.1
// @grant       none
// @require     http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js  
// ==/UserScript==

$("p.res").each(function(idx, elm){
  var m = $(this).html().match(/\[\[(\d+)\]\]/);
  if (m) {
    for(var i=0; i <= 7; i++) { // 他のlvクラスを削除
      $(this).removeClass("lv"+ i);
    }
    
    var level = parseInt(m[1], 10); // lvクラス追加
    $(this).addClass("lv"+ level);
    
    // [[n]]自体は小さく貼り直す
    $(this).html(
      $(this).html().replace(/\[\[(\d+)\]\]/, "")
    );
    $(this).append("<span style='font-size: 0.8rem; color: #777;'>"+ m[0] +"</span>");
  }
});