Added video and links in the chat

This commit is contained in:
Lars van Hijfte
2017-01-29 18:29:27 +01:00
parent 89c8c35b4a
commit 877637fcc9
2 changed files with 21 additions and 10 deletions

View File

@@ -2,19 +2,26 @@ var days = ["zondag", "maandag", "dinsdag", "woensdag", "donderdag", "vrijdag",
var months = ["januari", "februari", "maart", "april", "mei", "juni", "juli", "augustus", "september", "oktober", "november", "december"]
function fancyText(text) {
// Add images and gifs.
var regex = /(https:\/\/.[^ ]*\.(?:png|jpg|jpeg|gif))/ig;
text = text.replace(regex, function(img) {
return "<img src='" + img + "' />";
var regex = /(https?:\/\/.[^ ]*)/ig;
text = text.replace(regex, function(link) {
if (link.match(/(https:\/\/.[^ ]*\.(?:png|jpg|jpeg|gif))/ig)) {
return "<img alt='" + link + "' src='" + link + "' />";
} else if (link.match(/(https:\/\/.[^ ]*\.(?:mp4))/ig)) {
return "<video width='100%'>" +
"<source src='"+ link +"' type='video/mp4'>" +
"<b>Je browser ondersteund geen video</b>" +
"</video><button onclick='$(this).prev().get(0).play();'>Speel af</button>";
} else if (link.match(/(https:\/\/.[^ ]*\.(?:ogg))/ig)) {
return "<video width='100%'>" +
"<source src='"+ link +"' type='video/ogg'>" +
"<b>Je browser ondersteund geen video</b>" +
"</video><button onclick='$(this).prev().get(0).play();'>Speel af</button>";
} else {
return "<a href='" + link + "'>" + link + "</a>";
}
});
// Add links.
// regex = /(https:\/\/.[^ ]*\.(?:net|com|nl))/ig;
// text = text.replace(regex, function(link) {
// return "<a href='" + link + "'>LINK</a>";
// });
return text;
}

View File

@@ -130,4 +130,8 @@ body {
.chat-message img {
max-width: 100%;
}
.chat-message a {
text-decoration: underline;
}