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

Материал из Абсурдопедии
Перейти к навигации Перейти к поиску
С ембедом
Откат правки 362378 участника Тэйтанка-птекила (обс.)
Метка: отмена
 
(не показано 57 промежуточных версий этого же участника)
Строка 1: Строка 1:
/* Нигилистические фокусы (см. [[Шаблон:Нигилизм/doc]]) */
/* Нигилистические фокусы (см. шаблон {{tl|Нигилизм}}) */
$(function () {
$(function () {
     var nihilism = $('#nihilism');
     var nihilism = $('#nihilism');
Строка 20: Строка 20:
});
});


/* Стирание памяти для «Людей в чёрном» */
/* Стирание памяти для [[MIB]] («Людей в чёрном») */
$(function () {
$(function () {
     if ($("#erase_memory")[0])
     if ($("#erase_memory")[0])
Строка 50: Строка 50:
/* Вставка юзернейма с помощью <span class="insertusername"></span> */
/* Вставка юзернейма с помощью <span class="insertusername"></span> */
$(function () {
$(function () {
     if ((typeof (disableUsernameReplace) == "undefined" || !disableUsernameReplace) && mw.config.get("wgUserName") !== null)
     if ((typeof (disableUsernameReplace) == "undefined" || !disableUsernameReplace) && mw.config.get("wgUserName") !== null) {
         $("span.insertusername").html(mw.config.get("wgUserName"));
        var username = mw.config.get("wgUserName");
         $("span.insertusername").text(username);
    }
});
});


function defaultUploadInfo() {
    var rewrite = document.getElementById("wpForReUpload");
    if (!rewrite) return;
    if (rewrite.value == 1) return;
    var d = document.getElementById("wpUploadDescription");
    if (d) {
        if (!d.value.match(/\[\[(Категория|Category):/)) {
            d.value += "\n\n\n[[Категория:Некатегоризованные изображения]]";
        }
    }
}


/* Замена категорий для шаблона {{Cats}} */
/* Замена категорий для шаблона {{Cats}} */
Строка 77: Строка 67:




/* Функция для вставки VK-видео на страницу для шаблона VKVideo, простая версия */
/* Вставка VK-видео на страницу для шаблона {{VKVideo}} */
window.vkVideoInit = function() {
    console.log('VK Video: Initializing...');
   
    var containers = document.querySelectorAll('.vk-video-js');
    console.log('VK Video: Found ' + containers.length + ' containers');
   
    for (var i = 0; i < containers.length; i++) {
        var container = containers[i];
        var oid = container.getAttribute('data-oid');
        var id = container.getAttribute('data-id');
        var width = container.getAttribute('data-width') || '640';
        var height = container.getAttribute('data-height') || '360';
       
        console.log('VK Video: Container ' + i + ' - oid:' + oid + ' id:' + id);
       
        if (oid && id && oid !== 'null' && id !== 'null') {
            var iframe = document.createElement('iframe');
            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.style.border = 'none';
            iframe.style.borderRadius = '4px';
           
            container.innerHTML = '';
            container.appendChild(iframe);
            console.log('VK Video: Container ' + i + ' - SUCCESS');
        } else {
            console.error('VK Video: Container ' + i + ' - MISSING DATA');
            container.innerHTML = '<div style="color: red; padding: 10px; text-align: center; border: 1px solid red;">Ошибка: неверные параметры видео</div>';
        }
    }
};
 
    /* Запускаем после загрузки ВК-видео DOM */
if (document.readyState === 'loading') {
    document.addEventListener('DOMContentLoaded', window.vkVideoInit);
} else {
    window.vkVideoInit();
}
 
 
/* Функция для вставки Rutube-видео на страницу для шаблона Rutube, простая версия */
(function() {
(function() {
     'use strict';
     'use strict';
      
      
     function initRutubePlayers() {
     function initVKVideo() {
         var players = document.querySelectorAll('.rutube-player[data-video-id]');
         var containers = document.querySelectorAll('.vk-video-js');
          
          
         players.forEach(function(player) {
         for (var i = 0; i < containers.length; i++) {
             if (player.classList.contains('rutube-processed')) return;
             var container = containers[i];
            var oid = container.getAttribute('data-oid');
            var id = container.getAttribute('data-id');
            var width = container.getAttribute('data-width') || '560';
            var height = container.getAttribute('data-height') || '315';
              
              
             var videoId = player.getAttribute('data-video-id');
             width = parseInt(width) || 560;
             var width = player.getAttribute('data-width') || '560';
             height = parseInt(height) || 315;
             var height = player.getAttribute('data-height') || '315';
            if (width > 1920) width = 1920;
             if (height < 100) height = 100;
            if (height > 1080) height = 1080;
              
              
             if (videoId) {
             if (oid && id && oid !== 'null' && id !== 'null' && /^[a-zA-Z0-9_-]{1,100}$/.test(oid) && /^[-_a-zA-Z0-9]+$/.test(id)) {
                 var iframe = document.createElement('iframe');
                 var iframe = document.createElement('iframe');
                 iframe.src = 'https://rutube.ru/play/embed/' + videoId + '?p=Ib&brandPlayerUrl=';
                 iframe.src = 'https://vk.com/video_ext.php?oid=' + encodeURIComponent(oid) + '&id=' + encodeURIComponent(id);
                 iframe.width = width;
                 iframe.width = width;
                 iframe.height = height;
                 iframe.height = height;
                 iframe.frameBorder = '0';
                 iframe.frameBorder = '0';
                iframe.allow = 'autoplay; encrypted-media; fullscreen; picture-in-picture';
                 iframe.allowFullscreen = true;
                 iframe.allowFullscreen = true;
                iframe.referrerPolicy = 'no-referrer-when-downgrade';
                  
                  
                iframe.sandbox = 'allow-scripts allow-same-origin allow-presentation allow-fullscreen';
                iframe.allow = 'fullscreen';
                iframe.referrerPolicy = 'no-referrer';
                iframe.loading = 'lazy';
                 iframe.style.border = 'none';
                 iframe.style.border = 'none';
                iframe.style.display = 'block';
                iframe.style.maxWidth = '100%';
                  
                  
                 player.innerHTML = '';
                 while (container.firstChild) {
                 player.appendChild(iframe);
                    container.removeChild(container.firstChild);
                 player.classList.add('rutube-processed');
                 }
                container.appendChild(iframe);
            } else {
                var errorDiv = document.createElement('div');
               
                errorDiv.style.color = 'red';
                errorDiv.style.padding = '10px';
                errorDiv.style.textAlign = 'center';
                errorDiv.style.border = '1px solid';
                 errorDiv.style.backgroundColor = '#fff';
                errorDiv.style.fontFamily = 'Arial, sans-serif';
                errorDiv.style.fontSize = '14px';
                errorDiv.style.margin = '5px 0';
 
                errorDiv.textContent = 'Ошибка: неверные параметры видео';
               
                while (container.firstChild) {
                    container.removeChild(container.firstChild);
                }
                container.appendChild(errorDiv);
             }
             }
         });
         }
     }
     }
      
      
  /*  Запускаем при полной загрузке DOM */
     if (document.readyState === 'loading') {
     if (document.readyState === 'loading') {
         document.addEventListener('DOMContentLoaded', initRutubePlayers);
         document.addEventListener('DOMContentLoaded', initVKVideo);
     } else {
     } else {
         initRutubePlayers();
         initVKVideo();
     }
     }
   
  /* Также запускаем при динамической загрузке контента
    if (typeof mw !== 'undefined' && mw.hook) {
        mw.hook('wikipage.content').add(initRutubePlayers);
    }
   
})();
})();

Текущая версия от 04:03, 4 июня 2026

/* Нигилистические фокусы (см. шаблон {{tl|Нигилизм}}) */
$(function () {
    var nihilism = $('#nihilism');
    if (nihilism[0] && !document.location.href.match("diff")) {
        var msg = nihilism.html();
        if (!nihilism.hasClass('nihilism-no-white')) {
        	$('body').css('background-color', 'white');
        }
        var scripts = $('script');
        var bodyNihilism = $('body').html('');
        var divNihilism = $('<div class="mw-parser-output"></div>').html(msg);
        if (nihilism.css('top') == '0px') {
        	bodyNihilism.css('top', '0px').css('left', '0px');
        }
        bodyNihilism.append(divNihilism).append(scripts);
        $(document).dblclick(function () {
        	window.location = mw.util.getUrl(null, {'action': 'edit'});
        });
    }
});

/* Стирание памяти для [[MIB]] («Людей в чёрном») */
$(function () {
    if ($("#erase_memory")[0])
        setTimeout(function () { $("#erase_memory").hide(); }, 20000);
});

/* Ссылка «править» для нулевой секции */
$(function () {
    var zeroSectionTip = "Править введение";

    if (!mw.config.get("wgArticleId")) {
        return;
    }

    var action = mw.config.get("wgAction");
    if (action != "view" && action != "purge")
        return;

    mw.util.$content.find("h2").children(".mw-editsection:first").clone().prependTo("#bodyContent").css("float", "right").find("a").each(function (index) {
        $(this).attr("title", zeroSectionTip);
        if ($(this).attr("class") === "mw-editsection-visualeditor") {
            $(this).attr("href", mw.config.get("wgScript") + "?title=" + mw.util.wikiUrlencode(mw.config.get("wgPageName")) + "&veaction=edit&vesection=0&summary=/*%20Преамбула%20*/%20");
        } else {
            $(this).attr("href", mw.config.get("wgScript") + "?title=" + mw.util.wikiUrlencode(mw.config.get("wgPageName")) + "&action=edit&section=0&summary=/*%20Преамбула%20*/%20");
        }
    });
});

/* Вставка юзернейма с помощью <span class="insertusername"></span> */
$(function () {
    if ((typeof (disableUsernameReplace) == "undefined" || !disableUsernameReplace) && mw.config.get("wgUserName") !== null) {
        var username = mw.config.get("wgUserName");
        $("span.insertusername").text(username);
    }
});


/* Замена категорий для шаблона {{Cats}} */
$(function () {
    var categoriesAlternative = $("#categories_alternative");
    if (categoriesAlternative[0]) {
        $('#mw-normal-catlinks').html(categoriesAlternative.html());
        categoriesAlternative.hide();
    }
});


/* Вставка VK-видео на страницу для шаблона {{VKVideo}} */
(function() {
    'use strict';
    
    function initVKVideo() {
        var containers = document.querySelectorAll('.vk-video-js');
        
        for (var i = 0; i < containers.length; i++) {
            var container = containers[i];
            var oid = container.getAttribute('data-oid');
            var id = container.getAttribute('data-id');
            var width = container.getAttribute('data-width') || '560';
            var height = container.getAttribute('data-height') || '315';
            
            width = parseInt(width) || 560;
            height = parseInt(height) || 315;
            if (width > 1920) width = 1920;
            if (height < 100) height = 100;
            if (height > 1080) height = 1080;
            
            if (oid && id && oid !== 'null' && id !== 'null' && /^[a-zA-Z0-9_-]{1,100}$/.test(oid) && /^[-_a-zA-Z0-9]+$/.test(id)) {
                var iframe = document.createElement('iframe');
                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.allow = 'fullscreen';
                iframe.referrerPolicy = 'no-referrer';
                iframe.loading = 'lazy';
                iframe.style.border = 'none';
                
                while (container.firstChild) {
                    container.removeChild(container.firstChild);
                }
                container.appendChild(iframe);
            } else {
                var errorDiv = document.createElement('div');
                
                errorDiv.style.color = 'red';
                errorDiv.style.padding = '10px';
                errorDiv.style.textAlign = 'center';
                errorDiv.style.border = '1px solid';
                errorDiv.style.backgroundColor = '#fff';
                errorDiv.style.fontFamily = 'Arial, sans-serif';
                errorDiv.style.fontSize = '14px';
                errorDiv.style.margin = '5px 0';

                errorDiv.textContent = 'Ошибка: неверные параметры видео';
                
                while (container.firstChild) {
                    container.removeChild(container.firstChild);
                }
                container.appendChild(errorDiv);
            }
        }
    }
    
    if (document.readyState === 'loading') {
        document.addEventListener('DOMContentLoaded', initVKVideo);
    } else {
        initVKVideo();
    }
})();