From e04a2cfd805de46cfb38479d696a07c8b24f62b2 Mon Sep 17 00:00:00 2001 From: Scott Worley Date: Sat, 4 Aug 2012 13:00:11 -0700 Subject: [PATCH] URL detection --- webclient/rc.html | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/webclient/rc.html b/webclient/rc.html index d91d3a6..36c0c10 100644 --- a/webclient/rc.html +++ b/webclient/rc.html @@ -31,6 +31,9 @@ color: silver; font-family: monospace; } + a { + color: white; + } #container { height: 100%; } @@ -209,7 +212,26 @@ type += " self"; } text_span.setAttribute("class", type); - text_span.appendChild(document.createTextNode(message.Text)); + + // URL detection + var text = message.Text; + var URL_re = /\bhttps?:\/\/\S+/; + while (URL_re.test(text)) { + var match = URL_re.exec(text); + var leading_text = text.substr(0, match.index); + if (leading_text) { + text_span.appendChild(document.createTextNode(leading_text)); + } + var anchor = document.createElement("a"); + anchor.setAttribute("href", encodeURI(match[0])); + anchor.appendChild(document.createTextNode(match[0])); + text_span.appendChild(anchor); + text = text.substr(match.index + match[0].length); + } + if (text) { + text_span.appendChild(document.createTextNode(text)); + } + message.UI.appendChild(text_span); } -- 2.44.1