From fba78d490e7a303f928a63dbc33a1c45530adc46 Mon Sep 17 00:00:00 2001 From: Tor Hveem Date: Thu, 17 Oct 2013 13:36:54 +0200 Subject: [PATCH] Support more URLs for youtube and request html5 player to improve performance of embedding --- js/plugins.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/js/plugins.js b/js/plugins.js index a151128..c8fa5c6 100644 --- a/js/plugins.js +++ b/js/plugins.js @@ -27,7 +27,7 @@ var Plugin = function(contentForMessage) { * to display when messages are received. * */ -plugins.service('plugins', ['userPlugins', '$sce', function(userPlugins, $sce) { +plugins.service('plugins', ['userPlugins', '$sce', function(userPlugins, $sce) { var nsfwRegexp = new RegExp('nsfw', 'i'); @@ -129,10 +129,12 @@ plugins.factory('userPlugins', function() { var youtubePlugin = new Plugin(function(message) { - if (message.indexOf('youtube.com') != -1) { - var index = message.indexOf("?v="); - var token = message.substr(index+3); - return '' + 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 embedurl = "http://www.youtube.com/embed/" + token+ "?html5=1&autoplay=0&theme=dark&color=black&iv_load_policy=3"; + return ''; } return null;