This commit is contained in:
Thomas Forgione 2020-03-20 17:19:16 +01:00
parent 2e79ea916a
commit a3298f8ef5
2 changed files with 11 additions and 4 deletions

View File

@ -20,7 +20,6 @@ body {
}
.item {
width: 400px;
margin: 0.5rem;
}

View File

@ -24,7 +24,7 @@ class Message {
let name = document.createElement('span');
name.className = "text name";
name.style.color = this.context.color;
name.style.color = readableColor(this.context.color);
name.innerHTML = escapeHtml(this.context["display-name"]);
this.element.appendChild(name);
@ -54,7 +54,7 @@ function escapeHtml(unsafe) {
}
function formatEmotes(text, emotes) {
var splitText = text.split('');
var splitText = escapeHtml(text).split('');
for(var i in emotes) {
var e = emotes[i];
for(var j in e) {
@ -65,7 +65,6 @@ function formatEmotes(text, emotes) {
var length = mote[1] - mote[0],
empty = Array.apply(null, new Array(length + 1)).map(function() { return '' });
splitText = splitText.slice(0, mote[0]).concat(empty).concat(splitText.slice(mote[1] + 1, splitText.length));
splitText = splitText.map((x) => escapeHtml(x));
splitText.splice(mote[0], 1, '<img class="emoticon" src="http://static-cdn.jtvnw.net/emoticons/v1/' + i + '/4.0">');
}
}
@ -73,6 +72,15 @@ function formatEmotes(text, emotes) {
return splitText.join('');
}
function readableColor(color) {
switch (color.toLowerCase()) {
case "#0000ff": return "#8b58ff";
case "#008000": return "#319a24";
case "#b22222": return "#db4a3f";
default: return color;
}
}
function replaceAll(input, from, to) {
const fromLen = from.length;
let output = "";