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

Материал из Русского эксперта
Перейти к навигации Перейти к поиску
Нет описания правки
Нет описания правки
Строка 1: Строка 1:
/* Ссылкоправ */
/* Ссылкоправ */
function addCustomButton() {
document.addEventListener('DOMContentLoaded', function() {
     var toolbar = document.getElementById('toolbar'); // Предполагается, что элемент с id 'toolbar' существует
    // Поиск элемента группы кнопок
     if (!toolbar) {
     var toolbarGroup = document.querySelector('.group.group-insert');
         console.error('Toolbar not found');
     if (!toolbarGroup) {
         console.error('Toolbar group not found');
         return;
         return;
     }
     }


     // Создаем кнопку
     // Создание новой кнопки
     var button = document.createElement('img');
     var button = document.createElement('a');
     button.src = 'https://ruxpert.ru/images/7/72/Ссылкоправ.jpg'; // URL иконки
     button.setAttribute('role', 'button');
     button.alt = 'Ссылкоправ';
    button.setAttribute('title', 'Ссылкоправ');
    button.title = 'Ссылкоправ';
    button.setAttribute('class', 'tool tool-button');
     button.style.cursor = 'pointer';
    button.style.backgroundImage = 'url("https://ruxpert.ru/images/7/72/Ссылкоправ.jpg")';
     button.textContent = 'Ссылкоправ'; // Если вам нужен текст на кнопке
 
     // Добавление обработчика клика
     button.onclick = function() {
     button.onclick = function() {
         alert('Ссылкоправ');
         alert('Ссылкоправ');
     };
     };


     // Добавляем кнопку на панель инструментов
     // Добавление кнопки в группу инструментов
     toolbar.appendChild(button);
     toolbarGroup.appendChild(button);
}
});


// Добавляем кнопку после загрузки страницы
mw.loader.using(['mediawiki.util', 'mediawiki.user'], function () {
    console.error('Here2');
    if (mw.config.get('wgAction') === 'edit' || mw.config.get('wgAction') === 'submit') {
        addCustomButton();
    }
});


console.error('Here1');
console.error('Here3');





Версия от 20:28, 25 января 2024

/* Ссылкоправ */
document.addEventListener('DOMContentLoaded', function() {
    // Поиск элемента группы кнопок
    var toolbarGroup = document.querySelector('.group.group-insert');
    if (!toolbarGroup) {
        console.error('Toolbar group not found');
        return;
    }

    // Создание новой кнопки
    var button = document.createElement('a');
    button.setAttribute('role', 'button');
    button.setAttribute('title', 'Ссылкоправ');
    button.setAttribute('class', 'tool tool-button');
    button.style.backgroundImage = 'url("https://ruxpert.ru/images/7/72/Ссылкоправ.jpg")';
    button.textContent = 'Ссылкоправ'; // Если вам нужен текст на кнопке

    // Добавление обработчика клика
    button.onclick = function() {
        alert('Ссылкоправ');
    };

    // Добавление кнопки в группу инструментов
    toolbarGroup.appendChild(button);
});


console.error('Here3');


/*WikiEditor/Викификатор*/
if ( $.inArray( mw.config.get( 'wgAction' ), ['edit', 'submit'] ) !== -1 ) {
    mw.loader.load( '//ru.wikipedia.org/w/index.php?title=MediaWiki:Gadget-wikificator.js&action=raw&ctype=text/javascript' );
}

var customizeToolbar = function() {
    
    $( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
        'section': 'advanced',
        'group': 'format',
        'tools': {
            'wikify': {
                label: 'Викификатор',
                type: 'button',
                icon: '//upload.wikimedia.org/wikipedia/commons/0/06/Wikify-toolbutton.png',
                action: {
                    type: 'callback',
                    execute: function(context){
                        Wikify();
                    }
                }
            }
        }
    } );
};

if ( $.inArray( mw.config.get( 'wgAction' ), ['edit', 'submit'] ) !== -1 ) {
    mw.loader.using( 'user.options', function () {
        if ( mw.user.options.get('usebetatoolbar') ) {
            mw.loader.using( 'ext.wikiEditor.toolbar', function () {
                $(document).ready( customizeToolbar );
            } );
        }
    } );
};

/*************************/
/* Реклама Яндекс Директ */
/*************************/

/* Реклама Яндекса не должна показываться на страницах редактирования статей, обсуждения статей и участников, страницах участников, служебных страницах, страницах с историей правок. */

var path = decodeURIComponent(window.location.pathname);
if(path.indexOf("Участник:") === -1 && path.indexOf("Обсуждение") === -1 &&
   path.indexOf("index.php") === -1 && path.indexOf("Служебная:") === -1 &&
   path.indexOf("help.php") === -1 && path.indexOf("MediaWiki:") === -1) {

/* Блок 1 */

(function() {
 $('#top').after('<div id="yandex_rtb_R-A-446933-1"></div>');
})();

(function(w, d, n, s, t) {
w[n] = w[n] || [];
w[n].push(function() {
Ya.Context.AdvManager.render({
blockId: "R-A-446933-1",
renderTo: "yandex_rtb_R-A-446933-1",
async: true
});
});
t = d.getElementsByTagName("script")[0];
s = d.createElement("script");
s.type = "text/javascript";
s.src = "//an.yandex.ru/system/context.js";
s.async = true;
t.parentNode.insertBefore(s, t);
})(this, this.document, "yandexContextAsyncCallbacks");

/* Блок 2 */

(function() {
 $('#mw-content-text').after('<div id="yandex_rtb_R-A-446933-2"></div>');
})();

(function(w, d, n, s, t) {
w[n] = w[n] || [];
w[n].push(function() {
Ya.Context.AdvManager.render({
blockId: "R-A-446933-2",
renderTo: "yandex_rtb_R-A-446933-2",
async: true
});
});
t = d.getElementsByTagName("script")[0];
s = d.createElement("script");
s.type = "text/javascript";
s.src = "//an.yandex.ru/system/context.js";
s.async = true;
t.parentNode.insertBefore(s, t);
})(this, this.document, "yandexContextAsyncCallbacks");

}