Открыть меню
Переключить меню настроек
Открыть персональное меню
Вы не представились системе
Ваш IP-адрес будет виден всем, если вы внесёте какие-либо изменения.

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

Страница интерфейса MediaWiki
Нет описания правки
Нет описания правки
 
(не показано 49 промежуточных версий 3 участников)
Строка 1: Строка 1:
const pageName = mw.config.get("wgPageName");
const pageName = mw.config.get("wgPageName");
mw.loader.using([], function () {
    importScript("MediaWiki:PageDefaultAttributes.js");
});
// Отображение онлайна
document.querySelectorAll(".server-hook").forEach(function(element) {
    var ip = element.getAttribute("data-ip");
    var port = element.getAttribute("data-port");
    var url = "https://wiki.ss13-bluemoon.ru/nodeapi/status?ip=" + encodeURIComponent(ip) + "&port=" + encodeURIComponent(port);
    fetch(url).then(function(response) {
        if (!response.ok) {
            throw new Error(response.status);
        }
        return response.json();
    }).then(function(data) {
        element.textContent = data.response.players;
    }).catch(function(error) {
        element.textContent = "⨉";
    });
});
// Интерактивная таблица


if (pageName != "Шаблон:Таблица_Космический_Закон") {
if (pageName != "Шаблон:Таблица_Космический_Закон") {
Строка 6: Строка 30:
     const table = document.getElementById("law");
     const table = document.getElementById("law");
     if (table) {
     if (table) {
         table.addEventListener("click", function (event) {
         table.addEventListener("click", function(event) {
        const cell = event.target.closest("td");
            const cell = event.target.closest("td");
        if (!cell) return;
            if (!cell) return;
        if (!cell.dataset.id) return;
            if (!cell.dataset.id) return;
   
            if (current !== null) {
        if (current !== null) {
                document.getElementById(current).style.display = "none";
            document.getElementById(current).style.display = "none";
                if (currentCell) currentCell.classList.remove("law-selected");
            if (currentCell) currentCell.classList.remove("law-selected");
            }
        }
            if (cell.dataset.id === current) {
       
                current = null;
        if (cell.dataset.id === current) {
                currentCell = null;
            current = null;
                return;
            currentCell = null;
            }
            return;
            current = cell.dataset.id;
        }
            currentCell = cell;
       
            document.getElementById(current).style.display = "block";
        current = cell.dataset.id;
            cell.classList.add("law-selected");
        currentCell = cell;
       
        document.getElementById(current).style.display = "block";
        cell.classList.add("law-selected");
         });
         });
     }
     }
Строка 34: Строка 54:
}
}


mw.loader.using('jquery', function () {
// Вертикальный tabs
  $(function () {
 
    $('.vtabs').each(function () {
mw.loader.using('jquery', function() {
      const $container = $(this);
    $(function() {
      const $buttons = $container.find('.vtabs-button');
        $('.vtabs').each(function() {
      const $contents = $container.find('.vtabs-content');
            const $container = $(this);
            const $buttons = $container.find('.vtabs-button');
            const $contents = $container.find('.vtabs-content');
            $buttons.each(function(index) {
                $(this).on('click', function() {
                    $buttons.removeClass('active');
                    $contents.removeClass('active');
                    $(this).addClass('active');
                    $contents.eq(index).addClass('active');
                });
            });
        });
    });
});


      $buttons.each(function (index) {
// Сворачиваемая строка
        $(this).on('click', function () {
          $buttons.removeClass('active');
          $contents.removeClass('active');


          $(this).addClass('active');
mw.loader.using('mediawiki.util', function() {
          $contents.eq(index).addClass('active');
    $(function() {
        $('.colstr-header').each(function() {
            $(this).on('click', function() {
                const $panel = $(this).closest('.colstr-panel');
                const isOpen = $panel.toggleClass('open').hasClass('open');
                $(this).attr('aria-expanded', isOpen);
            });
         });
         });
      });
     });
     });
  });
});
});


mw.loader.using('mediawiki.util', function () {
// Пасхалка буква жопа
  $(function () {
 
    $('.colstr-header').each(function () {
mw.loader.using('mediawiki.util', function() {
      $(this).on('click', function () {
    mw.util.addPortletLink(
         const $panel = $(this).closest('.colstr-panel');
        'p-personal',
         const isOpen = $panel.toggleClass('open').hasClass('open');
        '#',
         $(this).attr('aria-expanded', isOpen);
        ' ',
      });
         'pt-omode',
         ' '
    ).addEventListener('click', function(e) {
         e.preventDefault();
        toggleSecret();
     });
     });
  });
 
    if (localStorage.getItem('ѾmodeEnabled') === 'true') {
        startSecret();
    }
});
});


function startSecret() {
    function getVisibleTextNodes(root) {
        let nodes = [];
        function walk(node) {
            if (node.nodeType === Node.TEXT_NODE) {
                if (node.nodeValue.trim() !== "" && node.parentNode.offsetParent !== null) {
                    nodes.push(node);
                }
            } else if (node.nodeType === Node.ELEMENT_NODE && node.tagName !== "SCRIPT" && node.tagName !== "STYLE") {
                for (let child of node.childNodes) walk(child);
            }
        }
        walk(root);
        return nodes;
    }
    let textNodes = getVisibleTextNodes(document.body);
    let matches = [];
    for (let node of textNodes) {
        let regex = /от/gi;
        let match;
        while ((match = regex.exec(node.nodeValue)) !== null) {
            matches.push({
                node,
                start: match.index,
                length: match[0].length
            });
        }
    }
    function replaceNext() {
        if (matches.length === 0) return;
        let randIndex = Math.floor(Math.random() * matches.length);
        let {
            node,
            start,
            length
        } = matches.splice(randIndex, 1)[0];
        let chars = node.nodeValue.split("");
        chars.splice(start, length, "Ѿ");
        node.nodeValue = chars.join("");
        matches = matches.filter(m => m.node !== node || m.start > start);
        setTimeout(replaceNext, 1);
    }


let isJopa = false;
     replaceNext();
if (pageName == "Заглавная_страница") {
  document.querySelector('.pashalka-jopa-trigger').addEventListener('click', () => {
     if (isJopa) return;
    const container = document.querySelector('.pashalka-jopa');
    const jopa = document.createElement('div');
    jopa.className = 'jopa';
    jopa.textContent = '>Ѡ<';
    container.appendChild(jopa);
    isJopa = true;
  });
}
}


 
function toggleSecret() {
document.querySelectorAll(".server-hook").forEach(function(element) {
    if (localStorage.getItem('ѾmodeEnabled') === 'true') {
        var ip = element.getAttribute("data-ip");
         localStorage.setItem('ѾmodeEnabled', 'false');
        var port = element.getAttribute("data-port");
        location.reload();
        var url = "https://wiki.ss13-bluemoon.ru/nodeapi/status?ip="+encodeURIComponent(ip)+"&port="+encodeURIComponent(port);
    } else {
         fetch(url)
        localStorage.setItem('ѾmodeEnabled', 'true');
            .then(function(response) {
        location.reload();
                    if (!response.ok) {
    }
                        throw new Error(response.status);
}
                    }
                    return response.json();
            })
            .then(function(data) {
                element.textContent = data.response.players;
            })
            .catch(function(error) {
                element.textContent = "⨉";
            });
  });

Текущая версия от 14:54, 24 октября 2025

const pageName = mw.config.get("wgPageName");

mw.loader.using([], function () {
    importScript("MediaWiki:PageDefaultAttributes.js");
});

// Отображение онлайна

document.querySelectorAll(".server-hook").forEach(function(element) {
    var ip = element.getAttribute("data-ip");
    var port = element.getAttribute("data-port");
    var url = "https://wiki.ss13-bluemoon.ru/nodeapi/status?ip=" + encodeURIComponent(ip) + "&port=" + encodeURIComponent(port);
    fetch(url).then(function(response) {
        if (!response.ok) {
            throw new Error(response.status);
        }
        return response.json();
    }).then(function(data) {
        element.textContent = data.response.players;
    }).catch(function(error) {
        element.textContent = "⨉";
    });
});

// Интерактивная таблица

if (pageName != "Шаблон:Таблица_Космический_Закон") {
    let current = null;
    let currentCell = null;
    const table = document.getElementById("law");
    if (table) {
        table.addEventListener("click", function(event) {
            const cell = event.target.closest("td");
            if (!cell) return;
            if (!cell.dataset.id) return;
            if (current !== null) {
                document.getElementById(current).style.display = "none";
                if (currentCell) currentCell.classList.remove("law-selected");
            }
            if (cell.dataset.id === current) {
                current = null;
                currentCell = null;
                return;
            }
            current = cell.dataset.id;
            currentCell = cell;
            document.getElementById(current).style.display = "block";
            cell.classList.add("law-selected");
        });
    }
} else {
    const allObjects = document.querySelectorAll(".law-object");
    allObjects.forEach(el => el.style.display = "block");
}

// Вертикальный tabs

mw.loader.using('jquery', function() {
    $(function() {
        $('.vtabs').each(function() {
            const $container = $(this);
            const $buttons = $container.find('.vtabs-button');
            const $contents = $container.find('.vtabs-content');
            $buttons.each(function(index) {
                $(this).on('click', function() {
                    $buttons.removeClass('active');
                    $contents.removeClass('active');
                    $(this).addClass('active');
                    $contents.eq(index).addClass('active');
                });
            });
        });
    });
});

// Сворачиваемая строка

mw.loader.using('mediawiki.util', function() {
    $(function() {
        $('.colstr-header').each(function() {
            $(this).on('click', function() {
                const $panel = $(this).closest('.colstr-panel');
                const isOpen = $panel.toggleClass('open').hasClass('open');
                $(this).attr('aria-expanded', isOpen);
            });
        });
    });
});

// Пасхалка буква жопа

mw.loader.using('mediawiki.util', function() {
    mw.util.addPortletLink(
        'p-personal',
        '#',
        ' ',
        'pt-omode',
        ' '
    ).addEventListener('click', function(e) {
        e.preventDefault();
        toggleSecret();
    });

    if (localStorage.getItem('ѾmodeEnabled') === 'true') {
        startSecret();
    }
});

function startSecret() {
    function getVisibleTextNodes(root) {
        let nodes = [];
        function walk(node) {
            if (node.nodeType === Node.TEXT_NODE) {
                if (node.nodeValue.trim() !== "" && node.parentNode.offsetParent !== null) {
                    nodes.push(node);
                }
            } else if (node.nodeType === Node.ELEMENT_NODE && node.tagName !== "SCRIPT" && node.tagName !== "STYLE") {
                for (let child of node.childNodes) walk(child);
            }
        }
        walk(root);
        return nodes;
    }

    let textNodes = getVisibleTextNodes(document.body);
    let matches = [];
    for (let node of textNodes) {
        let regex = /от/gi;
        let match;
        while ((match = regex.exec(node.nodeValue)) !== null) {
            matches.push({
                node,
                start: match.index,
                length: match[0].length
            });
        }
    }

    function replaceNext() {
        if (matches.length === 0) return;
        let randIndex = Math.floor(Math.random() * matches.length);
        let {
            node,
            start,
            length
        } = matches.splice(randIndex, 1)[0];
        let chars = node.nodeValue.split("");
        chars.splice(start, length, "Ѿ");
        node.nodeValue = chars.join("");
        matches = matches.filter(m => m.node !== node || m.start > start);
        setTimeout(replaceNext, 1);
    }

    replaceNext();
}

function toggleSecret() {
    if (localStorage.getItem('ѾmodeEnabled') === 'true') {
        localStorage.setItem('ѾmodeEnabled', 'false');
        location.reload();
    } else {
        localStorage.setItem('ѾmodeEnabled', 'true');
        location.reload();
    }
}