MyAnimeList(MAL) - Preview BBCODE

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

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

You will need to install an extension such as Tampermonkey to install this script.

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         MyAnimeList(MAL) - Preview BBCODE
// @version      1.0.4
// @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://greasyfork.org/users/16080
// ==/UserScript==

init();

function init() {
    if (document.location.href.includes("myanimelist.net/clubs.php?action=create")
        || document.location.href.includes("myanimelist.net/editclub.php")) {
        resizeDialog();

        // Create/Edit Club Description
        transformTextArea('textarea[name="club_description"]');
        return;
    }

    if (document.location.href.includes("myanimelist.net/clubs")) {
        // Club Comments
        transformTextArea("form.form-club-user-comment textarea");
        return;
    }

    if (document.location.href.includes("myanimelist.net/blog.php")) {
        // Blog Comments
        transformTextArea(".blog_detail_comment_wrapper form textarea");
        return;
    }

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

        // Blog Entry
        transformTextArea("#blogForm textarea[name=\"entry_text\"");
        return;
    }

    if (document.location.href.includes("myanimelist.net/editprofile.php")) {
        // Profile About Me
        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>");
        });
        return;
    }

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

        // Edit Manga Notes
        transformTextArea("#add_manga_comments");
        return;
    }

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

        // Edit Anime Notes
        transformTextArea("#add_anime_comments");
        return;
    }
}

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";
        }
    }
}