diff options
Diffstat (limited to 'juick-www/src')
-rw-r--r-- | juick-www/src/main/js/killy/index.js | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/juick-www/src/main/js/killy/index.js b/juick-www/src/main/js/killy/index.js index 391ce3b6..4d2331b6 100644 --- a/juick-www/src/main/js/killy/index.js +++ b/juick-www/src/main/js/killy/index.js @@ -41,6 +41,17 @@ function makeCts(makeNodeCallback, title) { return ctsNode; } +function makeIframe(src, w, h, scrolling='no') { + let iframe = document.createElement('iframe'); + iframe.width = w; + iframe.height = h; + iframe.frameBorder = 0; + iframe.scrolling = scrolling; + iframe.setAttribute('allowFullScreen', ''); + iframe.src = src; + return iframe; +} + function naiveEllipsis(str, len, ellStr='...') { let ellLen = ellStr.length; if (str.length <= len) { return str; } @@ -110,6 +121,45 @@ function getEmbedableLinkTypes() { audio.setAttribute('controls', ''); return wrapIntoTag(audio, 'div', 'audio'); } + }, + { + name: 'YouTube videos (and playlists)', + id: 'embed_youtube_videos', + ctsDefault: false, + re: /^(?:https?:)?\/\/(?:www\.|m\.)?(?:youtu(?:(?:\.be\/|be\.com\/(?:v|embed)\/)([-\w]+)|be\.com\/watch)((?:(?:\?|&(?:amp;)?)(?:\w+=[-\.\w]*[-\w]))*)|youtube\.com\/playlist\?list=([-\w]*)(&(amp;)?[-\w\?=]*)?)/i, + makeNode: function(aNode, reResult) { + let [url, v, args, plist] = reResult; + let iframeUrl = url; + if (plist !== undefined) { + iframeUrl = '//www.youtube-nocookie.com/embed/videoseries?list=' + plist; + } else { + args = args.replace(/^\?/, ''); + let arr = args.split('&').map(s => s.split('=')); + let pp = {}; arr.forEach(z => pp[z[0]] = z[1]); + let embedArgs = { rel: '0' }; + if (pp.t != undefined) { + const tre = /^(?:(\d+)|(?:(\d+)h)?(?:(\d+)m)?(\d+)s|(?:(\d+)h)?(\d+)m|(\d+)h)$/i; + let [, t, h, m, s, h1, m1, h2] = tre.exec(pp.t); + embedArgs['start'] = (+t) || ((+(h || h1 || h2 || 0))*60*60 + (+(m || m1 || 0))*60 + (+(s || 0))); + } + if (pp.list !== undefined) { + embedArgs['list'] = pp.list; + } + v = v || pp.v; + iframeUrl = '//www.youtube-nocookie.com/embed/' + v + '?' + Object.keys(embedArgs).map(k => `${k}=${embedArgs[k]}`).join('&'); + } + return wrapIntoTag(makeIframe(iframeUrl, 640, 360), 'div', 'youtube'); + } + }, + { + name: 'Vimeo videos', + id: 'embed_vimeo_videos', + ctsDefault: false, + //re: /^(?:https?:)?\/\/(?:www\.)?(?:player\.)?vimeo\.com\/(?:(?:video\/|album\/[\d]+\/video\/)?([\d]+)|([\w-]+)\/(?!videos)([\w-]+))/i, + re: /^(?:https?:)?\/\/(?:www\.)?(?:player\.)?vimeo\.com\/(?:video\/|album\/[\d]+\/video\/)?([\d]+)/i, + makeNode: function(aNode, reResult) { + return wrapIntoTag(makeIframe('//player.vimeo.com/video/' + reResult[1], 640, 360), 'div', 'vimeo'); + } } ] } |