MyAnimeList(MAL) - Preview BBCODE

This script will add the MAL BBCODE Editor where it is currently not enabled.

目前為 2025-02-18 提交的版本,檢視 最新版本

// ==UserScript==
// @name         MyAnimeList(MAL) - Preview BBCODE
// @version      1.0.3
// @description  This script will add the MAL BBCODE Editor where it is currently not enabled.
// @author       Cpt_mathix
// @match        https://myanimelist.net/*
// @grant        none
// @run-at document-body
// @namespace    https://gf.qytechs.cn/users/16080
// ==/UserScript==

init();

function init() {
    if (document.location.href.includes("myanimelist.net/clubs")) {
        initClubCommentsPreview();
        initClubDescriptionPreview();
        return;
    }

    if (document.location.href.includes("myanimelist.net/blog.php")) {
        initBlogCommentsPreview();
        return;
    }

    if (document.location.href.includes("myanimelist.net/myblog.php")) {
        initBlogEntryPreview();
        return;
    }

    if (document.location.href.includes("myanimelist.net/editprofile.php")) {
        initProfileAboutMePreview();
        return;
    }

    if (document.location.href.includes("myanimelist.net/ownlist/manga")) {
        initEditMangaPreview();
        return;
    }

    if (document.location.href.includes("myanimelist.net/ownlist/anime")) {
        initEditAnimePreview();
        return;
    }
}

function initClubCommentsPreview() {
    transformTextArea("form.form-club-user-comment textarea");
}

function initClubDescriptionPreview() {
    resizeDialog();
    transformTextArea('textarea[name="club_description"]');
}

function initBlogCommentsPreview() {
    transformTextArea(".blog_detail_comment_wrapper form textarea");
}

function initEditMangaPreview() {
    resizeDialog();
    transformTextArea("#add_manga_comments");
}

function initEditAnimePreview() {
    resizeDialog();
    transformTextArea("#add_anime_comments");
}

function initBlogEntryPreview() {
    resizeDialog();
    transformTextArea("#blogForm textarea[name=\"entry_text\"");
}

function initProfileAboutMePreview() {
    transformTextArea("#content form textarea[name=\"profile_aboutme\"", (textarea) => {
        textarea.insertAdjacentHTML("afterend", "<small><b>You can also preview bbcode with: <a href='https://cptmathix.github.io/MyAnimeList-BBCODE2HTML/'>https://cptmathix.github.io/MyAnimeList-BBCODE2HTML/</a><b></small>");
    });
}

function transformTextArea(selector, action) {
    var textarea = document.querySelector(selector);
    if (textarea) {
        textarea.classList.add("bbcode-message-editor");
        textarea.rows = 15;

        if (action) {
            action(textarea);
        }
    }
}

function resizeDialog() {
    var dialog = document.getElementById("dialog");
    if (dialog) {
        if (document.location.href.includes("hideLayout=1")){
            var clientWidth = document.body.clientWidth;
            dialog.style.width = clientWidth + "px";
        } else {
            dialog.style.width = "804px";
        }
    }
}

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址