新增 - 支持控制台简单的颜色

This commit is contained in:
suwings 2018-05-22 19:59:26 +08:00
parent 618cc83fd3
commit d4b631c311
2 changed files with 31 additions and 0 deletions

View File

@ -107,4 +107,33 @@
}
}
//Minecraft 服务器输出基本颜色
TOOLS.encodeConsoleColor = function (text) {
text = text.replace(/\[/igm, "<span class='color-green'>[&nbsp;</span>");
text = text.replace(/\]/igm, "<span class='color-green'>&nbsp;]</span>");
text = text.replace(/INFO/gm, "<span style='color:#03ea0a;'>INFO</span>");
text = text.replace(/WANG/gm, "<span class='color-red'>WANG</span>");
text = text.replace(/(\d{2,}:\d{2,}:\d{2,})/gm, "<span style='color:#017EBC;'> $1 </span>");
RegExpStringArr = [
["Unknown&nbsp;command", "Server", "Stopping"],
["/help"],
["WARN"]
]
for (var k in RegExpStringArr) {
for (var y in RegExpStringArr[k]) {
var reg = new RegExp("(" + RegExpStringArr[k][y] + ")", "igm");
console.log("当前:", k, y, "正则是:", "(" + RegExpStringArr[k][y] + ")", reg)
if (k == 0)
text = text.replace(reg, "<span style='color:#017EBC;'>$1</span>");
if (k == 1)
text = text.replace(reg, "<span class='color-green'>$1</span>");
if (k == 2)
text = text.replace(reg, "<span class='color-red'>$1</span>");
}
}
return text;
}
})();

View File

@ -140,6 +140,8 @@
//判断用户是否自己移动了滚轴
var BUFF_FONTIER_SIZE_DOWN = MinecraftConsole.scrollHeight - MinecraftConsole.clientHeight;
flag = (MinecraftConsole.scrollTop + 354 >= BUFF_FONTIER_SIZE_DOWN);
//color
consoleSafe = TOOLS.encodeConsoleColor(consoleSafe);
//add
MinecraftConsole.innerHTML += consoleSafe;
//unblive bt ths is t