Add start argument to youtube embeds if t arguement is present in url (#1155)

* Add start argument to youtube embeds if t arguement is present in url

* Move time argument regex to after match

* Allow for units in the t argument of youtube plugin

* Allow hash arguments aswell

* Correct or in reget for youtube plugin

* Shorten regex

* Allow argument before t argement that ends in t in youtube links

* Also allow youtube links without t argument
codeql
AStove 5 years ago committed by GitHub
parent 788855d2e3
commit 4902f5889d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 13
      js/plugins.js

@ -209,13 +209,18 @@ plugins.factory('userPlugins', function() {
* See: https://developers.google.com/youtube/player_parameters
*/
var youtubePlugin = new UrlPlugin('YouTube video', function(url) {
var regex = /(?:youtube\.com\/(?:[^\/]+\/.+\/|(?:v|e(?:mbed)?)\/|.*[?&]v=)|youtu\.be\/)([^"&?\/ ]{11})/i,
var regex = /(?:youtube\.com\/(?:[^\/]+\/.+\/|(?:v|e(?:mbed)?)\/|.*[?&]v=)|youtu\.be\/)([^"&?\/ ]{11})(?:.*t=)?(?:(\d+)h)?(?:(\d+)m)?(?:(\d+)s?)?/i,
match = url.match(regex);
if (match){
var token = match[1],
embedurl = "https://www.youtube.com/embed/" + token + "?html5=1&iv_load_policy=3&modestbranding=1&rel=0",
element = angular.element('<iframe></iframe>')
var token = match[1];
var hours = match[2] ? parseInt(match[2]) : 0;
var mins = match[3] ? parseInt(match[3]) : 0;
var secs = match[4] ? parseInt(match[4]) : 0;
var totalSecs = secs + mins*60 + hours*60*60;
var embedurl = "https://www.youtube.com/embed/" + token + "?html5=1&iv_load_policy=3&modestbranding=1&rel=0&start=" + totalSecs;
var element = angular.element('<iframe></iframe>')
.attr('src', embedurl)
.attr('width', '560')
.attr('height', '315')

Loading…
Cancel
Save