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

Материал из Абсурдопедии
Перейти к навигации Перейти к поиску
>Rappy 4187
Fixing JS error. Removing Terms of Use violations and Monobook-only code.
Откат правки 362378 участника Тэйтанка-птекила (обс.)
Метка: отмена
 
(не показаны 103 промежуточные версии 2 участников)
Строка 1: Строка 1:
importScript("MediaWiki:Dynavbar.js");
/* Нигилистические фокусы (см. шаблон {{tl|Нигилизм}}) */
importScript("MediaWiki:Editsumm.js");
$(function () {
importScript("MediaWiki:Gadget-NikAvtoStav.js");
     var nihilism = $('#nihilism');
importScript("MediaWiki:Stars.js");
     if (nihilism[0] && !document.location.href.match("diff")) {
importScript("MediaWiki:Gadget-markadmins.js");
        var msg = nihilism.html();
 
        if (!nihilism.hasClass('nihilism-no-white')) {
function addWikifButton() {
        $('body').css('background-color', 'white');
     var toolbar = (document.getElementById('cke_toolbar_source_1') || document.getElementById('toolbar')); // Monobook+Modern
        }
     if (!toolbar) return;
        var scripts = $('script');
    var i = document.createElement('img');
        var bodyNihilism = $('body').html('');
    i.src = 'http://upload.wikimedia.org/wikisource/ru/d/d1/Button-wikifikator.png';
         var divNihilism = $('<div class="mw-parser-output"></div>').html(msg);
    i.alt = i.title = 'Абсурдофикатор — оформитель текста';
         if (nihilism.css('top') == '0px') {
    i.onclick = Wikify;
        bodyNihilism.css('top', '0px').css('left', '0px');
    i.style.cursor = 'pointer';
         }
    toolbar.appendChild(i);
        bodyNihilism.append(divNihilism).append(scripts);
}
         $(document).dblclick(function () {
if (wgAction == 'edit' || wgAction == 'submit') {
        window.location = mw.util.getUrl(null, {'action': 'edit'});
    importScriptURI('http://ru.wikipedia.org/w/index.php?title=MediaWiki:Wikificator.js&action=raw&ctype=text/javascript');
    addOnloadHook(addWikifButton);
}
 
/* Обеспечиваем фокус с {{sysdep}} — Edward. */
function sysdep_init() {
    var lo = document.getElementById('linux_only');
    var wo = document.getElementById('winds_only');
    if (navigator.userAgent.match("Linux") || navigator.userAgent.match("X11")) {
         if (lo) lo.style.display = "block";
        if (wo) wo.style.display = "none";
    } else {
        if (lo) lo.style.display = "none";
         if (wo) wo.style.display = "block";
    }
}
 
/* Обеспечиваем нигилистические фокусы (см., например, статью [[Google]]) */
$(function() {
    var nhl = $('#nihilism')[0];
    if (nhl && !document.location.href.match("diff")) {
        var msg = nhl.innerHTML;
        $('body')[0].style.backgroundColor = 'white';
         $('body').html("<div id='nihilism_message'" + (nhl.style.top == "0px" ? " style='top: 0px; left: 0px;'" : "") + ">" + msg + "</div>");
         $(document).dblclick(function() {
            window.location = 'http://absurdopedia.wikia.com/index.php?title=' + encodeURIComponent(wgPageName) + '&action=edit';
         });
         });
     }
     }
});
});


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


/* Заставляем работать шаблон {{title}} (удалить этот код, когда заработает {{DISPLAYTITLE}}) */
/* Ссылка «править» для нулевой секции */
function rewrite_title() {
$(function () {
    if (wgAction == "view") {
     var zeroSectionTip = "Править введение";
        p = document.getElementById('correctTitle');
        if (p) {
            document.getElementById('firstHeading').innerHTML = p.innerHTML;
            document.getElementById('wrongTitle').style.display = "none";
        }
    }
}
 
/* + ссылка «править» для нулевой секции. */
$(function() {
     var zeroSectionTip = 'Править введение';


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


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


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


/* Вставка юзернейма с помощью <span class="insertusername"></span> */
/* Вставка юзернейма с помощью <span class="insertusername"></span> */
$(function() {
$(function () {
     if ((typeof(disableUsernameReplace) == 'undefined' || !disableUsernameReplace) && wgUserName != null)
     if ((typeof (disableUsernameReplace) == "undefined" || !disableUsernameReplace) && mw.config.get("wgUserName") !== null) {
         $('span.insertusername').html(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');
/* Замена категорий для шаблона {{Cats}} */
     if (d) {
$(function () {
         if (!d.value.match(/\[\[(Категория|Category):/)) {
     var categoriesAlternative = $("#categories_alternative");
            d.value += "\n\n\n[[Категория:Некатегоризованные изображения]]";
     if (categoriesAlternative[0]) {
        }
         $('#mw-normal-catlinks').html(categoriesAlternative.html());
        categoriesAlternative.hide();
     }
     }
}
});


// addOnloadHook(onPageInit);


/* Ссылка на случайную статью */
/* Вставка VK-видео на страницу для шаблона {{VKVideo}} */
$(function() {
(function() {
     $('.subnav-2a').each(function() {
     'use strict';
        if ($(this).attr('data-canonical') == 'random')
   
             $(this).attr('href', '/wiki/Служебная:RandomInCategory/Абсурдопедия:Случайные статьи');
    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();
    }
})();

Текущая версия от 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();
    }
})();