Mercurial Hosting > freedit
comparison src/test/tiny.html @ 28:d9d7aa2a79db
more video types
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Thu, 21 Jul 2022 23:44:49 -0600 |
parents | 6871eec2cf4c |
children | 8ff35379cc89 |
comparison
equal
deleted
inserted
replaced
27:6871eec2cf4c | 28:d9d7aa2a79db |
---|---|
4 <meta name="viewport" content="width=device-width, initial-scale=1"> | 4 <meta name="viewport" content="width=device-width, initial-scale=1"> |
5 <script src="http://tinymce.luan.software/tinymce.min.js" xreferrerpolicy="origin"></script> | 5 <script src="http://tinymce.luan.software/tinymce.min.js" xreferrerpolicy="origin"></script> |
6 <style> | 6 <style> |
7 </style> | 7 </style> |
8 <script> | 8 <script> |
9 var youtubePtn1 = new RegExp('https://youtu.be/([a-zA-Z0-9_-]+)(?:\\?t=([0-9]+))?'); | 9 function videoIframe(url) { |
10 var youtubePtn2 = new RegExp('https://www.youtube.com/watch\\?v=([a-zA-Z0-9_-]+)(?:\\?t=([0-9]+)s)?'); | 10 return '<iframe data-video="'+url+'" width="560" height="315" frameborder="0" allowfullscreen src="'+url+'"></iframe>'; |
11 var bitchutePtn = new RegExp('https://www.bitchute.com/video/([a-zA-Z0-9]+)/'); | 11 } |
12 var rumblePtn = new RegExp('https://rumble.com/embed/[a-z0-9]+/\\?pub=[a-z0-9]+'); | 12 |
13 var url2; | 13 var videoHandlers = {}; |
14 { | |
15 let ptn1 = new RegExp('https://youtu.be/([a-zA-Z0-9_-]+)(?:\\?t=([0-9]+))?'); | |
16 let ptn2 = new RegExp('https://www.youtube.com/watch\\?v=([a-zA-Z0-9_-]+)(?:\\?t=([0-9]+)s)?'); | |
17 videoHandlers.youtube = function(url) { | |
18 let result = url.match(ptn1) || url.match(ptn2); | |
19 if( result ) { | |
20 url = 'https://www.youtube.com/embed/' + result[1]; | |
21 if( result[2] ) | |
22 url += '?start=' + result[2]; | |
23 return videoIframe(url); | |
24 } | |
25 } | |
26 } | |
27 { | |
28 let ptn = new RegExp('https://rumble.com/embed/[a-z0-9]+/\\?pub=[a-z0-9]+'); | |
29 videoHandlers.rumble = function(url) { | |
30 if( url.match(ptn) ) { | |
31 return videoIframe(url); | |
32 } | |
33 } | |
34 } | |
35 { | |
36 let ptn = new RegExp('https://www.bitchute.com/video/([a-zA-Z0-9]+)/'); | |
37 videoHandlers.bitchute = function(url) { | |
38 let result = url.match(ptn); | |
39 if( result ) { | |
40 url = 'https://www.bitchute.com/embed/' + result[1]; | |
41 return videoIframe(url); | |
42 } | |
43 } | |
44 } | |
45 { | |
46 let ptn = new RegExp('https://vimeo.com/([0-9]+)'); | |
47 videoHandlers.vimeo = function(url) { | |
48 let result = url.match(ptn); | |
49 if( result ) { | |
50 url = 'https://player.vimeo.com/video/' + result[1]; | |
51 return videoIframe(url); | |
52 } | |
53 } | |
54 } | |
55 { | |
56 let ptn = new RegExp('https://dai.ly/([a-z0-9]+)'); | |
57 videoHandlers.dailymotion = function(url) { | |
58 let result = url.match(ptn); | |
59 if( result ) { | |
60 url = 'https://www.dailymotion.com/embed/video/' + result[1]; | |
61 return videoIframe(url); | |
62 } | |
63 } | |
64 } | |
65 { | |
66 let ptn = new RegExp('https://www.tiktok.com/[^/]+/video/([0-9]+)'); | |
67 videoHandlers.tiktok = function(url) { | |
68 let result = url.match(ptn); | |
69 if( result ) { | |
70 let html = '<blockquote class="tiktok-embed" data-video-id="'+result[1]+'" style="max-width: 560px; margin-left: 0;"><section></section></blockquote>'; | |
71 //html += '<script async src="https://www.tiktok.com/embed.js"></'+'script>'; | |
72 return html; | |
73 } | |
74 } | |
75 } | |
76 { | |
77 let ptn = new RegExp('\\.[a-zA-Z0-9]+$'); | |
78 videoHandlers.file = function(url) { | |
79 if( url.match(ptn) ) { | |
80 return '<video controls width="560" height><source src="'+url+'"></video>'; | |
81 } | |
82 } | |
83 } | |
84 | |
85 function videoUrlToHtml(url) { | |
86 for (let key in videoHandlers) { | |
87 let handle = videoHandlers[key]; | |
88 let html = handle(url); | |
89 if(html) return html; | |
90 } | |
91 return '<a data-video="'+url+'" href="'+url+'">'+url+'</a>'; | |
92 } | |
93 console.log(videoUrlToHtml('https://www.tiktok.com/@chantelleef/video/7112118342181276933?is_from_webapp=1&sender_device=pc&web_id=7073254106622838318')); | |
14 | 94 |
15 function media_url_resolver(data,resolve,reject) { | 95 function media_url_resolver(data,resolve,reject) { |
16 let html; | 96 let html = videoUrlToHtml(data.url); |
17 let url = data.url; | |
18 url2 = url; | |
19 let result; | |
20 if( result = url.match(youtubePtn1) || url.match(youtubePtn2) ) { | |
21 html = '<iframe data-video="'+url+'" width="560" height="315" src="https://www.youtube.com/embed/' + result[1]; | |
22 if( result[2] ) | |
23 html += '?start=' + result[2] | |
24 html += '" frameborder="0" allowfullscreen></iframe>'; | |
25 } else if( result = url.match(bitchutePtn) ) { | |
26 html = '<iframe data-video="'+url+'" width="560" height="315" scrolling="no" frameborder="0" style="border: none;" src="https://www.bitchute.com/embed/' + result[1] + '/"></iframe>'; | |
27 } else if( url.match(rumblePtn) ) { | |
28 html = '<iframe data-video="'+url+'" width="560" height="315" frameborder="0" allowfullscreen src="' + url + '"></iframe>'; | |
29 } else { | |
30 html = '<a data-video="'+url+'" href="'+url+'">'+url+'</a>'; | |
31 } | |
32 resolve({ html: html }); | 97 resolve({ html: html }); |
33 } | 98 } |
34 | 99 |
35 | 100 |
36 function tinymceSetup(editor) { | 101 function tinymceSetup(editor) { |