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

Материал из Revera Wiki
Нет описания правки
Метка: отменено
Нет описания правки
Метка: отменено
Строка 4: Строка 4:
     let sidebar = document.getElementById("p-navigation") || document.getElementById("p-tb");
     let sidebar = document.getElementById("p-navigation") || document.getElementById("p-tb");


     if (sidebar && !document.getElementById("reverinDateWidget")) {
     function ensureReverinDateWidget() {
        let dateDiv = document.createElement("div");
        if (sidebar && !document.getElementById("reverinDateWidget")) {
        dateDiv.id = "reverinDateWidget";
            let dateDiv = document.createElement("div");
        dateDiv.style.padding = "10px";
            dateDiv.id = "reverinDateWidget";
        dateDiv.style.borderTop = "1px solid #ccc";
            dateDiv.style.padding = "10px";
        dateDiv.style.marginTop = "10px";
            dateDiv.style.borderTop = "1px solid #ccc";
        dateDiv.style.fontWeight = "bold";
            dateDiv.style.marginTop = "10px";
        dateDiv.style.whiteSpace = "pre-line";
            dateDiv.style.fontWeight = "bold";
        dateDiv.innerText = "Загрузка...";
            dateDiv.style.whiteSpace = "pre-line";
            dateDiv.innerText = "Загрузка реверинской даты...";


        sidebar.appendChild(dateDiv);
            sidebar.appendChild(dateDiv);
            console.log("`#reverinDateWidget` вставлен в сайтбар!");
        }
     }
     }
    function waitForReverinScript(callback) {
        let attempts = 0;
        let checkInterval = setInterval(function() {
            if (typeof window.loadReverinDate === "function") {
                clearInterval(checkInterval);
                console.log("Скрипт `reverin-date.js` загружен, запускаем!");
                window.loadReverinDate();
                callback();
            } else if (attempts >= 20) {
                clearInterval(checkInterval);
                console.error("Ошибка: `reverin-date.js` не загрузился!");
            }
            attempts++;
        }, 250);
    }
    function waitForTooltips() {
        let attempts = 0;
        let checkInterval = setInterval(function() {
            if (typeof window.addTooltipHandlers === "function") {
                clearInterval(checkInterval);
                console.log("Подсказки загружены, запускаем!");
                window.addTooltipHandlers();
            } else if (attempts >= 20) {
                clearInterval(checkInterval);
                console.error("Ошибка: `addTooltipHandlers` не загрузился!");
            }
            attempts++;
        }, 250);
    }
    ensureReverinDateWidget();
    waitForReverinScript(waitForTooltips);
});
});

Версия от 22:56, 25 февраля 2025

mw.loader.load("https://revera.world/js/reverin-date.js");

document.addEventListener("DOMContentLoaded", function() {
    let sidebar = document.getElementById("p-navigation") || document.getElementById("p-tb");

    function ensureReverinDateWidget() {
        if (sidebar && !document.getElementById("reverinDateWidget")) {
            let dateDiv = document.createElement("div");
            dateDiv.id = "reverinDateWidget";
            dateDiv.style.padding = "10px";
            dateDiv.style.borderTop = "1px solid #ccc";
            dateDiv.style.marginTop = "10px";
            dateDiv.style.fontWeight = "bold";
            dateDiv.style.whiteSpace = "pre-line";
            dateDiv.innerText = "Загрузка реверинской даты...";

            sidebar.appendChild(dateDiv);
            console.log("`#reverinDateWidget` вставлен в сайтбар!");
        }
    }

    function waitForReverinScript(callback) {
        let attempts = 0;
        let checkInterval = setInterval(function() {
            if (typeof window.loadReverinDate === "function") {
                clearInterval(checkInterval);
                console.log("Скрипт `reverin-date.js` загружен, запускаем!");
                window.loadReverinDate();
                callback();
            } else if (attempts >= 20) {
                clearInterval(checkInterval);
                console.error("Ошибка: `reverin-date.js` не загрузился!");
            }
            attempts++;
        }, 250);
    }

    function waitForTooltips() {
        let attempts = 0;
        let checkInterval = setInterval(function() {
            if (typeof window.addTooltipHandlers === "function") {
                clearInterval(checkInterval);
                console.log("Подсказки загружены, запускаем!");
                window.addTooltipHandlers();
            } else if (attempts >= 20) {
                clearInterval(checkInterval);
                console.error("Ошибка: `addTooltipHandlers` не загрузился!");
            }
            attempts++;
        }, 250);
    }

    ensureReverinDateWidget();
    waitForReverinScript(waitForTooltips);
});