MediaWiki:Common.js: различия между версиями

Случайно затёр
повысим надёжностьВК
Метка: отменено
Строка 68: Строка 68:


/* Вставка VK-видео на страницу для шаблона {{VKVideo}} */
/* Вставка VK-видео на страницу для шаблона {{VKVideo}} */
(function() {
(function() {  
     'use strict';
     'use strict';  
      
      
     function initVKVideo() {
     function initVKVideo() {  
         var containers = document.querySelectorAll('.vk-video-js');
         var containers = document.querySelectorAll('.vk-video-js');  
          
          
         for (var i = 0; i < containers.length; i++) {
         for (var i = 0; i < containers.length; i++) {  
             var container = containers[i];
             var container = containers[i];  
             var oid = container.getAttribute('data-oid');
             var oid = container.getAttribute('data-oid');  
             var id = container.getAttribute('data-id');
             var id = container.getAttribute('data-id');  
             var width = container.getAttribute('data-width') || '560';
             var width = container.getAttribute('data-width') || '560';  
             var height = container.getAttribute('data-height') || '315';
             var height = container.getAttribute('data-height') || '315';  
              
              
             width = parseInt(width) || 560;
             width = parseInt(width) || 560;  
             height = parseInt(height) || 315;
             height = parseInt(height) || 315;  
            if (width > 2000) width = 2000;
            if (height < 100) height = 100;
            if (height > 2000) height = 2000;
              
              
             if (oid && id && oid !== 'null' && id !== 'null' && /^[-_a-zA-Z0-9]+$/.test(oid) && /^[-_a-zA-Z0-9]+$/.test(id)) {
            if (width > 2000) width = 2000;
                 var iframe = document.createElement('iframe');
            if (height < 100) height = 100;
                 iframe.src = 'https://vk.com/video_ext.php?oid=' + encodeURIComponent(oid) + '&id=' + encodeURIComponent(id);
            if (height > 2000) height = 2000;
                 iframe.width = width;
           
                 iframe.height = height;
             if (oid && id && oid !== 'null' && id !== 'null' && /^[-_a-zA-Z0-9]+$/.test(oid) && /^[-_a-zA-Z0-9]+$/.test(id)) {  
                 iframe.frameBorder = '0';
                 var iframe = document.createElement('iframe');  
                 iframe.allowFullscreen = true;
                 iframe.src = 'https://vk.com/video_ext.php?oid=' + encodeURIComponent(oid) + '&id=' + encodeURIComponent(id);  
                 iframe.width = width;  
                 iframe.height = height;  
                 iframe.frameBorder = '0';  
                 iframe.allowFullscreen = true;  
                  
                  
                 iframe.sandbox = 'allow-scripts allow-same-origin allow-presentation allow-fullscreen';
                 iframe.sandbox = 'allow-scripts allow-presentation allow-fullscreen';
                 iframe.allow = 'fullscreen';
                 iframe.allow = 'fullscreen';
                iframe.referrerPolicy = 'no-referrer';
                iframe.loading = 'lazy';
                  
                  
                 iframe.style.border = 'none';
                 iframe.style.border = 'none';
                iframe.style.pointerEvents = 'auto';
                  
                  
                 while (container.firstChild) {
                 if ('credentialless' in iframe) {
                     container.removeChild(container.firstChild);
                     iframe.credentialless = true;
                 }
                 }
                 container.appendChild(iframe);
               
                while (container.firstChild) {
                    container.removeChild(container.firstChild);
                }
                 container.appendChild(iframe);  
             } else {
             } else {
                 var errorDiv = document.createElement('div');
                 var errorDiv = document.createElement('div');  
                 errorDiv.style.cssText = 'color: red; padding: 10px; text-align: center; border: 1px solid red;';
                 errorDiv.style.cssText = 'color: red; padding: 10px; text-align: center; border: 1px solid red;';  
                 errorDiv.textContent = 'Ошибка: неверные параметры видео';
                 errorDiv.textContent = 'Ошибка: неверные параметры видео';  
               
                 while (container.firstChild) {  
                 while (container.firstChild) {
                     container.removeChild(container.firstChild);  
                     container.removeChild(container.firstChild);
                 }  
                 }
                 container.appendChild(errorDiv);  
                 container.appendChild(errorDiv);
             }  
             }
         }  
         }
     }  
     }
      
      
     if (document.readyState === 'loading') {
     if (document.readyState === 'loading') {  
         document.addEventListener('DOMContentLoaded', initVKVideo);
         document.addEventListener('DOMContentLoaded', initVKVideo);  
     } else {
     } else {  
         initVKVideo();
         initVKVideo();  
     }
     }  
})();
})();


/* Вставка Rutube-видео на страницу для шаблона {{Rutube}} */
/* Вставка Rutube-видео на страницу для шаблона {{Rutube}} */