From 9f46e656cb6140b63ed31470bd1c5fa6a85a2011 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lorenz=20H=C3=BCbschle-Schneider?= Date: Fri, 25 Apr 2014 19:03:05 +0100 Subject: [PATCH] Improve youtube matching URL closes #266 --- js/plugins.js | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/js/plugins.js b/js/plugins.js index 151528f..8a243a6 100644 --- a/js/plugins.js +++ b/js/plugins.js @@ -143,15 +143,20 @@ plugins.factory('userPlugins', function() { */ var youtubePlugin = new Plugin(function(message) { - var regExp = /^.*((youtu.be\/)|(v\/)|(\/u\/\w\/)|(embed\/)|(watch\?))\??v?=?([^#\&\?]*).*/; - var match = message.match(regExp); - if (match && match[7].length==11){ - var token = match[7]; + var regExp = /((?:https?:\/\/)?(?:www\.)?(?:youtube.com|youtu.be)\/(?:v\/|embed\/|watch(?:\?v=|\/))?([a-zA-Z0-9-]+))/gm; + var match = regExp.exec(message); + var retval = ''; + + // iterate over all matches + while (match !== null){ + var token = match[2]; var embedurl = "https://www.youtube.com/embed/" + token + "?html5=1&iv_load_policy=3&modestbranding=1&rel=0&showinfo=0"; - return ''; + retval += ''; + // next match + match = regExp.exec(message); } - return null; + return retval; }); youtubePlugin.name = 'YouTube video';