1class SmartVideoAll { 2 constructor() { 3 this.video_block = ".js-video-block"; 4 this.video_btn = ".js-video-block-btn"; 5 this.video_modal_btn = ".js-video-modal-btn"; 6 this.video_modal = ".js-video-modal"; 7 this.video_video = ".js-video-block-video"; 8 this.video_frame = ".js-video-block-frame"; 9 10 this.provider = { 11 VK: 'vk', 12 VK_VIDEO: 'vkontakte', 13 VK_CLIP: 'vkontakte_clip', 14 YOUTUBE: 'youtube', 15 RUTUBE: 'rutube', 16 FILE: 'file', 17 }; 18 19 this.providerValues = new Set(Object.values(this.provider)); 20 21 this.bsModal = null; 22 this.bsModalDialog = null; 23 this.bsModalContainer = null; 24 } 25 26 _getProvider(url = null) { 27 let provider = null; 28 29 if (url){ 30 let type_youtube = url.match(/((?:https?:)?\/\/)?((?:www|m)\.)?((?:youtube(?:-nocookie)?\.com|youtu.be))(\/(?:[\w\-]+\?v=|embed\/|live\/|v\/)?)([\w\-]+)(\S+)?$/); 31 let type_vk = url.match(/(http:\/\/|https:\/\/)?(www.)?(vk\.com|vkontakte\.ru|vk\.ru|vkvideo\.ru)/); 32 let type_rutube = url.match(/(http:\/\/|https:\/\/)?(www.)?(rutube\.ru)/); 33 34 if (type_youtube) { 35 provider = this.provider.YOUTUBE; 36 } else if (type_vk) { 37 provider = this.provider.VK; 38 } else if (type_rutube) { 39 provider = this.provider.RUTUBE; 40 } 41 } 42 43 return provider; 44 } 45 46 PlayVideo(event) { 47 const block = event.target.closest(this.video_block); 48 49 if (!block) { 50 return; 51 } 52 53 const frame = block.querySelector(this.video_frame); 54 55 if (!frame) { 56 return; 57 } 58 59 frame.src += "?autoplay=1&controls=0&showinfo=0&rel=0"; 60 61 block 62 .querySelector(this.video_video) 63 .classList.add("play"); 64 65 }; 66 67 PlayVideoModal(url, provider, type = null) { 68 if (url) { 69 this.bsModal.show(); 70 71 let content = ""; 72 73 if (provider === this.provider.FILE) { 74 content = ` 75 <video 76 id="modalVideo" 77 controls 78 autoplay 79 playsinline 80 preload="metadata" 81 style="width:100%;height:100%;" 82 > 83 <source src="${url}"> 84 ÐÐ°Ñ Ð±ÑаÑÐ·ÐµÑ Ð½Ðµ поддеÑÐ¶Ð¸Ð²Ð°ÐµÑ Ð²Ð¾ÑпÑоизведение видео. 85 </video>`; 86 } else { 87 content = ` 88 <iframe 89 id="modalVideoIFrame" 90 src="${url}" 91 frameborder="0" 92 allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; screen-wake-lock; fullscreen;" 93 allowfullscreen 94 webkitAllowFullScreen 95 mozallowfullscreen> 96 </iframe>`; 97 } 98 99 if (type && type === "shorts"){ 100 this.bsModalDialog.classList.remove("modal-xl"); 101 this.bsModalDialog.classList.add("modal-sm"); 102 103 this.bsModalContainer.innerHTML = content; 104 this.bsModalContainer.setAttribute('style', "--bs-aspect-ratio: 177% !important;"); 105 } else { 106 this.bsModalContainer.innerHTML = content; 107 } 108 109 if (provider === this.provider.RUTUBE) { 110 setTimeout(() => { 111 let video = document.getElementById('modalVideoIFrame'); 112 video.contentWindow.postMessage(JSON.stringify({ 113 type: 'player:play', 114 data: {} 115 }), '*'); 116 }, 1000); 117 } 118 } else { 119 alert("ÐÑоизоÑла оÑибка пÑи оÑкÑÑÑии видео... ÐÑ Ñже ÑазбиÑаемÑÑ Ñ Ð¿Ñоблемой!") 120 } 121 }; 122 123 124 init() { 125 126 document.querySelectorAll(`${this.video_btn}
126:not([data-video-initialized])`).forEach(btn => { 127 btn.dataset.videoInitialized = "1"; 128 btn.addEventListener("click", event => this.PlayVideo(event)); 129 }); 130 131 const listVideoModal = document.querySelectorAll(`${this.video_modal_btn}:not([data-video-initialized])`); 132 133 if (listVideoModal.length){ 134 const modal = document.querySelector(this.video_modal); 135 136 if (modal) { 137 this.bsModal = bootstrap.Modal.getOrCreateInstance(modal); 138 this.bsModalContainer = modal.querySelector(".ratio"); 139 this.bsModalDialog = modal.querySelector(".modal-dialog"); 140 141 listVideoModal.forEach(btn => { 142 btn.dataset.videoInitialized = "1"; 143 btn.addEventListener("click", event => { 144 let url = event.currentTarget.dataset.url; 145 let provider = event.currentTarget.dataset.provider; 146 let type = event.currentTarget.dataset.type; 147 148 if (provider){ 149 if (this.providerValues.has(provider)) { 150 // коÑÑекÑнÑй пÑÐ¾Ð²Ð°Ð¹Ð´ÐµÑ 151 152 if (!type && provider === this.provider.VK_CLIP) { 153 type = 'shorts'; 154 } 155 156 if (url !== undefined && url !== ""){ 157 this.PlayVideoModal(url, provider, type); 158 } else { 159 console.error("ÐÐ»Ñ Ð²Ð¸Ð´ÐµÐ¾ не пеÑедан URL"); 160 console.log(event.target) 161 } 162 } else { 163 console.error("ÐеизвеÑÑнÑй пÑÐ¾Ð²Ð°Ð¹Ð´ÐµÑ Ñ Ð²Ð¸Ð´ÐµÐ¾: " , url); 164 } 165 } else { 166 // Ð´Ð»Ñ ÑÐ¾Ñ ÑÐ°Ð½ÐµÐ½Ð¸Ñ ÑовмеÑÑимоÑÑи Ñо ÑÑаÑÑми веÑÑиÑми 167 let url_video = null; 168 provider = this._getProvider(url); 169 170 switch (provider){ 171 case this.provider.YOUTUBE: 172 let youtube_video_url = url.match(/(?:https?:)?(?:\/\/)?(?:[0-9A-Z-]+\.)?(?:youtu\.be\/|youtube(?:-nocookie)?\.com\S*?[^\w\s-])([\w-]{11})(?=[^\w-]|$)(?![?=&+%\w.-]*(?:[^<>]*>|<\/a>))[?=&+%\w.-]*/); 173 174 if (youtube_video_url){ 175 url_video = "https://www.youtube.com/embed/" + youtube_video_url[1] + "?autoplay=1&controls=1&showinfo=0&rel=0"; 176 } else { 177 url_video = url; 178 } 179 180 break; 181 case this.provider.VK: 182 if (url.toLowerCase().includes('video_ext.php')){ 183 if (url.toLowerCase().includes('autoplay')){ 184 url_video = url; 185 } else { 186 url_video = url + '&autoplay=1'; 187 } 188 } else { 189 let id_video = url.split(/\/video|\/video-|_/); 190 191 if (id_video.length >= 3){ 192 url_video = 'https://vk.com/video_ext.php?oid='+ id_video[1] + '&id=' + id_video[2] + '&autoplay=1'; 193 } else { 194 let id_video = url.split(/\/clip|\/clip-|_/); 195 196 if (id_video.length >= 3){ 197 url_video = 'https://vk.com/video_ext.php?oid='+ id_video[1] + '&id=' + id_video[2] + '&autoplay=1'; 198 } 199 } 200 } 201 break; 202 case this.provider.RUTUBE: 203 url = url.replace('shorts', 'video'); 204 if (url.toLowerCase().includes('play/embed')){ 205 url_video = url; 206 } else { 207 let id_video = url.split(/\/video\/|\//); 208 209 if (id_video.length >= 3){ 210 url_video = 'https://rutube.ru/play/embed/'+ id_video[3]; 211 } 212 } 213 214 break; 215 } 216 217 this.PlayVideoModal(url_video, provider, type); 218 } 219 }); 220 }); 221 222 modal.addEventListener("hidden.bs.modal", () => { 223 this.bsModalDialog.classList.remove("modal-sm"); 224 this.bsModalDialog.classList.add("modal-xl"); 225 226 this.bsModalContainer.innerHTML = ""; 227 this.bsModalContainer.removeAttribute('style'); 228 }); 229 } else { 230 console.error("ÐÐµÑ Ð¼Ð¾Ð´Ð°Ð»Ñного окна Ð´Ð»Ñ Ð²Ñвода видео"); 231 } 232 } 233 } 234} 235 236window.smartVideo = new SmartVideoAll(); 237window.smartVideo.init();
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.