From eab1da08262571df60aa732e4b3bb4b94f1a9a0e Mon Sep 17 00:00:00 2001 From: Amogh M Aradhya Date: Tue, 10 Oct 2023 16:52:26 +0530 Subject: [PATCH] Used named patterns instead of numbers --- funnel/assets/js/utils/embedvideo.js | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/funnel/assets/js/utils/embedvideo.js b/funnel/assets/js/utils/embedvideo.js index 1e677c420..88a65e588 100644 --- a/funnel/assets/js/utils/embedvideo.js +++ b/funnel/assets/js/utils/embedvideo.js @@ -8,18 +8,21 @@ const Video = { */ getVideoTypeAndId(url) { const regexMatch = url.match( - /(http:|https:|)\/\/(player.|www.)?(y2u\.be|vimeo\.com|youtu(be\.com|\.be|be\.googleapis\.com))\/(video\/|embed\/|live\/|watch\?v=|v\/)?([A-Za-z0-9._%-]*)(&\S+)?(\?h=([^&]+))?/ + /(http:|https:|)\/\/(player.|www.)?(?y2u\.be|vimeo\.com|youtu(be\.com|\.be|be\.googleapis\.com))\/(video\/|embed\/|live\/|watch\?v=|v\/)?(?[A-Za-z0-9._%-]*)(&\S+)?(\?h=(?[^&]+))?/ ); let type = ''; if (regexMatch && regexMatch.length > 5) { - if (regexMatch[3].indexOf('youtu') > -1 || regexMatch[3].indexOf('y2u') > -1) { + if ( + regexMatch.groups.service.indexOf('youtu') > -1 || + regexMatch.groups.service.indexOf('y2u') > -1 + ) { type = 'youtube'; - } else if (regexMatch[3].indexOf('vimeo') > -1) { + } else if (regexMatch.groups.service.indexOf('vimeo') > -1) { type = 'vimeo'; return { type, - videoId: regexMatch[6], - paramId: regexMatch[9], + videoId: regexMatch.groups.videoId, + paramId: regexMatch.groups.paramId, }; } return { @@ -38,7 +41,9 @@ const Video = { if (type === 'youtube') { videoEmbedUrl = ``; } else if (type === 'vimeo') { - videoEmbedUrl = ``; + videoEmbedUrl = ``; } if (videoEmbedUrl) { videoWrapper.innerHTML = videoEmbedUrl;