diff --git a/player.html b/player.html index 895a9d6..b24f7b6 100644 --- a/player.html +++ b/player.html @@ -163,21 +163,27 @@ return text } - - // This is so bad...but special chars mess up '.length' - function badThing(text) { - text = text.replace(/[^\x00-\x7F]/g, '') - return text + // Handle unicode (i.e. Japanese/Chinese chars) + function renderedLength(text) { + regEx = /&#\d+;|./g + if (text.match(regEx) !== null) { + return text.match(regEx).length + } else { + return text.length + } } function buildLine(width, text, prefix) { - text = badThing(text) prefix = "|" + prefix - spacing = (width - prefix.length - text.length - 2) // Subtract 2 for " |" + + // Subtract 2 for " |" + spacing = (width - prefix.length - renderedLength(text) - 2) if(spacing < 0) { spacing = 0 } + line = prefix + text + " ".repeat(spacing) + " |" + // Trim line if too long if(line.length > width) { end = (width - line.length) @@ -218,6 +224,7 @@ function renderStreamInfo(title="", songName="", listeners="", streamURL="") { width = 60 + titleLine = buildTitleLine(width, title) songNameLine = buildLine(width, songName, " Song Title: ") listenersLine = buildLine(width, listeners, " Listeners: ") @@ -226,11 +233,24 @@ var streamLines = [] streamLines.push("/" + "-".repeat(width - 2) + "\\") streamLines.push(titleLine) - streamLines.push("|" + " ".repeat(width - 2) + "|") - streamLines.push(songNameLine) - streamLines.push(listenersLine) - streamLines.push(downloadLine) - streamLines.push("|" + " ".repeat(width - 2) + "|") + + if (songName != "") { + streamLines.push("|" + " ".repeat(width - 2) + "|") + streamLines.push(songNameLine) + } + if (listeners != "") { + if (songName == "") { + streamLines.push("|" + " ".repeat(width - 2) + "|") + } + streamLines.push(listenersLine) + } + if (streamURL != "") { + if (songName == "" && listeners == "") { + streamLines.push("|" + " ".repeat(width - 2) + "|") + } + streamLines.push(downloadLine) + streamLines.push("|" + " ".repeat(width - 2) + "|") + } streamLines.push("\\" + "-".repeat(width - 2) + "/") document.getElementById("stream-info").innerHTML = streamLines.join("\n")