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

Нет описания правки
Метки: ручная отмена отменено
Нет описания правки
Метка: отменено
Строка 104: Строка 104:
             callback(false);
             callback(false);
         }
         }
    }
    function resetCategoryTree() {
        console.log("Категория не найдена. Очищаем данные и сбрасываем дерево.");
        localStorage.removeItem('categoryTreeHTML');
        localStorage.removeItem('lastOpenedPageTitle');
        localStorage.removeItem('highlightedCategory');
        localStorage.removeItem('expandedCategories');
        // Оставляем верхний уровень категорий открытым
        $('#p-categorytree-portlet .CategoryTreeItem').each(function() {
            if ($(this).parents('.CategoryTreeChildren').length === 0) {
                $(this).find('.CategoryTreeToggle').first().click();
            }
        });
        // Повторно навешиваем обработчики событий
        attachCategoryEvents();
     }
     }


Строка 137: Строка 119:
         console.log("Начинаем поиск категории для текущей страницы:", currentPageTitle);
         console.log("Начинаем поиск категории для текущей страницы:", currentPageTitle);


         if (scrollToCategory(currentPageTitle)) {
         let found = false;
            return;
        }


         var $categoryItems = $('#p-categorytree-portlet .CategoryTreeItem');
         let searchTimeout = setTimeout(() => {
        if ($categoryItems.length === 0) {
            if (!found) {
            resetCategoryTree();
                console.log("Категория не найдена за 100мс, подменяем на `Категория:Начало`...");
             return;
                currentPageTitle = "Категория:Начало";
         }
                searchAndExpandCategory(currentPageTitle);
             }
         }, 100);


        var index = 0;
         function searchAndExpandCategory(title) {
         function processNext() {
             if (scrollToCategory(title)) {
             if (index >= $categoryItems.length) {
                 found = true;
                 console.log("Категория не найдена. Сбрасываем дерево.");
                 clearTimeout(searchTimeout);
                 resetCategoryTree();
                 return;
                 return;
             }
             }


             var $item = $($categoryItems[index]);
             var $categoryItems = $('#p-categorytree-portlet .CategoryTreeItem');
             expandAndFindCategory($item, function(found) {
            var index = 0;
                 if (!found) {
 
                     index++;
             function processNext() {
                     processNext();
                 if (index >= $categoryItems.length) {
                     console.log("Категория не найдена, подменяем на `Категория:Начало`...");
                     searchAndExpandCategory("Категория:Начало");
                    return;
                 }
                 }
             });
 
                var $item = $($categoryItems[index]);
                expandAndFindCategory($item, function(foundItem) {
                    if (!foundItem) {
                        index++;
                        processNext();
                    }
                });
             }
 
            processNext();
         }
         }


         processNext();
         searchAndExpandCategory(currentPageTitle);
     }
     }