22
|
1 <!doctype html>
|
|
2 <html>
|
|
3 <head>
|
|
4 <meta name="viewport" content="width=device-width, initial-scale=1">
|
24
|
5 <script src="http://tinymce.luan.software/tinymce.min.js" xreferrerpolicy="origin"></script>
|
22
|
6 <style>
|
|
7 </style>
|
|
8 <script>
|
28
|
9 function videoIframe(url) {
|
|
10 return '<iframe data-video="'+url+'" width="560" height="315" frameborder="0" allowfullscreen src="'+url+'"></iframe>';
|
|
11 }
|
|
12
|
30
|
13 // fucking moronic javascript doesn't have \Q \E in regex
|
28
|
14 var videoHandlers = {};
|
|
15 {
|
30
|
16 let ptn1 = /^https:\/\/youtu\.be\/([a-zA-Z0-9_-]+)(?:\?t=([0-9]+))?/;
|
|
17 let ptn2 = /^https:\/\/www\.youtube\.com\/watch\?v=([a-zA-Z0-9_-]+)(?:&t=([0-9]+)s)?/;
|
28
|
18 videoHandlers.youtube = function(url) {
|
|
19 let result = url.match(ptn1) || url.match(ptn2);
|
|
20 if( result ) {
|
|
21 url = 'https://www.youtube.com/embed/' + result[1];
|
|
22 if( result[2] )
|
|
23 url += '?start=' + result[2];
|
|
24 return videoIframe(url);
|
|
25 }
|
|
26 }
|
|
27 }
|
|
28 {
|
30
|
29 let ptn = /^https:\/\/rumble\.com\/embed\/[a-z0-9]+\/\?pub=[a-z0-9]+/;
|
28
|
30 videoHandlers.rumble = function(url) {
|
|
31 if( url.match(ptn) ) {
|
|
32 return videoIframe(url);
|
|
33 }
|
|
34 }
|
|
35 }
|
|
36 {
|
30
|
37 let ptn = /^https:\/\/www\.bitchute\.com\/video\/([a-zA-Z0-9]+)\//;
|
28
|
38 videoHandlers.bitchute = function(url) {
|
|
39 let result = url.match(ptn);
|
|
40 if( result ) {
|
|
41 url = 'https://www.bitchute.com/embed/' + result[1];
|
|
42 return videoIframe(url);
|
|
43 }
|
|
44 }
|
|
45 }
|
|
46 {
|
30
|
47 let ptn = /^https:\/\/vimeo\.com\/([0-9]+)/;
|
28
|
48 videoHandlers.vimeo = function(url) {
|
|
49 let result = url.match(ptn);
|
|
50 if( result ) {
|
|
51 url = 'https://player.vimeo.com/video/' + result[1];
|
|
52 return videoIframe(url);
|
|
53 }
|
|
54 }
|
|
55 }
|
|
56 {
|
30
|
57 let ptn = /^https:\/\/dai\.ly\/([a-z0-9]+)/;
|
28
|
58 videoHandlers.dailymotion = function(url) {
|
|
59 let result = url.match(ptn);
|
|
60 if( result ) {
|
|
61 url = 'https://www.dailymotion.com/embed/video/' + result[1];
|
|
62 return videoIframe(url);
|
|
63 }
|
|
64 }
|
|
65 }
|
|
66 {
|
30
|
67 let ptn = /^https:\/\/www\.tiktok\.com\/[^/]+\/video\/([0-9]+)/;
|
28
|
68 videoHandlers.tiktok = function(url) {
|
|
69 let result = url.match(ptn);
|
|
70 if( result ) {
|
|
71 let html = '<blockquote class="tiktok-embed" data-video-id="'+result[1]+'" style="max-width: 560px; margin-left: 0;"><section></section></blockquote>';
|
|
72 //html += '<script async src="https://www.tiktok.com/embed.js"></'+'script>';
|
|
73 return html;
|
|
74 }
|
|
75 }
|
|
76 }
|
|
77 {
|
30
|
78 let ptn = /\.[a-zA-Z0-9]+$/;
|
28
|
79 videoHandlers.file = function(url) {
|
|
80 if( url.match(ptn) ) {
|
|
81 return '<video controls width="560" height><source src="'+url+'"></video>';
|
|
82 }
|
|
83 }
|
|
84 }
|
|
85
|
|
86 function videoUrlToHtml(url) {
|
|
87 for (let key in videoHandlers) {
|
|
88 let handle = videoHandlers[key];
|
|
89 let html = handle(url);
|
|
90 if(html) return html;
|
|
91 }
|
|
92 return '<a data-video="'+url+'" href="'+url+'">'+url+'</a>';
|
|
93 }
|
|
94 console.log(videoUrlToHtml('https://www.tiktok.com/@chantelleef/video/7112118342181276933?is_from_webapp=1&sender_device=pc&web_id=7073254106622838318'));
|
22
|
95
|
|
96 function media_url_resolver(data,resolve,reject) {
|
28
|
97 let html = videoUrlToHtml(data.url);
|
22
|
98 resolve({ html: html });
|
|
99 }
|
|
100
|
24
|
101
|
23
|
102 function tinymceSetup(editor) {
|
24
|
103
|
|
104 editor.ui.registry.addToggleButton('styleCode', {
|
|
105 icon: 'sourcecode',
|
|
106 tooltip: 'Code',
|
|
107 onAction: function(api) {
|
|
108 editor.execCommand('mceToggleFormat', false, 'code')
|
|
109 },
|
|
110 onSetup: function(api) {
|
|
111 api.setActive(editor.formatter.match('code'));
|
|
112 let changed = editor.formatter.formatChanged('code', api.setActive);
|
|
113 return function() { changed.unbind(); };
|
|
114 }
|
|
115 });
|
|
116
|
|
117 editor.ui.registry.addMenuButton('styleText', {
|
|
118 icon: 'format',
|
|
119 tooltip: 'Text',
|
|
120 fetch: function(callback) {
|
|
121 callback([
|
|
122 'fontsize',
|
|
123 'forecolor',
|
|
124 ])
|
|
125 }
|
23
|
126 });
|
26
|
127
|
|
128 editor.on( 'init', function(e) {editor.focus()} );
|
23
|
129 }
|
|
130
|
22
|
131 tinymce.init({
|
|
132 selector: 'textarea',
|
23
|
133 setup: tinymceSetup,
|
27
|
134 //menubar: false,
|
26
|
135 statusbar: false,
|
24
|
136 toolbar: 'link image media | styleCode bold italic underline strikethrough superscript styleText | blockquote numlist bullist',
|
26
|
137 plugins: ['link', 'image', 'media', 'lists', 'code', 'autoresize'],
|
|
138 autoresize_bottom_margin: 0,
|
22
|
139 link_target_list: false,
|
|
140 link_title: false,
|
|
141 image_description: false,
|
|
142 image_dimensions: false,
|
|
143 object_resizing: false,
|
|
144 contextmenu: false,
|
|
145 media_alt_source: false,
|
|
146 media_dimensions: false,
|
|
147 media_poster: false,
|
|
148 media_url_resolver: media_url_resolver,
|
|
149 text_patterns: false,
|
26
|
150 content_style: 'img {max-width: 500px;} p {margin: 0}',
|
23
|
151 //newline_behavior: 'linebreak',
|
22
|
152 extended_valid_elements: 'b,i',
|
|
153 formats: {
|
|
154 bold: { inline: 'b' },
|
|
155 italic: {inline: 'i'},
|
|
156 underline: {inline: 'u'},
|
|
157 },
|
|
158 });
|
|
159
|
|
160 function log() {
|
|
161 console.log(tinymce.activeEditor.getContent());
|
|
162 }
|
|
163 </script>
|
|
164 </head>
|
|
165 <body>
|
23
|
166 <p><a href="https://www.tiny.cloud/">TinyMCE</a></p>
|
22
|
167 <textarea></textarea>
|
|
168 <p><button onclick="log()">log</button></p>
|
|
169 </body>
|
|
170 </html>
|