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

Нет описания правки
Нет описания правки
Строка 63: Строка 63:
     }
     }


     function expandAndFindCategory($parent) {
     function expandAndFindCategory($parent, callback) {
         return new Promise((resolve) => {
         var $toggleButton = $parent.find('.CategoryTreeToggle').first();
            var $toggleButton = $parent.find('.CategoryTreeToggle').first();
        if ($toggleButton.length && !$parent.hasClass('expanded')) {
            if ($toggleButton.length && !$parent.hasClass('expanded')) {
            $toggleButton.click();
                $toggleButton.click();


                setTimeout(() => {
            setTimeout(function() {
                    resolve(scrollToCategory(mw.config.get('wgTitle')));
                if (scrollToCategory(mw.config.get('wgTitle'))) {
                 }, 1000);
                    callback(true);
            } else {
                } else {
                resolve(false);
                    callback(false);
            }
                 }
         });
            }, 1000);
        } else {
            callback(false);
         }
     }
     }


     async function recursiveSearchForCategory() {
     function recursiveSearchForCategory() {
         console.log("Очищаем localStorage перед поиском...");
         console.log("Очищаем localStorage перед поиском...");
         localStorage.removeItem('lastOpenedPageTitle');
         localStorage.removeItem('lastOpenedPageTitle');
Строка 96: Строка 98:


         var $categoryItems = $('#p-categorytree-portlet .CategoryTreeItem');
         var $categoryItems = $('#p-categorytree-portlet .CategoryTreeItem');
         for (var i = 0; i < $categoryItems.length; i++) {
         var index = 0;
             var $item = $($categoryItems[i]);
 
            if (await expandAndFindCategory($item)) {
        function processNext() {
             if (index >= $categoryItems.length) {
                console.log("Категория для текущей страницы не найдена.");
                 return;
                 return;
             }
             }
            var $item = $($categoryItems[index]);
            expandAndFindCategory($item, function(found) {
                if (!found) {
                    index++;
                    processNext();
                }
            });
         }
         }


         console.log("Категория для текущей страницы не найдена.");
         processNext();
     }
     }


     setTimeout(() => {
     setTimeout(function() {
         recursiveSearchForCategory();
         recursiveSearchForCategory();
     }, 500);
     }, 500);