MAL Favorites Row Wrap

Display user favorites in rows without horizontal scroll.

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         MAL Favorites Row Wrap
// @namespace    https://myanimelist.net/
// @version      1.0
// @description  Display user favorites in rows without horizontal scroll.
// @grant        none
// @match        https://myanimelist.net/profile/*
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    function expandFavorites(callback) {
        const moreBtn = document.querySelector('.btn-favmore');

        if (!moreBtn) return callback();

        moreBtn.click();

        setTimeout(() => {
            moreBtn.remove();
            callback();
        }, 500);
    }

    function organizeRows() {
        const sections = document.querySelectorAll('.fav-slide-block');

        if (!sections.length) return;

        sections.forEach(section => {
            const favList = section.querySelector('.fav-slide');

            if (!favList) return;

            const items = Array.from(favList.children);

            if (!items.length) return;

            section.querySelectorAll('.btn-fav-slide-side').forEach(btn => btn.style.display = 'none');
            favList.remove();

            let currentUl;
            items.forEach((item, index) => {
                if (index % 10 === 0) {
                    currentUl = document.createElement('ul');
                    currentUl.className = 'fav-slide';
                    currentUl.dataset.slide = "10";
                    section.querySelector('.fav-slide-outer').appendChild(currentUl);
                }
                currentUl.appendChild(item);
            });
        });
    }

    const observer = new MutationObserver((_, obs) => {
        const favSection = document.querySelector('.fav-slide-block');

        if (!favSection) return;

        obs.disconnect();
        expandFavorites(organizeRows);
    });

    observer.observe(document.body, { childList: true, subtree: true });
})();